Gin Web框架基准测试

531 阅读7分钟

测试机(阿里云 8CPU 8G CentOS8):

yum install -y git
git clone https://github.com/wg/wrk.git
cd wrk && make
cp wrk /usr/local/bin/
wrk -t8 -c100 -d10s --latency http://www.baidu.com
wrk -v

应用服务器(阿里云 CentOS8):

wget https://dl.google.com/go/go1.13.8.linux-amd64.tar.gz
tar -C /usr/local -xf go1.13.8.linux-amd64.tar.gz
vi /etc/profile
export PATH=$PATH:/usr/local/go/bin
source /etc/profile
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,direct

不想看过程的,直接上结果(单位:qps/s):

sleep毫秒数 1CPU 1G 4CPU 4G 8CPU 8G
0ms 30006 92380 150691
1ms 26228 60744 66487
5ms 13656 17816 17949
10ms 8078 9128 9204
50ms 1862 1890 1890
100ms 940 949 949

应用服务器(阿里云 1CPU 1G):

wrk -t8 -c100 -d10s --latency http://172.16.58.64:8080/sleep0
  8 threads and 100 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     3.22ms    1.86ms  37.44ms   64.91%
    Req/Sec     3.79k   295.09     7.42k    92.54%
  Latency Distribution
     50%    3.22ms
     75%    4.54ms
     90%    5.46ms
     99%    7.59ms
  303076 requests in 10.10s, 38.73MB read
Requests/sec:  30006.73

wrk -t8 -c100 -d10s --latency http://172.16.58.64:8080/sleep1
  8 threads and 100 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     3.66ms    1.52ms  22.90ms   71.13%
    Req/Sec     3.31k   213.88     5.74k    93.90%
  Latency Distribution
     50%    3.48ms
     75%    4.58ms
     90%    5.39ms
     99%    7.65ms
  264907 requests in 10.10s, 33.85MB read
Requests/sec:  26228.68

wrk -t8 -c100 -d10s --latency http://172.16.58.64:8080/sleep5
  8 threads and 100 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     6.97ms    1.25ms  19.51ms   70.60%
    Req/Sec     1.73k   113.74     2.24k    61.92%
  Latency Distribution
     50%    6.70ms
     75%    7.67ms
     90%    8.69ms
     99%   10.19ms
  137949 requests in 10.10s, 17.63MB read
Requests/sec:  13656.85

wrk -t8 -c100 -d10s --latency http://172.16.58.64:8080/sleep10
  8 threads and 100 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    11.87ms    1.21ms  24.62ms   69.29%
    Req/Sec     1.01k    55.02     1.21k    69.62%
  Latency Distribution
     50%   11.59ms
     75%   12.52ms
     90%   13.65ms
     99%   15.10ms
  80903 requests in 10.01s, 10.42MB read
Requests/sec:   8078.95

wrk -t8 -c100 -d10s --latency http://172.16.58.64:8080/sleep50
  8 threads and 100 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    51.44ms    1.09ms  61.18ms   80.78%
    Req/Sec   233.91     22.21   242.00     92.00%
  Latency Distribution
     50%   51.19ms
     75%   51.83ms
     90%   52.75ms
     99%   55.04ms
  18644 requests in 10.01s, 2.40MB read
Requests/sec:   1862.63

wrk -t8 -c100 -d10s --latency http://172.16.58.64:8080/sleep100
  8 threads and 100 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   101.55ms    1.13ms 109.64ms   85.74%
    Req/Sec   118.67      8.80   121.00     95.96%
  Latency Distribution
     50%  101.39ms
     75%  101.94ms
     90%  102.53ms
     99%  106.77ms
  9415 requests in 10.01s, 1.22MB read
Requests/sec:    940.12

应用服务器(阿里云 4CPU 4G):

wrk -t8 -c100 -d10s --latency http://172.16.58.64:8080/sleep0
  8 threads and 100 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     1.17ms    1.13ms  30.08ms   89.88%
    Req/Sec    11.65k     1.13k   18.47k    80.87%
  Latency Distribution
     50%    0.88ms
     75%    1.47ms
     90%    2.31ms
     99%    4.98ms
  933048 requests in 10.10s, 119.24MB read
Requests/sec:  92380.27

wrk -t8 -c100 -d10s --latency http://172.16.58.64:8080/sleep1
  8 threads and 100 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     1.58ms  541.40us  14.43ms   88.88%
    Req/Sec     7.64k   232.91     8.30k    74.10%
  Latency Distribution
     50%    1.41ms
     75%    1.63ms
     90%    2.19ms
     99%    3.34ms
  613484 requests in 10.10s, 78.40MB read
