大家一直都说Go性能很好,而Gin框架更是比较好的web服务框架。但是为什么我用http_load压测Gin,当300qps的时候,就开始出现大量超时。而且压测10min后就开始出现超时现象。
我的Gi操作就是当请求进来后,sleep 1毫秒,然后return ok(1毫秒为模拟服务响应时间,比如查数据库什么的),但是即使这样当压力到达300qps的时候,服务就超时了。。。
请大神们帮忙,是不是我使用的哪个地方有问题?至少Gin也要导到少说1千,多了1万的qps吧?为啥到了300就有问题了。。。
代码如下:
package main
import (
"time"
"gopkg.in/gin-gonic/gin.v1"
"net/http"
)
func main() {
route := gin.Default()
route.GET("/bin/search", func(c *gin.Context) {
time.Sleep(time.Millisecond * 1)
c.String(http.StatusOK, "OK")
})
s := &http.Server{
Addr: ":1234",
Handler: route,
ReadTimeout: 1 * time.Second,
WriteTimeout: 1 * time.Second,
MaxHeaderBytes: 1 << 20,
}
s.ListenAndServe()
}
```
~/codes/apkAdmin(master*) » wrk -c 100 -t 10 -d 10m http://127.0.0.1:1234/bin/search
Running 10m test @ http://127.0.0.1:1234/bin/search
10 threads and 100 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 17.98ms 39.48ms 987.19ms 92.64%
Req/Sec 1.32k 612.42 3.77k 65.24%
7803730 requests in 10.00m, 0.86GB read
Socket errors: connect 0, read 23, write 0, timeout 0
Requests/sec: 13003.68
Transfer/sec: 1.46MB
------------------------------------------------------------
~/codes/apkAdmin(master*) » wrk -c 100 -t 10 -d 10m http://127.0.0.1:1234/bin/search
Running 10m test @ http://127.0.0.1:1234/bin/search
10 threads and 100 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 36.36ms 74.70ms 997.60ms 90.05%
Req/Sec 1.09k 726.72 4.70k 58.11%
5881268 requests in 10.00m, 661.84MB read
Socket errors: connect 0, read 309, write 0, timeout 0
Requests/sec: 9800.17
Transfer/sec: 1.10MB
------------------------------------------------------------
~/codes/apkAdmin(master*) » wrk -c 100 -t 10 -d 10m http://127.0.0.1:1234/bin/search
Running 10m test @ http://127.0.0.1:1234/bin/search
10 threads and 100 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 68.92ms 125.57ms 996.69ms 87.01%
Req/Sec 0.99k 583.94 3.72k 65.28%
4554951 requests in 10.00m, 512.58MB read
Socket errors: connect 0, read 328, write 0, timeout 0
Requests/sec: 7590.57
Transfer/sec: 0.85MB
------------------------------------------------------------
```
三次压测结果。4核8G Mac. go version go1.8.3 darwin/amd64
#7
更多评论