timeout configuration
**Timeout configuration** is the practice of setting **time limits** for operations to prevent them from running indefinitely, which can block resources, degrade user experience, and cascade into broader system failures. In AI systems, proper timeouts are especially important because LLM inference can vary dramatically in duration.
**Types of Timeouts in AI Systems**
- **Connection Timeout**: How long to wait for a connection to be established with the API server (typically **5–10 seconds**).
- **Read Timeout**: How long to wait for the server to start sending response data (typically **30–120 seconds** for LLM APIs).
- **Total Request Timeout**: Maximum total time for the entire request-response cycle, including retries.
- **Streaming Timeout**: For streaming LLM responses, the maximum time between receiving consecutive chunks.
- **Inference Timeout**: Server-side limit on how long model inference can run before being terminated.
**Why Timeouts Matter for LLM Applications**
- **Variable Inference Time**: LLM response time depends on output length, model load, prompt complexity, and server capacity — a request might take 2 seconds or 120 seconds.
- **Resource Management**: Without timeouts, a hung request ties up a connection, a worker thread, and potentially GPU memory indefinitely.
- **User Experience**: Users expect responses within reasonable time frames — a 5-minute wait with no feedback is unacceptable.
- **Cascade Prevention**: In microservices, a slow downstream service without timeouts can cause upstream services to queue up and eventually crash (cascading failure).
**Best Practices**
- **Set Timeouts on Every External Call**: Never leave timeouts at default (often infinite) — explicitly configure them.
- **Tiered Timeouts**: Use shorter timeouts for interactive requests (30s) and longer timeouts for batch processing (5min).
- **Timeout + Retry**: Combine timeouts with retry logic — if a request times out, retry with potentially different parameters or a different server.
- **User Feedback**: For long operations, provide progress indicators rather than silent waiting.
- **Monitor Timeout Rates**: Track how often timeouts occur — high rates indicate performance problems or misconfigured limits.
Proper timeout configuration is a **silent hero** of production reliability — most cascading failures and hung-system incidents trace back to missing or misconfigured timeouts.