The Quotes Load Generator is a simple Go-based tool designed to generate load on a set of URLs. It is useful for testing the performance and reliability of the Quotes Frontend application or other services.
- Configurable Load: Specify the URLs, requests per second, and duration of the load test.
- Concurrency: Generates concurrent requests to simulate real-world traffic.
- Lightweight: Built with Go for minimal resource usage.
- Go 1.25 or later
- Docker (optional, for containerized usage)
cmd/: Contains the CLI commands and themain.goentry point for the application.internal/loadgen/: Contains the core logic for generating load.
--url: List of URLs to load (can be specified multiple times).--hostname: Hostname to prefix to all URLs (optional, should not include protocol).--protocol: Protocol to use for URLs (httporhttps, default:https).--rps: Number of requests per second (default:10).--duration: Duration of the load test in seconds (default:10).--metrics: Enable Prometheus metrics endpoint. When enabled, metrics about the load test will be exposed at the/metricsendpoint.--metrics-port: Port for the Prometheus metrics endpoint (default:8080).
-
Clone the repository:
git clone https://github.com/nais/examples/quotes-loadgen.git cd quotes-loadgen -
Build the application:
cd cmd go build -o quotes-loadgen -
Run the load generator:
./quotes-loadgen load --url / --url /quotes --url /analytics --url /api/quotes --url /api/analytics --url /api/analytics/summary --hostname "localhost:3000" --protocol "http" --rps 8 --duration 30
- This example generates 8 requests per second for 30 seconds on frontend pages and API endpoints including quotes and analytics.
-
Build the Docker image:
docker build -t quotes-loadgen . -
Run the container:
docker run --rm quotes-loadgen load --url / --url /quotes --url /analytics --url /api/quotes --url /api/analytics --url /api/analytics/summary --hostname "localhost:3000" --protocol "http" --rps 8 --duration 30
The Quotes Load Generator supports the following environment variables for configuration:
LOADGEN_URLS: A comma-separated list of URLs to load. Overrides the--urlflag.LOADGEN_HOSTNAME: Hostname to prefix to all URLs. Overrides the--hostnameflag.LOADGEN_PROTOCOL: Protocol to use for URLs (httporhttps). Overrides the--protocolflag.LOADGEN_RPS: Number of requests per second. Overrides the--rpsflag.LOADGEN_DURATION: Duration of the load test in seconds. Overrides the--durationflag.LOADGEN_METRICS: Set totrueto enable the Prometheus metrics endpoint. Overrides the--metricsflag.LOADGEN_METRICS_PORT: Specifies the port for the Prometheus metrics endpoint. Overrides the--metrics-portflag (default:8080).
You can configure the load generator using environment variables instead of command-line flags:
export LOADGEN_URLS="/,/quotes,/analytics,/api/quotes,/api/analytics,/api/analytics/summary"
export LOADGEN_HOSTNAME="localhost:3000"
export LOADGEN_PROTOCOL="http"
export LOADGEN_RPS=8
export LOADGEN_DURATION=30
./quotes-loadgen loadThe application can be deployed to the Nais platform using the provided .nais/app.yaml file. Ensure the Docker image is pushed to a container registry accessible by Nais.
This project is licensed under the MIT License. See the LICENSE file for details.