How fortio/fortio works
Main Components
• CLI & Launcher: The top-level commands (main.go, cli/ directory) that parse command-line arguments to start the load test, echo server, or both.
• Load Generators: Components for generating load in various protocols. These include:
– HTTP load generation (fhttp/)
– gRPC load generation (fgrpc/ and jrpc/)
– TCP (tcprunner/) and UDP (udprunner/)
– Additional support for curl-like fetching (fcurl/)
• Server & Web UI: The server process (echosrv/, ui/ directories, rapi/ handlers) that serves a web UI, REST endpoints (for triggering tests, stopping tests, retrieving reports) and has support for additional server side features (like echoing requests, DEBUG endpoints, multi-proxy functionality).
• Supporting Libraries: Utility packages for network handling (fnet/), dynamic flags (dflag/), logging (log/), versioning (version/) and histogram/stats (stats/, histogram/). These provide the core building blocks for load measurement, metrics gathering, logging and configuration.
• CI/CD and Packaging: Infrastructure for building, testing, containerizing, and packaging Fortio (e.g., Dockerfile variants, .circleci/, .github/, debian/).
• Scripting Component: The “grol” scripting language which is embedded (grol/), allowing users to write scripts for interactive tests.
Relationships and Data Flow
• The CLI and server bootstrap the application and then call into the core libraries.
• The load generators invoke HTTP/gRPC/TCP/UDP routines from fhttp, fgrpc, tcprunner, and udprunner respectively. These modules handle the actual load and record performance metrics.
• The measured results (latency histograms, percentiles, response codes) are aggregated by the statistics/histogram modules and then optionally exposed via the web UI or saved as JSON files.
• The web server (running on port 8080 by default) provides a UI, acts as a proxy (via multi-target forwarding and TCP proxies), and also exposes debugging endpoints.
• Optional REST endpoints (under /fortio/rest/) allow remote triggering, stopping, and status queries for load runs.
• Logging and dynamic flag configuration are used across components to allow for runtime adjustments and structured logging.
Architectural Patterns & Design Principles
• Modular/Pipeline Design: Each protocol-specific load generator is isolated in its own package while sharing common libraries for metrics and configuration.
• Separation of Concerns: There is a clear distinction between the CLI interface, load generation logic, and the web/REST server.
• Embeddability: Many components, such as the load generation libraries, are designed to be reused/integrated by other projects.
• CI/CD & Packaging: Use of Dockerfiles, GitHub workflows, and CircleCI to support automated testing, building, and packaging.
• Lightweight Design: Fortio is designed for high performance and low dependency overhead (e.g., using a specialized HTTP client in fhttp).
Key Technologies, Frameworks, and Tools
• Go Language – central to all components.
• Docker – many Dockerfiles and container images are provided.
• gRPC and HTTP/1.1 (with optional HTTP/2 via -h2 flag) support.
• CI/CD configurations (.circleci, .github) indicate integration with CircleCI and Dependabot.
• Linux packaging (debian/) for distributing binaries.
• Embedded web UI using HTML, CSS, and JavaScript for result graphing.
• Do not oversimplify: even if a component seems “small” (e.g., the logger module), include it as an essential piece because it is used across all parts of the system.
• External dependencies, such as TLS certificate handling for secure connections and external tools like Homebrew or Docker Hub.