Requests/sec:  60744.08

wrk -t8 -c100 -d10s --latency http://172.16.58.64:8080/sleep5
  8 threads and 100 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     5.35ms  445.99us  18.23ms   96.76%
    Req/Sec     2.25k    48.53     2.30k    89.40%
  Latency Distribution
     50%    5.28ms
     75%    5.33ms
     90%    5.43ms
     99%    6.46ms
  179948 requests in 10.10s, 23.00MB read
Requests/sec:  17816.49

wrk -t8 -c100 -d10s --latency http://172.16.58.64:8080/sleep10
  8 threads and 100 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    10.43ms  844.13us  30.33ms   97.44%
    Req/Sec     1.16k    45.60     1.21k    68.66%
  Latency Distribution
     50%   10.31ms
     75%   10.38ms
     90%   10.53ms
     99%   11.88ms
  92193 requests in 10.10s, 11.87MB read
Requests/sec:   9128.76

wrk -t8 -c100 -d10s --latency http://172.16.58.64:8080/sleep50
Running 10s test @ http://172.16.58.64:8080/sleep50
  8 threads and 100 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    50.54ms    0.85ms  64.00ms   95.75%
    Req/Sec   237.49     17.31   330.00     95.12%
  Latency Distribution
     50%   50.39ms
     75%   50.52ms
     90%   50.74ms
     99%   52.72ms
  18917 requests in 10.01s, 2.44MB read
Requests/sec:   1890.09

wrk -t8 -c100 -d10s --latency http://172.16.58.64:8080/sleep100
  8 threads and 100 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   100.57ms  471.06us 111.32ms   91.22%
    Req/Sec   119.72      6.06   121.00     98.99%
  Latency Distribution
     50%  100.45ms
     75%  100.62ms
     90%  100.96ms
     99%  102.06ms
  9504 requests in 10.01s, 1.23MB read
Requests/sec:    949.31

应用服务器(阿里云 8CPU 8G):

wrk -t8 -c100 -d10s --latency http://172.16.58.64:8080/sleep0
  8 threads and 100 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   748.93us  768.79us  15.99ms   87.50%
    Req/Sec    19.06k     2.02k   45.51k    80.80%
  Latency Distribution
     50%  433.00us
     75%    0.97ms
     90%    1.68ms
     99%    3.44ms
  1521963 requests in 10.10s, 194.50MB read
Requests/sec: 150691.26

wrk -t8 -c100 -d10s --latency http://172.16.58.64:8080/sleep1
  8 threads and 100 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     1.46ms  624.06us  14.49ms   92.44%
    Req/Sec     8.35k   242.80     8.73k    90.12%
  Latency Distribution
     50%    1.30ms
     75%    1.42ms
     90%    1.90ms
     99%    2.89ms
  665320 requests in 10.01s, 85.02MB read
Requests/sec:  66487.91

wrk -t8 -c100 -d10s --latency http://172.16.58.64:8080/sleep5
  8 threads and 100 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     5.35ms  475.42us  18.45ms   97.13%
    Req/Sec     2.25k    51.06     2.30k    91.62%
  Latency Distribution
     50%    5.28ms
     75%    5.33ms
     90%    5.43ms
     99%    6.25ms
  179603 requests in 10.01s, 22.95MB read
Requests/sec:  17949.91

wrk -t8 -c100 -d10s --latency http://172.16.58.64:8080/sleep10
  8 threads and 100 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    10.41ms  587.88us  26.71ms   95.78%
    Req/Sec     1.16k    53.45     1.21k    56.75%
  Latency Distribution
     50%   10.31ms
     75%   10.38ms
     90%   10.56ms
     99%   11.77ms
  92139 requests in 10.01s, 11.86MB read
Requests/sec:   9204.21

wrk -t8 -c100 -d10s --latency http://172.16.58.64:8080/sleep50
  8 threads and 100 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    50.57ms  657.01us  59.48ms   93.16%
    Req/Sec   237.46     17.85   242.00     96.12%
  Latency Distribution
     50%   50.41ms
     75%   50.58ms
     90%   50.98ms
     99%   52.32ms
  18917 requests in 10.01s, 2.44MB read
Requests/sec:   1890.03

