NGINX、PHP8、SWOOLE4.8.6 AB压力测试/性能测试

分类: php 发布时间: 2022-02-10 11:22 浏览: 203 次

服务器环境

腾讯云
Intel Xeon E5-2680 v4(2.4 GHz)
8核 16G
CentOS 8.4 64位
nginx/1.20.2
PHP 8.1.2
swoole 4.8.6

nginx 配置

server
{
listen 80;
server_name 127.0.0.1 10.105.17.82;
index index.htm index.html index.php;
root /www/test/;
charset utf-8;
access_log off;
error_log /dev/null;
location ^~/tg {
proxy_pass http://127.0.0.1:9502;

}
location ~.*\.(css|js|swf|jpg|gif|png|jpep|jpg|mp3|xx|xmlbak|xml)$
{
expires 720h;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

aa.html

hello

aa.php

echo "hello php";

swoole.php

$http = new Swoole\Http\Server("127.0.0.1", 9502);
$http->set(array(
'worker_num' => 100,
));
$http->on('request', function ($request, $response) {
$response->end("
<h1>Hello Swoole. #".rand(1000, 9999)."</h1>
");
});
$http-&gt;start();

压测命令:

ab -c 100 -n 1000000 -k http://127.0.0.1/aa.php

nginx纯静态 aa.html

nginx+php-fpm aa.php

nginx+swoole tg/aa.php

结果: swoole是php-fpm的双倍,如果去掉nginx,单独运行,效率会更高

QPS
nginx 115889.2
nginx+php-fpm 25441.71
nginx+swoole 51215.08

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!