4

Service A calls into service B via HTTP. This happens frequently, and the size of transferred data is not very big. I discovered that re-using the same TCP connection to send multiple requests from A to B seems to improve latency. Naturally, the idea of connection pooling comes to mind:

  1. Open multiple connections to service B and keep them alive
  2. When A needs to make a call to B, provide it with one of the connections from the pool

Implementing this involves solving some problems which are outside of the scope of what I'm trying to do, so I'm looking for a cheap way to implement this (maybe have some specifically configured proxy server between A and B?).

I could just jump in and start coding, but this problem seems so common that I'm pretty sure someone has already solved it before.

  • 1
    Most HTTP client libraries already do that. What language are you using? – user207421 Feb 25 '13 at 22:19
  • If the calling service client is Java, then take a look at HttpClient - http://stackoverflow.com/questions/4851535/http-connection-pooling-using-httpclient. The pooling has to be at source - even if a proxy does support pooling to the end client, the overhead of opening and closing connections to the proxy will still remain. – Akber Choudhry Feb 25 '13 at 22:20
  • Problem is, the client service is in PHP (and I can't rewrite it in Java, otherwise I'd use the apache HTTP components). PHP's cURL extension can re-use connections, but those connections are not preserved across different HTTP requests (apache shuts them down once the request is complete) –  Feb 25 '13 at 22:36
  • Apache should keep them alive if you use HTTP 1.1 headers. @AkberChoudhry The native Java HttpURLConnection also does connection pooling. – user207421 Feb 26 '13 at 00:52

0 Answers0