Global Timeout Configuration vs Per-Request Overrides for Latency Constraints
0 reputation · 28 Apr 2024, 05:07 UTC
0 reputation · 28 Apr 2024, 05:07 UTC
When designing performance tests in k6, managing request timeouts is essential to prevent hanging VU (Virtual User) iterations and to accurately measure service degradation. k6 provides two primary methods for controlling these durations: a global timeout property within the options object and granular overrides passed directly into individual http.request calls.
The trade-off involves balancing configuration simplicity against the need for specific latency thresholds across different endpoints. While a global setting ensures a consistent baseline for all traffic, certain legacy endpoints or heavy reporting queries may require longer windows to avoid false-positive failures, whereas critical API paths require strict, shorter timeouts to simulate real-world client behavior.
In a scenario with mixed-latency endpoints, should the architecture rely on a conservative global timeout with targeted overrides for slow requests, or a strict global timeout with expanded windows for specific calls? Which approach provides more maintainable scripts when scaling the number of tested endpoints?
When you have a mix of fast and slow endpoints, the most maintainable approach is to set a conservative global timeout (longer than the fastest expected latency) and apply per‑request overrides only to the truly critical, latency‑sensitive paths. This keeps the majority of requests governed by a single value while still protecting the most important calls from false failures.
options.timeout establishes a baseline that applies to every HTTP request unless an override is supplied.http.request(..., { timeout: ms }) takes precedence over the global value for that specific call.http_failures metric, affecting overall pass/fail status.options.timeout, so a too‑short global timeout can break the test harness itself.Choose a global timeout that covers the slowest *expected* endpoint but is still shorter than the maximum acceptable latency for most traffic. For example, options.timeout = 8000 (8 s).
Identify the critical paths that must fail faster (e.g., /orders/create, /payments/charge) and add overrides:
http.get('https://api.example.com/orders/create', { timeout: 2000 })Document the list of overridden endpoints in a separate file or comment block so future contributors can see which paths have special limits.
Run the test and inspect http_reqs and http_failures to confirm overrides are respected.
When adding new endpoints, default to the global timeout unless there is a clear business or technical reason to override.
To fine‑tune the recommendation, could you share how many endpoints you consider “critical” versus “slow”? Knowing the ratio helps decide whether a stricter global timeout with many overrides is truly necessary.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.