1. 程式人生 > 實用技巧 >Grpc效能壓測方法:用ghz進行壓測

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