wrk -t8 -c100 -d10s --latency http://172.16.58.64:8080/sleep100
  8 threads and 100 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   100.67ms    1.30ms 116.17ms   97.93%
    Req/Sec   119.50      7.76   121.00     98.49%
  Latency Distribution
     50%  100.44ms
     75%  100.61ms
     90%  100.88ms
     99%  106.89ms
  9504 requests in 10.01s, 1.23MB read
Requests/sec:    949.24

gitee.com/wizardhan/g… 主键查询一次

wrk -t8 -c40 -d10s --latency http://172.16.58.113:8080/select1
Running 10s test @ http://172.16.58.113:8080/select1
  8 threads and 40 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     1.01ms  805.32us  16.39ms   89.15%
    Req/Sec     5.29k   242.14     6.83k    79.16%
  Latency Distribution
     50%  741.00us
     75%    1.30ms
     90%    1.85ms
     99%    2.91ms
  424378 requests in 10.10s, 110.49MB read
Requests/sec:  42019.85
Transfer/sec:     10.94MB

主键查询二次

wrk -t8 -c40 -d10s --latency http://172.16.58.113:8080/select2
Running 10s test @ http://172.16.58.113:8080/select2
  8 threads and 40 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     1.70ms    1.16ms  26.48ms   92.33%
    Req/Sec     3.11k   208.00     6.01k    89.53%
  Latency Distribution
     50%    1.47ms
     75%    2.12ms
     90%    2.70ms
     99%    5.29ms
  248002 requests in 10.10s, 101.46MB read
Requests/sec:  24557.82
Transfer/sec:     10.05MB

主键随机查询

wrk -t8 -c40 -d10s --latency http://172.16.58.113:8080/selectById
Running 10s test @ http://172.16.58.113:8080/selectById
  8 threads and 40 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     0.99ms    0.93ms  19.68ms   92.71%
    Req/Sec     5.58k   249.73     6.44k    79.55%
  Latency Distribution
     50%  694.00us
     75%    1.21ms
     90%    1.77ms
     99%    3.63ms
  448317 requests in 10.10s, 110.07MB read
Requests/sec:  44388.59


行锁

wrk -t8 -c40 -d10s --latency http://172.16.58.113:8080/decr
Running 10s test @ http://172.16.58.113:8080/decr
  8 threads and 40 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   101.77ms  213.28ms   1.08s    87.75%
    Req/Sec   431.01    201.59     1.16k    82.02%
  Latency Distribution
     50%    5.44ms
     75%   61.82ms
     90%  409.28ms
     99%  939.94ms
  33377 requests in 10.02s, 4.27MB read
Requests/sec:   3332.31
Transfer/sec:    436.06KB

随机行锁更新

wrk -t8 -c40 -d10s --latency http://172.16.58.113:8080/decrRand
Running 10s test @ http://172.16.58.113:8080/decrRand
  8 threads and 40 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     1.91ms  728.40us  14.72ms   81.59%
    Req/Sec     2.65k   106.52     3.53k    84.60%
  Latency Distribution
     50%    1.78ms
     75%    2.28ms
     90%    2.69ms
     99%    4.02ms
  212459 requests in 10.10s, 27.96MB read
Requests/sec:  21034.83
Transfer/sec:      2.77MB

innodb事务+行锁测试

wrk -t8 -c40 -d10s --latency http://172.16.58.113:8080/txAndDecr
Running 10s test @ http://172.16.58.113:8080/txAndDecr
  8 threads and 40 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    11.80ms    3.31ms  39.66ms   75.58%
    Req/Sec   426.54     64.31   555.00     61.50%
  Latency Distribution
     50%   11.19ms
     75%   13.44ms
     90%   15.84ms
     99%   23.12ms
  33994 requests in 10.01s, 4.51MB read
Requests/sec:   3395.56

innodb事务+随机行锁测试

wrk -t8 -c40 -d10s --latency http://172.16.58.113:8080/txAndRandDecr
Running 10s test @ http://172.16.58.113:8080/txAndRandDecr
  8 threads and 40 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     1.90ms  752.44us  14.91ms   85.70%
    Req/Sec     2.67k   121.76     4.15k    89.54%
  Latency Distribution
     50%    1.79ms
     75%    2.26ms
     90%    2.63ms
     99%    3.91ms
  213290 requests in 10.10s, 29.09MB read
Requests/sec:  21117.74

