swoole与传统nginx/php-fpm并发性能比较

nginx/php-fpm
$servername = "";
$username = "root";
$password = "";
$dbname = "test";
 
// 创建连接
$conn = new mysqli($servername, $username, $password, $dbname);
// 检测连接
if ($conn->connect_error) {
    die("连接失败: " . $conn->connect_error);
} 
 
$sql = "INSERT INTO test (name, create_time) VALUES ('zhuyanbin', ". time()." )";
 
if ($conn->query($sql) === TRUE) {
    #echo 'success';
} else {
    #echo 'error';
}
 
$conn->close();
swoole
//高性能HTTP服务器
    $http = new Swoole\Http\Server("0.0.0.0", 9501);

    $http->on("start", function ($server) {
        echo "success";
    });

    $http->on("request", function ($request, $response) {
		#$swoole_mysql = new Swoole\Coroutine\MySQL();
		#$swoole_mysql->connect([
			#'host'     => '',
			#'port'     => 3306,
			#'user'     => 'root',
			#'password' => '',
			#'database' => 'test',
		#]);
		#$sql = "INSERT INTO test (name, create_time) VALUES ('zhuyanbin', ". time()." )";
		#$res = $swoole_mysql->query($sql);
		#if ($res === false) {
			#echo 'error';
		#}
        $response->header("Content-Type", "text/plain");
        $response->end("Hello World\n");
    });

    $http->start();

测试服务器为腾讯云1G4核最低配服务器

在10个用户并发1000的状态下测试10次结果(有数据库操作)

nginx/php-fpmswoole
1718.3
16.416.9
16.316.7
16.917.5
16.417.0
1716.8
16.316.8
17.717.3
16.118.1
16.516.7
平均值
nginx/php-fpm:16.6
swoole:17.2

在10个用户并发1000的状态下测试10次结果(无数据库操作)

nginx/php-fpmswoole
6.46.2
7.46.1
8.36.1
6.46.2
6.66.1
6.37.8
6.46.1
7.26.9
6.36.2
6.46.8
平均值
nginx/php-fpm:6.77
swoole:6.45
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值