rakyll/hey usage examples

rakyll/hey is a popular open-source HTTP load testing tool developed in Go.
It allows you to send a high volume of concurrent requests to a target URL and measure various performance metrics.

Here are a few examples of how you can use rakyll/hey:

1. Basic HTTP load testing:

hey -n 1000 -c 100 http://example.com

This command sends 1000 requests with a concurrency of 100 to http://example.com and reports the average response time, throughput, and other statistics.

2. Load testing with custom headers:

hey -n 1000 -c 100 -H "Authorization: Bearer <token>" http://example.com 

Here, the command includes a custom header -H “Authorization: Bearer ” along with the target URL. This is useful for simulating authenticated requests or adding any other required headers.

3. Load testing with POST requests:

hey -n 1000 -c 100 -m POST -d 'payload' http://example.com

This example demonstrates sending 1000 concurrent POST requests to http://example.com with a payload specified by the -d flag. It’s useful for load testing APIs that require data submission via POST.

4. Load testing with duration and rate limits:

hey -z 30s -q 50 http://example.com

In this case, the -z flag specifies the duration of the test (30 seconds), and -q sets a fixed query rate of 50 requests per second. This is helpful when you want to stress test an application under sustained load.

5. Load testing with HTTP/2:

hey -n 1000 -c 100 -m GET --h2 http://example.com

This command utilizes HTTP/2 (–h2) for sending GET requests to the target URL. HTTP/2 is the latest version of the HTTP protocol and can be leveraged for improved performance and efficiency.

6. Load testing with custom request headers from a file:

hey -n 1000 -c 100 -H @headers.txt http://example.com

In this example, the -H flag is followed by @headers.txt, which specifies a file containing custom headers. This is useful when you have a large number of headers or want to load headers from an external file.

7. Load testing with cookie-based sessions:

hey -n 1000 -c 100 --disable-redirects --disable-keepalive --disable-compression --disable-cookies http://example.com

Here, several flags (–disable-redirects, –disable-keepalive, –disable-compression, –disable-cookies) are used to disable certain features.
This is helpful when you want to simulate unique sessions with different cookies for each request.

8. Load testing with a specified HTTP method distribution:

hey -n 1000 -c 100 -m GET:80,POST:20 http://example.com

This example specifies the distribution of HTTP methods to be used during the load test. In this case, 80% of requests will be sent using the GET method, and 20% will use the POST method. You can adjust the distribution as per your testing requirements.

9. Load testing with request data from a file:

hey -n 1000 -c 100 -m POST -D payload.txt http://example.com

The -D flag is used to specify a file containing the payload data for POST requests. In this example, the file payload.txt contains the request body that will be sent with each POST request.

10. Load testing with custom TLS configuration:

hey -n 1000 -c 100 --cert path/to/cert.pem --key path/to/key.pem https://example.com

This command demonstrates load testing with a custom TLS configuration.
The –cert flag specifies the path to a custom TLS certificate file, and –key specifies the path to the corresponding private key file. This is useful when you need to test an application that requires client-side certificates for authentication.

These examples demonstrate some common use cases of rakyll/hey for load testing. You can further explore the tool’s documentation for additional command-line options and advanced features.

Leave a Reply

Your email address will not be published. Required fields are marked *