插入 wrk -t8 -c40 -d10s --latency http://172.16.58.113:8080/insert Running 10s test @ http://172.16.58.113:8080/insert 8 threads and 40 connections Thread Stats Avg Stdev Max +/- Stdev Latency 3.19ms 2.78ms 40.35ms 93.17% Req/Sec 1.81k 415.95 2.19k 87.50% Latency Distribution 50% 2.42ms 75% 3.10ms 90% 4.65ms 99% 17.39ms 144093 requests in 10.01s, 18.69MB read Requests/sec: 14392.02

// innodb事务+插入 wrk -t8 -c40 -d10s --latency http://172.16.58.113:8080/txAndInsert Running 10s test @ http://172.16.58.113:8080/txAndInsert 8 threads and 40 connections Thread Stats Avg Stdev Max +/- Stdev Latency 3.21ms 3.17ms 52.00ms 93.95% Req/Sec 1.82k 427.66 2.89k 87.41% Latency Distribution 50% 2.41ms 75% 3.11ms 90% 4.58ms 99% 17.90ms 145049 requests in 10.10s, 19.50MB read Requests/sec: 14361.07

// 下单无事务 wrk -t8 -c40 -d10s --latency http://172.16.58.113:8080/decrAndInsert Running 10s test @ http://172.16.58.113:8080/decrAndInsert 8 threads and 40 connections Thread Stats Avg Stdev Max +/- Stdev Latency 14.45ms 5.91ms 49.63ms 79.53% Req/Sec 349.25 116.87 520.00 50.38% Latency Distribution 50% 11.62ms 75% 18.52ms 90% 23.38ms 99% 31.97ms 27837 requests in 10.01s, 3.69MB read Requests/sec: 2781.09

下单有事务 wrk -t8 -c40 -d10s --latency http://172.16.58.113:8080/txAndDecrAndInsert Running 10s test @ http://172.16.58.113:8080/txAndDecrAndInsert 8 threads and 40 connections Thread Stats Avg Stdev Max +/- Stdev Latency 28.78ms 6.36ms 109.74ms 85.52% Req/Sec 174.18 13.72 212.00 63.38% Latency Distribution 50% 26.71ms 75% 31.12ms 90% 37.08ms 99% 52.08ms 13899 requests in 10.01s, 1.84MB read Requests/sec: 1388.59

空事务 wrk -t8 -c40 -d10s --latency http://172.16.58.113:8080/txEmpty Running 10s test @ http://172.16.58.113:8080/txEmpty 8 threads and 40 connections Thread Stats Avg Stdev Max +/- Stdev Latency 783.30us 608.44us 15.15ms 95.11% Req/Sec 6.76k 230.44 7.18k 85.40% Latency Distribution 50% 652.00us 75% 749.00us 90% 1.14ms 99% 2.20ms 543753 requests in 10.10s, 67.93MB read Requests/sec: 53839.48 Transfer/sec: 6.73MB

分表插入 wrk -t8 -c40 -d10s --latency http://172.16.58.113:8080/insertMulti?number=1 Running 10s test @ http://172.16.58.113:8080/insertMulti?number=1 8 threads and 40 connections Thread Stats Avg Stdev Max +/- Stdev Latency 5.82ms 7.29ms 121.64ms 93.56% Req/Sec 1.10k 358.24 3.74k 84.54% Latency Distribution 50% 3.78ms 75% 5.46ms 90% 9.54ms 99% 41.56ms 88184 requests in 10.10s, 11.86MB read Requests/sec: 8731.52 Transfer/sec: 1.17MB

wrk -t8 -c40 -d10s --latency http://172.16.58.114:8080/insertMulti?number=1 Running 10s test @ http://172.16.58.114:8080/insertMulti?number=1 8 threads and 40 connections Thread Stats Avg Stdev Max +/- Stdev Latency 6.14ms 7.84ms 121.54ms 93.24% Req/Sec 1.07k 333.80 1.98k 83.88% Latency Distribution 50% 3.86ms 75% 5.61ms 90% 10.23ms 99% 45.50ms 85281 requests in 10.01s, 11.47MB read Requests/sec: 8515.51 Transfer/sec: 1.15MB

wrk -t8 -c40 -d10s --latency http://172.16.58.114:8080/insertMulti?number=2 Running 10s test @ http://172.16.58.114:8080/insertMulti?number=2 8 threads and 40 connections Thread Stats Avg Stdev Max +/- Stdev Latency 4.03ms 2.35ms 35.11ms 90.87% Req/Sec 1.31k 219.05 2.16k 83.75% Latency Distribution 50% 3.53ms 75% 4.30ms 90% 5.85ms 99% 14.68ms 104379 requests in 10.01s, 14.04MB read Requests/sec: 10426.03 Transfer/sec: 1.40MB

