Go HTTP server performance

发布于 2020-07-28 · 本文总共 2321 字 · 阅读大约需要 7 分钟

Golang http server

package main

import "net/http"

func helloworld(w http.ResponseWriter, r *http.Request) {
	w.Write([]byte("hello world\n"))
}

func main() {
	http.HandleFunc("/", helloworld)
	http.ListenAndServe(":3000", nil)
}

go build simpleServer.go ./simpleServer &

curl http://127.0.0.1:3000 hello world

测试

用4个线程来模拟1000个并发连接QPS:75350

用4个线程来模拟1000个并发连接,整个测试持续30秒,连接超时30秒,打印出请求的延迟统计信息。 wrk -t4 -c1000 -d30s -T30s –latency http://127.0.0.1:3000

 wrk -t4 -c1000 -d30s -T30s --latency http://127.0.0.1:3000
Running 30s test @ http://127.0.0.1:3000
  4 threads and 1000 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     3.29ms  602.79us  48.87ms   83.92%
    Req/Sec    18.94k     2.27k   29.63k    68.25%
  Latency Distribution
     50%    3.29ms
     75%    3.55ms
     90%    3.82ms
     99%    4.61ms
  2260988 requests in 30.01s, 276.00MB read
  Socket errors: connect 751, read 95, write 0, timeout 0
Requests/sec:  75350.05
Transfer/sec:      9.20MB

1线程1000个并发连接: wrk -t1 -c1000 -d30s -T30s –latency http://127.0.0.1:3000

Running 30s test @ http://127.0.0.1:3000
  1 threads and 1000 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     2.66ms  750.63us   8.08ms   66.59%
    Req/Sec    82.90k     9.90k  125.79k    78.33%
  Latency Distribution
     50%    2.78ms
     75%    3.18ms
     90%    3.51ms
     99%    4.45ms
  2476011 requests in 30.03s, 302.25MB read
  Socket errors: connect 748, read 37, write 0, timeout 0
Requests/sec:  82463.77
Transfer/sec:     10.07MB

1线程1个并发连接: wrk -t1 -c1 -d30s -T30s –latency http://127.0.0.1:3000

Running 30s test @ http://127.0.0.1:3000
  1 threads and 1 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    40.54us   25.39us   3.21ms   93.54%
    Req/Sec    24.15k     1.03k   26.46k    75.75%
  Latency Distribution
     50%   36.00us
     75%   39.00us
     90%   52.00us
     99%  106.00us
  723116 requests in 30.10s, 88.27MB read
Requests/sec:  24024.35
Transfer/sec:      2.93MB

runtime.GOMAXPROCS(1)

wrk -t1 -c1 -d30s -T30s –latency http://127.0.0.1:3000

Running 30s test @ http://127.0.0.1:3000
  1 threads and 1 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    36.87us   15.04us   0.96ms   92.34%
    Req/Sec    26.48k     1.69k   28.58k    82.06%
  Latency Distribution
     50%   33.00us
     75%   36.00us
     90%   46.00us
     99%  104.00us
  793135 requests in 30.10s, 97.57MB read
Requests/sec:  26349.94
Transfer/sec:      3.24MB

wrk -t4 -c1000 -d30s -T30s –latency http://127.0.0.1:3000

Running 30s test @ http://127.0.0.1:3000
  4 threads and 1000 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     3.93ms    1.26ms  47.92ms   88.99%
    Req/Sec    15.93k     2.30k   19.11k    81.50%
  Latency Distribution
     50%    3.59ms
     75%    4.53ms
     90%    5.17ms
     99%    7.81ms
  1901815 requests in 30.01s, 233.97MB read
  Socket errors: connect 751, read 106, write 0, timeout 0
Requests/sec:  63380.07
Transfer/sec:      7.80MB

go version

go version go version go1.13.6 darwin/amd64




本博客所有文章采用的授权方式为 自由转载-非商用-非衍生-保持署名 ,转载请务必注明出处,谢谢。
声明:
本博客欢迎转发,但请保留原作者信息!
博客地址:邱文奇(qiuwenqi)的博客;
内容系本人学习、研究和总结,如有雷同,实属荣幸!
阅读次数:

文章评论

comments powered by Disqus


章节列表