Concurrency performance comparison between swoole and traditional 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();

The test server is Tencent Cloud 1G4 core minimum server

Test 10 results under the condition of 10 users concurrently 1000 (with database operation)

nginx/php-fpm swoole
17 18.3
16.4 16.9
16.3 16.7
16.9 17.5
16.4 17.0
17 16.8
16.3 16.8
17.7 17.3
16.1 18.1
16.5 16.7
average value
nginx/php-fpm:16.6
swoole:17.2

Test 10 times under the condition of 10 users concurrently 1000 (no database operation)

nginx/php-fpm swoole
6.4 6.2
7.4 6.1
8.3 6.1
6.4 6.2
6.6 6.1
6.3 7.8
6.4 6.1
7.2 6.9
6.3 6.2
6.4 6.8
average value
nginx/php-fpm:6.77
swoole:6.45

Guess you like

Origin blog.csdn.net/qq_41526316/article/details/109897167