Open
Description
swoole6.0.2 cli 并发上不去 php zts 自编译插件的正常
只有cli有这个问题 感觉是封装独立cli或静态编译 导致受到影响了
越多核下差距越大 cli下发挥的并发数好像跟单线程时差不多
环境
Ubuntu 22.04 64位
4 核(vCPU)4 GiB
还是之前那个测试反馈补充 #5731
使用cli 官网6.0.2
./swoole-cli 7.php
wrk -t4 -c400 -d3s "http://127.0.0.1:4455/"
Running 3s test @ http://127.0.0.1:4455/
4 threads and 400 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 30.47ms 11.13ms 99.77ms 74.06%
Req/Sec 3.28k 668.95 8.27k 84.17%
39238 requests in 3.03s, 7.60MB read
Requests/sec: 12930.06
Transfer/sec: 2.50M
使用原生编译的插件
docker run -p 4456:4455 -v /home/:/home/ phpswoole/swoole:6.0.2-php8.2-zts "php /home/7.php"
wrk -t4 -c400 -d3s "http://127.0.0.1:4456/"
Running 3s test @ http://127.0.0.1:4456/
4 threads and 400 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 15.33ms 14.84ms 169.68ms 92.62%
Req/Sec 7.50k 1.42k 11.38k 76.67%
89684 requests in 3.04s, 17.36MB read
Requests/sec: 29528.88
Transfer/sec: 5.72MB
代码
$server = new \Swoole\WebSocket\Server('0.0.0.0', 4455,SWOOLE_THREAD);
$server->set([
'init_arguments' => function (){
return [];
},
'daemonize' => false,#守护进程
'reactor_num' => swoole_cpu_num(),#reactor线程数 1-4倍 默认值:CPU 核数
'worker_num' => swoole_cpu_num(),#CPU核数的1-4倍 默认值:CPU 核数 迎接Swoole 6多线程版本
'task_worker_num' => 0,#WORK_NUM,#task进程数量
'display_errors' => true,#显示错误
'debug_mode' => true,#调试模式
'hook_flags' => SWOOLE_HOOK_ALL,#开启协程钩子
'enable_coroutine' => true,#启用协程
'task_enable_coroutine' => true,#Task启用协程
'open_websocket_ping_frame' => true,#ws开启ping帧
'open_websocket_pong_frame' => true,#ws开启pong帧
'websocket_compression' => true,#ws压缩
'http_parse_cookie' => false,#自动解析COOKIE请求
'http_parse_post' => true,#自动解析POST请求
'http_parse_files' => false,#自动解析上传文件
'http_compression' => true,#http压缩
'http_compression_level'=> 6,#压缩级别 1-9
'open_http_protocol' => true,#HTTP协议解析
]);
$ret = random_bytes(50);
#启动+重启事件回调函数
$server->on('WorkerStart', function ($server, $worker_id){
\Swoole\Runtime::enableCoroutine();#必须用异步 避免奇奇怪怪BUG
$GLOBALS['worker_id'] = $worker_id;#进程序号
$GLOBALS['worker_id_only'] = $worker_id;#($worker_id+(int)WORK_HOST)*-1;#进程序号 唯一
echo ($server->taskworker?'TASK':'worker')."启动进程 {$GLOBALS['worker_id']} \n";
});
#数据接收事件回调函数
$server->on('message',function ($server, $frame){
@$server->push( $frame->fd, $frame->data, $frame->opcode , SWOOLE_WEBSOCKET_FLAG_FIN );
});
#http请求事件回调函数
$server->on('request', function ($request, $response){
global $ret;
@$response->end($ret);
});
$server->start();
Metadata
Metadata
Assignees
Labels
No labels