Skip to content

Add HTTP Connection Pool Configuration Support #2505

@aryanmehrotra

Description

@aryanmehrotra

The default Go HTTP client has MaxIdleConnsPerHost: 2, which is insufficient for microservices making frequent requests to the same host. This causes:

  • Connection pool exhaustion errors: "http: putIdleConn: too many idle connections for host"
  • Increased latency: Connection establishment time increases from 4.5ms to 13.6ms (3x slower)
  • Poor connection reuse, leading to unnecessary connection overhead

Suggested Solution

Add configurable HTTP connection pool settings to gofr's HTTP service initialization, allowing users to customize:

  • MaxIdleConns: Maximum idle connections across all hosts
  • MaxIdleConnsPerHost: Maximum idle connections per host (critical setting)
  • IdleConnTimeout: How long to keep idle connections

Proposed Changes

  1. Add HTTP connection pool configuration options to App.AddHTTPService() method
  2. Apply settings to the HTTP client's transport used by gofr's HTTP services

Benefits

  • Eliminates connection pool exhaustion errors
  • Improves performance for high-frequency inter-service calls
  • Backward compatible

Configuration

Allow configuration via:

  • Programmatic API: Optional parameters to AddHTTPService()

Metadata

Metadata

Assignees

Labels

triageThe issue needs triaging.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions