Swoole-src: libevent support

Created on 19 Aug 2017  ·  3Comments  ·  Source: swoole/swoole-src

Thank you for you good library.

Please answer these questions before submitting your issue. Thanks!
在提交Issue前请回答以下问题:

  1. What did you do? If possible, provide a recipe for reproducing the error.
    请详细描述问题的产生过程,贴出相关的代码,最好能提供可稳定重现的最小实例。

I made test with 2000 rps, 10 concurency.

I took your simple example:
$server = new Swoole\Http\Server('0.0.0.0', 1080);
$server->set(['worker_num' => 1,]);
$server->on('Request', function($request, $response) {$response->end(' swoole response is ok');});
$server->start();

I got this result:
100% < 15.49 ms
99% < 8.28 ms
98% < 4.35 ms
95% < 0.72 ms
90% < 0.26 ms
85% < 0.23 ms
80% < 0.21 ms
75% < 0.20 ms
50% < 0.17 ms

I also took workerman example:

require_once __DIR__ . '/vendor/autoload.php';
use Workerman\Worker;
Worker::$eventLoopClass = '\Workerman\Events\Ev';
$http_worker = new Worker("http://0.0.0.0:1080");
$http_worker->count = 1;
$http_worker->onMessage = function($connection, $data)
{$connection->send("hello world \n");};
Worker::runAll();

I got this result:
100% < 3.88 ms
99% < 1.09 ms
98% < 0.94 ms
95% < 0.75 ms
90% < 0.63 ms
85% < 0.55 ms
80% < 0.52 ms
75% < 0.49 ms
50% < 0.43 ms

Workerman is more slow 2-3 times.
I installed event library (pecl install event) and enabled it in code Worker::$eventLoopClass = '\Workerman\Events\Ev';
I got this result:
100% < 6.59 ms
99% < 0.37 ms
98% < 0.23 ms
95% < 0.17 ms
90% < 0.15 ms
85% < 0.15 ms
80% < 0.14 ms
75% < 0.13 ms
50% < 0.11 ms

It is faster 4 times then previous version and 1.5 times then swoole.

  1. What did you expect to see?
    期望的结果是什么?

I need to be faster :)
How can I use libevent with swoole or how can I change epoll to something else?

  1. What did you see instead?
    实际运行的结果是什么?

socket select is very slow.

  1. What version of Swoole are you using (php --ri swoole)?
    你所使用的Swoole版本号是什么(使用php --ri swoole可以获取)?

1.9.18

  1. What is your machine environment used (including version of kernel & php & gcc) ?
    你使用的机器系统环境是什么(包括内核、PHP、gcc编译器版本信息)?

4.8.0-52-generic #55-Ubuntu SMP Fri Apr 28 13:28:50 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
PHP 7.0.18
gcc (Ubuntu 6.2.0-5ubuntu12) 6.2.0 20161005

  1. If you are using ssl, what is your openssl version?
    如果你使用了SSL,你的openssl版本是什么?

no ssl

Thank you for you good library again.

question

All 3 comments

The default use of SWOOLE_PROCESS mode, there will be two IPC(inter-process communication.).
You can use the SWOOLE_BASE mode.

Swoole is based on epoll, no need libevent.

$server = new Swoole\Http\Server('0.0.0.0', 1080, SWOOLE_BASE);
$server->set(['worker_num' => 1,]);
$server->on('Request', function($request, $response) {$response->end(' swoole response is ok');});
$server->start();

More faster?) May be you must use GO? Swoole fastest library in PHP.

@matyhtf thank you very match.
workerman:
100% < 7.76 ms
99% < 0.91 ms
98% < 0.66 ms
95% < 0.51 ms
90% < 0.45 ms
85% < 0.40 ms
80% < 0.38 ms
75% < 0.36 ms
50% < 0.26 ms

swoole:
100% < 6.54 ms
99% < 1.78 ms
98% < 0.60 ms
95% < 0.44 ms
90% < 0.36 ms
85% < 0.32 ms
80% < 0.29 ms
75% < 0.27 ms
50% < 0.19 ms

@coollider now I am faster enough.
My colleagues write code on go and whey are faster then me only two times but they spend for writing more then me ten times. https://highloadcup.ru/rating/ When I will need to write code faster than php I will write it on C :)

Was this page helpful?
0 / 5 - 0 ratings