swoole和workerman性能对比

0

swoole是c/c++写的网络通讯扩展,workerman是纯php写的网络框架,两者功能类似。我看到网上很多评论说swoole性能比workerman高不少,甚至还看到知乎有说workerman和swoole比不在一个数量级的。但是为什么我的压测结果却不是这样,不管是我的mac pro还是刚刚阿里云服务器,二者性能差不多甚至有时workerman要比swoole压测性能高一些?以下是我的压测脚本和结果。


环境 阿里云:Ubuntu 18.04.3 LTS; 4核 4G;php7.2;swoole 4.4.15; workerman 3.4.24;


swoole 压测脚本:


<?php
$http = new swoole_http_server("127.0.0.1", "1234");
$http->set(array(
'worker_num' => 4,
'daemonize' => false,
));
$http->on('request', function ($request, $response) {
$response->end("hello");
});
$http->start();

workerman 压测脚本:


<?php
require_once __DIR__ . '/workerman/Autoloader.php';
use Workerman\Worker;
$worker = new Worker('http://0.0.0.0:12345');
$worker->count = 4;
$worker->onMessage = function($connection, $data) {
$connection->send('hello');
};

swoole 结果:


 ab -n1000000 -c1000 -k http://127.0.0.1:1234/
This is ApacheBench, Version 2.3 <$Revision: 1807734 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (be patient)
Completed 100000 requests
Completed 200000 requests
Completed 300000 requests
Completed 400000 requests
Completed 500000 requests
Completed 600000 requests
Completed 700000 requests
Completed 800000 requests
Completed 900000 requests
Completed 1000000 requests
Finished 1000000 requests

Server Software: swoole-http-server
Server Hostname: 127.0.0.1
Server Port: 1234

Document Path: /
Document Length: 5 bytes

Concurrency Level: 1000
Time taken for tests: 11.421 seconds
Complete requests: 1000000
Failed requests: 0
Keep-Alive requests: 1000000
Total transferred: 157000000 bytes
HTML transferred: 5000000 bytes
Requests per second: 87561.23 [#/sec] (mean)
Time per request: 11.421 [ms] (mean)
Time per request: 0.011 [ms] (mean, across all concurrent requests)
Transfer rate: 13424.91 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 1 26.0 0 1040
Processing: 2 11 5.2 11 244
Waiting: 2 11 5.2 11 244
Total: 2 11 29.6 11 1281

Percentage of the requests served within a certain time (ms)
50% 11
66% 12
75% 12
80% 12
90% 13
95% 13
98% 16
99% 21
100% 1281 (longest request)

workerman结果:


 ab -n1000000 -c1000 -k http://127.0.0.1:12345/
This is ApacheBench, Version 2.3 <$Revision: 1807734 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (be patient)
Completed 100000 requests
Completed 200000 requests
Completed 300000 requests
Completed 400000 requests
Completed 500000 requests
Completed 600000 requests
Completed 700000 requests
Completed 800000 requests
Completed 900000 requests
Completed 1000000 requests
Finished 1000000 requests

Server Software: workerman
Server Hostname: 127.0.0.1
Server Port: 12345

Document Path: /
Document Length: 5 bytes

Concurrency Level: 1000
Time taken for tests: 10.674 seconds
Complete requests: 1000000
Failed requests: 0
Keep-Alive requests: 1000000
Total transferred: 125000000 bytes
HTML transferred: 5000000 bytes
Requests per second: 93686.80 [#/sec] (mean)
Time per request: 10.674 [ms] (mean)
Time per request: 0.011 [ms] (mean, across all concurrent requests)
Transfer rate: 11436.38 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.7 0 29
Processing: 3 11 2.5 10 26
Waiting: 3 11 2.5 10 26
Total: 3 11 2.7 10 47

Percentage of the requests served within a certain time (ms)
50% 10
66% 10
75% 11
80% 11
90% 11
95% 19
98% 20
99% 21
100% 47 (longest request)

二者性能基本相近,没有特别大的区别。有兴趣的可以自己试下上面的压测脚本,看看结果是不是和我一致。

已邀请:

censc

赞同来自:

没有带业务的测试是没什么用的,有时候你的电脑某个进程抽了呢。也会影响测试结果的对吧 就这么简单的测试没啥意义 在业务里使用然后对比

要回复问题请先登录注册