gofr
gofr copied to clipboard
feat: add HTTP connection pool configuration support
Pull Request Template
Description:
- Added HTTP Connection Pool Configuration support to GoFr's HTTP service initialization
- Addresses issue #2505 by providing configurable connection pool settings to resolve performance bottlenecks
- Introduces
ConnectionPoolConfigstruct withMaxIdleConns,MaxIdleConnsPerHost, andIdleConnTimeoutoptions - Solves connection pool exhaustion errors and reduces latency from 13.6ms to 4.5ms for high-frequency inter-service calls
- Maintains backward compatibility with existing GoFr applications
Breaking Changes (if applicable):
- None. This is a purely additive feature that maintains full backward compatibility with existing code.
Additional Information:
- Implements the existing
Optionsinterface pattern used by Circuit Breaker and Health Check configurations - Added comprehensive unit tests covering all configuration scenarios
- Updated existing examples and created dedicated connection pool example with documentation
- Works seamlessly with existing service options (can be combined with Circuit Breaker and Health Check)
Usage Example:
app.AddHTTPService("api-service", "https://api.example.com",
&service.ConnectionPoolConfig{
MaxIdleConns: 100, // Total idle connections
MaxIdleConnsPerHost: 20, // Per-host idle connections (vs default 2)
IdleConnTimeout: 90 * time.Second, // Keep alive duration
},
)
Checklist:
I have formatted my code using goimport and golangci-lint.
All new code is covered by unit tests.
This PR does not decrease the overall code coverage.
I have reviewed the code comments and documentation for clarity.
Thank you for your contribution!