最近在学习 Swoole,Golang,网上看到了很多 Swoole 和 Golang 的对比,也自行代码测试,发现略不同。貌似 Swoole 和 Golang QPS 旗鼓相当。
测试版本:
go1.19.1
swoole-4.8.11
测试代码
web.go
package main
import (
"net/http"
)
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("hi,golang"))
})
http.ListenAndServe("0.0.0.0:8080", nil)
}
web.php
<?php
$http = new \Swoole\Http\Server('0.0.0.0',6060);
$http->set([
'document_root' => '/data/www/test',
]);
$http->on('request',function ($request, $response){
$response->header("Content-Type", "text/html; charset=utf-8");
$response->end('hi,swoole');
});
$http->start();
先正常测试
Swoole QPS:5575.97 / Sec
GO QPS:5234.77 / Sec
长链接测试:
Go QPS: 32318 / Sec
Swoole QPS: 37952 / Sec