要用 ghz CLI 打 Benchmark,可先參考 ghz CLI 的使用說明。
1 | usage: ghz [<flags>] [<host>] |
比較常用的有 –proto、–call、-d、-c、-n、–connections、-O、-o 這幾個參數。
像是要打一個 Benchmark 就會用 –proto 指定 proto 檔的位置、用 –call 指定要調用哪個 proto service、-d 指定 proto service 調用時所需要的資料、-c 指定 Benchmark 的 concurrent 數、-n 指定 Benchmark 要發送的數量,最後帶上 gRPC service 的 IP。
ghz --proto $protofile --call $protoservice -d '$protodata' -c $concurrency -n $numbers --insecure $ip

運行的結果有點類似 Apache 的 ab,可看到處理時間的統計與分佈。
如果要設定 Benchmark 的 gRPC 連線數,可使用 –connections 指定。若不指定預設是使用一個 gRPC 連線,不論設多少的 Concurrent 都共用這條連線。
ghz –proto $protofile –call $protoserv ice -d ‘$protodata’ –connections $connections -c $concurrency -n $numbers –insecure $ip

除了直接 Console 顯示 Benchmark 的結果,ghz 也提供了輸出成報表檔的功能,支援輸出 json 、html、csv、… 等格式,可透過 -O 指定輸出的格式,並透過 -o 指定輸出檔案的位置。
ghz --proto $protofile --call $protoservice -d '$protodata' -c $concurrency -n $numbers --insecure $ip -O html -o $outputfile
