ghz is a command line utility and Go package for load testing and benchmarking gRPC services. It is intended to be used for testing and debugging services locally, and in automated continuous integration environments for performance regression testing.
The client side can be parametrized with number of connections to use, number of requests to send concurrently, CPU usage limit, and payload size. Request rate can also be optionally limited. It is also possible to define the payload to be sent.
Installation:
Load Options:
ghz --async --proto /helloworld.proto --call helloworld.Greeter/SayHello -c 10 -n 100 --rps 200 127.0.0.1:50051
You can view the different call/load option on the ghz docs
Configuration Files
{
"proto": "/path/to/greeter.proto",
"call": "helloworld.Greeter.SayHello",
"total": 2000,
"concurrency": 50,
"data": {
"name": "Joe"
},
"metadata": {
"foo": "bar",
"trace_id": "{{.RequestNumber}}",
"timestamp": "{{.TimestampUnix}}"
},
"import-paths": [
"/path/to/protos"
],
"max-duration": "10s",
"host": "0.0.0.0:50051"
}
Once the JSON file is ready then open the terminal, run the command ghz --config=SayHello.json in the project directory. Summary:
Count: 10000
Total: 50.05 s
Slowest: 56.17 ms
Fastest: 50.17 ms
Average: 50.58 ms
Requests/sec: 199.79
Response time histogram:
50.167 [1] |
50.768 [8056] |∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎
51.368 [1900] |∎∎∎∎∎∎∎∎∎
51.968 [37] |
52.568 [1] |
53.169 [0] |
53.769 [0] |
54.369 [1] |
54.969 [1] |
55.569 [0] |
56.170 [3] |
Latency distribution:
10 % in 50.32 ms
25 % in 50.40 ms
50 % in 50.56 ms
75 % in 50.72 ms
90 % in 50.88 ms
95 % in 51.00 ms
99 % in 51.23 ms
Status code distribution:
[OK] 10000 responses
If the host is incorrect then the error description will be mentioned in the Error distribution
Summary:
Count: 10000
Total: 50.05 s
Slowest: 0 ns
Fastest: 0 ns
Average: 305.33 ms
Requests/sec: 199.80
Response time histogram:
Latency distribution:
Status code distribution:
[Unavailable] 10000 responses
Error distribution:
[10000] rpc error: code = Unavailable desc = connection error: desc = "transport: Error while dialing dial tcp 127.0.0.1:50051: connectex: No connection could be made because the target machine actively refused it."
Incase, your request requires additional information, for example, the request header should include authorization or login credentials or bearer token then you can create a JSON file and add those information into the JSON file. Later, pass that file in the ghz command using the flag option -M ./metadata.json Some cool ghz features include:
ghz-web
ghz-web is a completely separate complimentary application for storing, viewing and comparing the results of test runs over time. It would have separate config not related to your ghz runs.
ghz-web setup:
Run it using ghz-web -config web.yml
Go to http://localhost:3000/ and you should see a UI. Create a project. Take note of the ID.
POST /api/projects/:id/ingestghz -insecure --config=SayHello.json 127.0.0.1:50051 -M ./metadata.json -O json | http post localhost:3000/api/projects/1/ingest
if you have failed to run ghz-web before ingesting the json data then the below error will be displayed
ReplyDelete-----------------------------------------------------------
http: error: ConnectionError: HTTPConnectionPool(host='localhost', port=3000): Max retries exceeded with url: /api/projects/1/ingest (Caused by NewConnectionError(': Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it')) while doing a POST request to URL: http://localhost:3000/api/projects/1/ingest