TL;DR
We’ll use hey, a simple command-line tool to simulate an HTTP flood on your website. It’s easy to install and use, even if you don’t have much technical experience.
Steps
- Install hey
hey is available for Linux, macOS, and Windows. Here’s how to install it:
- Linux (Debian/Ubuntu):
sudo apt update && sudo apt install hey
brew install hey
choco install hey
To send a single GET request to your website, use:
hey
Replace with the actual URL of your site (e.g., https://www.example.com).
To simulate a flood, you need to send multiple requests concurrently. The -n flag specifies the total number of requests and -c sets the concurrency (number of parallel requests). Start with a small number of concurrent requests.
hey -n 100 -c 10
This sends 100 requests with 10 concurrent connections. Monitor your website’s performance while running this command.
Gradually increase the concurrency (-c) to see how your server handles more load. Be cautious, as excessive traffic can overload your server and potentially cause downtime. Start with small increments (e.g., 20, 50, 100).
hey -n 1000 -c 50
- POST requests: Use the
-mflag to specify a POST request body.
hey -n 10 -c 2 -m 'data=some_post_data'
-H flag. You can specify multiple headers.
hey -n 10 -c 2 -H "Content-Type: application/json" -H "X-Custom-Header: value"
hey provides useful statistics, including:
- Requests per second (RPS): Shows how many requests your server can handle.
- Average response time: Indicates how long it takes for your server to respond.
- Error rate: Highlights any errors encountered during the test.
- Test on a staging environment first: Never run load tests directly on your production website without testing it thoroughly in a staging or development environment.
- Respect rate limits: Be mindful of any rate limiting policies implemented by your hosting provider or CDN.
- Monitor server resources: Keep an eye on CPU usage, memory consumption, and network bandwidth during the test to identify potential bottlenecks.