內容簡介:現在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)
下載
編譯源代碼遇到找不到包的問題,沒時間進行折騰,對於工具還秉持“能用就行”的態度,遇到需要通過修改源碼解決的問題,或者有閑暇,再深入研究學習一下它們的實現。
好在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。