测试部门提供GHZ工具来辅助实现gRPC接口性能测试;相比较于市面上的其他工具,GHZ的好处是只需要提供proto文件就可以发起测试了,不需要额外编写客户端与压测程序。
1,通过http://help.j.snowballfinance.com/jmp_apply/add 申请压测服务器权限:10.10.50.2,原因写gRPC压测需要。
2,跳转到目录:/opt/tools/ghz/,进入projects目录,创建自己的压测文件夹目录。

3,将压测需要的proto文件或者protoset文件存在压测文件夹目录下。

4,编写sh脚本,用以执行压测。
/opt/tools/ghz/ghz --config [配置文件] -D [参数文件] [压测目标主机与端口],参考如下示例。

5,编写配置文件。
{
“proto”: “”, #proto文件路径
“call”: “”, #调用的方法名称
“skipTLS”: true, #忽略客户端TLS安全校验
“insecure”: true, #非安全明文传输
“total”: 200, #总共请求的次数
“concurrency”: 1, #并发数
“host”: “XX.XX.XX.XX:XXXX” #主机与端口
}
参考如下示例:

6,编写参数文件。
将请求数据以JSON格式写在参数文件中。
注意,当格式为JSONArray时候,GHZ将会循环遍历该文件,每次取一个节点的数据来请求。我们采用这种方式来构建混合压测。
参考示例如下。

7,执行压测。
终端输入 ./[sh脚本] ./[参数文件],gRPC压测立即开始,测试完成后可以看到响应压测结果。
附GHZ使用说明:
usage: ghz [<flags>] [<host>]
Flags:
-h, --help Show context-sensitive help (also try --help-long and --help-man).
--config= Path to the JSON or TOML config file that specifies all the test run settings.
--proto= The Protocol Buffer .proto file.
--protoset= The compiled protoset file. Alternative to proto. -proto takes precedence.
--call= A fully-qualified method name in 'package.Service/method' or 'package.Service.Method' format.
-i, --import-paths= Comma separated list of proto import paths. The current working directory and the directory of the protocol buffer file are automatically added to the import list.
--cacert= File containing trusted root certificates for verifying the server.
--cert= File containing client certificate (public key), to present to the server. Must also provide -key option.
--key= File containing client private key, to present to the server. Must also provide -cert option.
--cname= Server name override when validating TLS certificate - useful for self signed certs.
--skipTLS Skip TLS client verification of the server's certificate chain and host name.
--insecure Use plaintext and insecure connection.
--authority= Value to be used as the :authority pseudo-header. Only works if -insecure is used.
-c, --concurrency=50 Number of requests to run concurrently. Total number of requests cannot be smaller than the concurrency level. Default is 50.
-n, --total=200 Number of requests to run. Default is 200.
-q, --qps=0 Rate limit, in queries per second (QPS). Default is no rate limit.
-t, --timeout=20s Timeout for each request. Default is 20s, use 0 for infinite.
-z, --duration=0 Duration of application to send requests. When duration is reached, application stops and exits. If duration is specified, n is ignored. Examples: -z 10s -z 3m.
-x, --max-duration=0 Maximum duration of application to send requests with n setting respected. If duration is reached before n requests are completed, application stops and exits. Examples: -x 10s -x 3m.
--duration-stop="close" Specifies how duration stop is reported. Options are close, wait or ignore.
-d, --data= The call data as stringified JSON. If the value is '@' then the request contents are read from stdin.
-D, --data-file= File path for call data JSON file. Examples: /home/user/file.json or ./file.json.
-b, --binary The call data comes as serialized binary message or multiple count-prefixed messages read from stdin.
-B, --binary-file= File path for the call data as serialized binary message or multiple count-prefixed messages.
-m, --metadata= Request metadata as stringified JSON.
-M, --metadata-file= File path for call metadata JSON file. Examples: /home/user/metadata.json or ./metadata.json.
--stream-interval=0 Interval for stream requests between message sends.
--reflect-metadata= Reflect metadata as stringified JSON used only for reflection request.
-o, --output= Output path. If none provided stdout is used.
-O, --format= Output format. One of: summary, csv, json, pretty, html, influx-summary, influx-details. Default is summary.
--connections=1 Number of connections to use. Concurrency is distributed evenly among all the connections. Default is 1.
--connect-timeout=10s Connection timeout for the initial connection dial. Default is 10s.
--keepalive=0 Keepalive time duration. Only used if present and above 0.
--name= User specified name for the test.
--tags= JSON representation of user-defined string tags.
--cpus=12 Number of cpu cores to use.
--debug= The path to debug log file.
-e, --enable-compression Enable Gzip compression on requests.
-v, --version Show application version.
Args:
[<host>] Host and port to test.

本文介绍了如何利用GHZ工具进行gRPC接口的性能测试,无需额外编写客户端和压测程序。主要步骤包括申请压测服务器权限、放置proto文件、编写执行压测的sh脚本和配置文件、设定请求参数,最后执行测试并查看结果。
656

被折叠的 条评论
为什么被折叠?



