Skip to content

Conversation

@ish1416
Copy link

@ish1416 ish1416 commented Nov 10, 2025

Pull Request Template

Description:

  • Added HTTP Connection Pool Configuration support to GoFr's HTTP service initialization
  • Addresses issue Add HTTP Connection Pool Configuration Support #2505 by providing configurable connection pool settings to resolve performance bottlenecks
  • Introduces ConnectionPoolConfig struct with MaxIdleConns, MaxIdleConnsPerHost, and IdleConnTimeout options
  • 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 Options interface 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!

Add ConnectionPoolConfig struct with MaxIdleConns, MaxIdleConnsPerHost, and IdleConnTimeout options
Implement Options interface to apply connection pool settings to HTTP services
Add comprehensive tests for connection pool configuration
Update examples to demonstrate connection pool usage
Create dedicated example for HTTP connection pool configuration

Fixes gofr-dev#2505

This addresses the issue where default Go HTTP client has MaxIdleConnsPerHost: 2,
which causes connection pool exhaustion and increased latency for microservices
making frequent requests to the same host.

Benefits:
- Eliminates connection pool exhaustion errors
- Improves performance for high-frequency inter-service calls
- Backward compatible with existing code
- Configurable via programmatic API
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant