Grpc性能压测方法: 用ghz进行压测

Tags: protocol 

目录

说明

现在grpc的压测工具很少,比http的压测工具少太多了,好像还没有一个“公认”的压测工具,在github中搜索“grpc benchmark”,bojand/ghz排在比较靠前的位置,文档也比较齐全整洁:Simple gRPC benchmarking and load testing tool 。也有文章分享了用Locust进行grpc压测的方法。

相关笔记

Go语言实现grpc server和grpc client,用protobuf格式的消息通信(GRPC)

Grpc性能压测方法:用ghz进行压测

下载

编译源代码遇到找不到包的问题,没时间进行折腾,对于工具还秉持“能用就行”的态度,遇到需要通过修改源码解决的问题,或者有闲暇,再深入研究学习一下它们的实现。

好在ghz的release页面提供了已经编译好的可执行文件,直接下载使用好了:bojand/ghz release

使用

ghz的一个好处是直接传入.proto文件就可以压测了,不需要根据grpc的.proto文件生成单独的压测程序。

例如压测Grpc项目中的例子helloworld

./ghz -insecure \
  -proto ./helloworld.proto \
  -call helloworld.Greeter.SayHello \
  -d '{"name":"Joe"}' \
  -c 10 \
  -n 100000 \
  10.10.64.58:50051

压测输出如下:

Summary:
  Count:	100000
  Total:	8.07 s
  Slowest:	41.88 ms
  Fastest:	0.54 ms
  Average:	7.87 ms
  Requests/sec:	12387.61

Response time histogram:
  0.538 [1]	|
  4.672 [22943]	|∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎
  8.806 [46907]	|∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎
  12.940 [19671]	|∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎
  17.074 [5965]	|∎∎∎∎∎
  21.208 [2077]	|∎∎
  25.342 [1094]	|∎
  29.476 [725]	|∎
  33.610 [381]	|
  37.743 [146]	|
  41.877 [90]	|

Latency distribution:
  10% in 3.70 ms
  25% in 4.81 ms
  50% in 6.65 ms
  75% in 9.58 ms
  90% in 13.15 ms
  95% in 16.56 ms
  99% in 27.01 ms
Status code distribution:
  [OK]   100000 responses

官网上有更多的例子Examples

注意

参数-c指定并发请求数:

-c  Number of requests to run concurrently.
    Total number of requests cannot be smaller than the concurrency level. Default is 50.

压测时观察连接情况,发现无论-c指定的参数是多少,都只建立了一个tcp连接,-c所指的并发似乎是并发的往一个grpc连接中发请求,而不是模拟多个client。

参考

  1. bojand/ghz
  2. Simple gRPC benchmarking and load testing tool
  3. 压测工具Locust的使用
  4. bojand/ghz release

推荐阅读

Copyright @2011-2019 All rights reserved. 转载请添加原文连接,合作请加微信lijiaocn或者发送邮件: [email protected],备注网站合作

友情链接:  系统软件  程序语言  运营经验  水库文集  网络课程  微信网文  发现知识星球