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


内容简介:现在grpc的压测工具很少,比http的压测工具少太多了,好像还没有一个“公认”的压测工具,在github中搜索“grpc benchmark”,

本文转载自:https://www.lijiaocn.com/技巧/2019/02/22/grpc-benchmark-method.html,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有。

说明

现在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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM