Skip to content

Latest commit

 

History

History
103 lines (69 loc) · 3.76 KB

File metadata and controls

103 lines (69 loc) · 3.76 KB

Quotes Load Generator

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.

Features

  • 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.

Prerequisites

  • Go 1.25 or later
  • Docker (optional, for containerized usage)

Usage

Folder Structure

  • cmd/: Contains the CLI commands and the main.go entry point for the application.
  • internal/loadgen/: Contains the core logic for generating load.

Command-Line Options

  • --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 (http or https, 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 /metrics endpoint.
  • --metrics-port: Port for the Prometheus metrics endpoint (default: 8080).

Running Locally

  1. Clone the repository:

    git clone https://github.com/nais/examples/quotes-loadgen.git
    cd quotes-loadgen
  2. Build the application:

    cd cmd
    go build -o quotes-loadgen
  3. 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.

Running with Docker

  1. Build the Docker image:

    docker build -t quotes-loadgen .
  2. 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

Environment Variables

The Quotes Load Generator supports the following environment variables for configuration:

  • LOADGEN_URLS: A comma-separated list of URLs to load. Overrides the --url flag.
  • LOADGEN_HOSTNAME: Hostname to prefix to all URLs. Overrides the --hostname flag.
  • LOADGEN_PROTOCOL: Protocol to use for URLs (http or https). Overrides the --protocol flag.
  • LOADGEN_RPS: Number of requests per second. Overrides the --rps flag.
  • LOADGEN_DURATION: Duration of the load test in seconds. Overrides the --duration flag.
  • LOADGEN_METRICS: Set to true to enable the Prometheus metrics endpoint. Overrides the --metrics flag.
  • LOADGEN_METRICS_PORT: Specifies the port for the Prometheus metrics endpoint. Overrides the --metrics-port flag (default: 8080).

Example Usage with Environment Variables

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 load

Deployment

The 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.

License

This project is licensed under the MIT License. See the LICENSE file for details.