gofr icon indicating copy to clipboard operation
gofr copied to clipboard

Add HTTP Connection Pool Configuration Support

Open aryanmehrotra opened this issue 1 month ago • 7 comments

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()

aryanmehrotra avatar Nov 09 '25 19:11 aryanmehrotra

@aryanmehrotra Ill take up this issue and will raise a PR soon!

ish1416 avatar Nov 10 '25 05:11 ish1416

Hi @ish1416 since the issue is triage phase we need to decide if we want to support this.

aryanmehrotra avatar Nov 10 '25 05:11 aryanmehrotra

@aryanmehrotra I have raised a PR which supports this!

ish1416 avatar Nov 10 '25 05:11 ish1416

@ish1416 Sure assigned the issue to you. We will review the PR shortly.

Umang01-hash avatar Nov 11 '25 07:11 Umang01-hash

@Umang01-hash Why do package unit testing failing?

ish1416 avatar Nov 11 '25 07:11 ish1416

@ish1416 The Default MQTT Broker we use to connect is giving some connection issue. Don;t worry we will fix it soon. You can work on your issue and once it get fixed your pipeline will also pass.

Umang01-hash avatar Nov 11 '25 07:11 Umang01-hash

@Umang01-hash Okay Thanks

ish1416 avatar Nov 11 '25 07:11 ish1416

hey @Umang01-hash @ish1416 is this fixed or can I work on this ?

KhanjarSingh avatar Nov 18 '25 04:11 KhanjarSingh

hey @Umang01-hash is this issue been solved? If not, Can I work on it?

KhanjarSingh avatar Nov 28 '25 16:11 KhanjarSingh