本机环境
go version go1.12.5 windows/amd64
i7-4710HQ @2.5GHZ
16GB LDDR3
测试命令:
hey -disable-keepalive -H "Authorization: Bearer {your_token}" -n 50000 https://localhost/v2/forum
响应压缩 | jwt_token 解码 | 从mysql获取account | QPS |
---|---|---|---|
√ | √ | √ | 852.9773 |
x | √ | √ | 997.6741 |
√ | √ | x | 1295.9095 |
x | √ | x | 1670.9208 |
x | x | x | 1728.1799 |
启用jwt,无jwt缓存,有响应压缩
Summary:
Total: 58.6182 secs
Slowest: 0.5031 secs
Fastest: 0.0057 secs
Average: 0.0582 secs
Requests/sec: 852.9773
启用jwt,无jwt缓存,无响应压缩
从任务管理器中看到mysql的cpu使用率超过10%
Summary:
Total: 50.1166 secs
Slowest: 0.4664 secs
Fastest: 0.0053 secs
Average: 0.0497 secs
Requests/sec: 997.6741
启用jwt,有jwt缓存,无响应压缩
从任务管理器中看到mysql的cpu使用率不超过1%
Summary:
Total: 28.9322 secs
Slowest: 0.0906 secs
Fastest: 0.0028 secs
Average: 0.0288 secs
Requests/sec: 1728.1799
启用jwt,只对从mysql获取的account操作做缓存。不对jwt对token的decode结果做缓存。有响应压缩。
Summary:
Total: 38.5829 secs
Slowest: 0.4813 secs
Fastest: 0.0037 secs
Average: 0.0383 secs
Requests/sec: 1295.9095
启用jwt,只对从mysql获取的account操作做缓存。不对jwt对token的decode结果做缓存。无响应压缩
Summary:
Total: 29.9236 secs
Slowest: 0.4693 secs
Fastest: 0.0031 secs
Average: 0.0297 secs
Requests/sec: 1670.9208
分析:
- 每次响应,响应压缩会消耗cpu
- 每次请求,对jwt的token解码时,消耗cpu
- 每次请求,token解码后,根据里面的数据从mysql获取account信息,消耗cpu
- 添加jwt缓存后,第2,3项消耗不存在了(对于同一个token的多次请求,只有第一次会经历 2,3 过程)
网友评论