wrk -t8 -c40 -d10s --latency http://172.16.58.113:8080/insertMulti?number=2 Running 10s test @ http://172.16.58.113:8080/insertMulti?number=2 8 threads and 40 connections Thread Stats Avg Stdev Max +/- Stdev Latency 4.08ms 2.64ms 42.18ms 92.64% Req/Sec 1.31k 233.95 2.27k 85.66% Latency Distribution 50% 3.52ms 75% 4.28ms 90% 5.98ms 99% 16.55ms 104788 requests in 10.10s, 14.09MB read Requests/sec: 10374.95 Transfer/sec: 1.40MB

wrk -t8 -c40 -d10s --latency http://172.16.58.113:8080/insertMulti?number=3 Running 10s test @ http://172.16.58.113:8080/insertMulti?number=3 8 threads and 40 connections Thread Stats Avg Stdev Max +/- Stdev Latency 3.88ms 2.07ms 39.28ms 89.99% Req/Sec 1.34k 158.14 3.75k 88.26% Latency Distribution 50% 3.51ms 75% 4.16ms 90% 5.53ms 99% 12.63ms 107041 requests in 10.10s, 14.39MB read Requests/sec: 10598.53 Transfer/sec: 1.43MB

wrk -t8 -c40 -d10s --latency http://172.16.58.114:8080/insertMulti?number=3 Running 10s test @ http://172.16.58.114:8080/insertMulti?number=3 8 threads and 40 connections Thread Stats Avg Stdev Max +/- Stdev Latency 4.09ms 2.79ms 51.73ms 94.75% Req/Sec 1.30k 133.77 2.04k 83.88% Latency Distribution 50% 3.57ms 75% 4.31ms 90% 5.71ms 99% 15.30ms 103568 requests in 10.01s, 13.93MB read Requests/sec: 10343.22 Transfer/sec: 1.39MB

wrk -t8 -c40 -d10s --latency http://172.16.58.114:8080/insertMulti?number=4 Running 10s test @ http://172.16.58.114:8080/insertMulti?number=4 8 threads and 40 connections Thread Stats Avg Stdev Max +/- Stdev Latency 4.63ms 4.07ms 81.58ms 93.49% Req/Sec 1.23k 309.84 2.09k 86.88% Latency Distribution 50% 3.60ms 75% 4.54ms 90% 6.79ms 99% 23.39ms 98032 requests in 10.01s, 13.18MB read Requests/sec: 9795.84 Transfer/sec: 1.32MB

wrk -t8 -c40 -d10s --latency http://172.16.58.113:8080/insertMulti?number=4 Running 10s test @ http://172.16.58.113:8080/insertMulti?number=4 8 threads and 40 connections Thread Stats Avg Stdev Max +/- Stdev Latency 4.84ms 6.01ms 162.87ms 94.88% Req/Sec 1.24k 326.83 2.18k 85.88% Latency Distribution 50% 3.58ms 75% 4.50ms 90% 6.80ms 99% 27.90ms 98760 requests in 10.01s, 13.28MB read Requests/sec: 9868.87 Transfer/sec: 1.33MB

// innodb 双主机插入 wrk -t8 -c80 -d10s --latency http://172.16.58.113:8080/insert2Host Running 10s test @ http://172.16.58.113:8080/insert2Host 8 threads and 80 connections Thread Stats Avg Stdev Max +/- Stdev Latency 5.87ms 9.09ms 187.40ms 94.56% Req/Sec 2.34k 629.58 6.07k 84.89% Latency Distribution 50% 3.77ms 75% 5.45ms 90% 9.07ms 99% 50.05ms 186729 requests in 10.10s, 25.11MB read Requests/sec: 18490.19 Transfer/sec: 2.49MB

wrk -t8 -c80 -d10s --latency http://172.16.58.114:8080/insert2Host Running 10s test @ http://172.16.58.114:8080/insert2Host 8 threads and 80 connections Thread Stats Avg Stdev Max +/- Stdev Latency 5.82ms 9.29ms 326.13ms 94.53% Req/Sec 2.34k 631.29 7.22k 86.03% Latency Distribution 50% 3.82ms 75% 5.53ms 90% 9.14ms 99% 46.39ms 186571 requests in 10.10s, 25.09MB read Requests/sec: 18473.21 Transfer/sec: 2.48MB