• Post Reply Bookmark Topic Watch Topic
  • New Topic

Http connection pool  RSS feed

 
Rajendra Kumar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I want write code for Http conncetion pooling similar to Db connection pooling. Please send me sample code or refrence for the same.

Thanks
Rajendra
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How exactly the HTTP connection pool should behave ?

Do you want to make a pool of connections to a HTTP server and use them as and when required ? If you keep connections living all the time then a port would also be blocked too.

You should pool objects where creation of such objects are costly affair.If creating creation of objects doesn't take much time then making a connection pool might not be of much use.
 
Joe Ess
Bartender
Posts: 9426
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JRE pools HTTP connections by default. Have a look at the JDK Release Notes: Http Persistent Connections
[ August 31, 2007: Message edited by: Joe Ess ]
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Joe Ess:
The JRE pools HTTP connections by default. Have a look at the JDK Release Notes: Http Persistent Connections


Hi Joe,

I guess the original poster ( RajendraRanch ) wants a HTTP connection pool where the individual connections may or may not have http keepalive options enabled(nothing has been said by the poster).

If my application wants to communicate with a HTTP server and there are multiple request being made to the same server symustaneously then keep alive might not help.Pool would be required , if at all pooling of http connection gives better performance.

RajendraRanch please check with the JavaRanch's naming policy.

 
Joe Ess
Bartender
Posts: 9426
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If my application wants to communicate with a HTTP server and there are multiple request being made to the same server symustaneously then keep alive might not help.Pool would be required , if at all pooling of http connection gives better performance.


In that case you'd be better off using using a caching proxy like squid than trying to reinvent the wheel and making your application manage network functionality.
 
Rajendra Kumar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks for response.

My requirement is to maintain http connections to single URL in pool and use them whenever I need. IT is same as how we connect to DB and maintain the connections in pool.

Thanks again.
Rajendra
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Joe Ess:


In that case you'd be better off using using a caching proxy like squid than trying to reinvent the wheel and making your application manage network functionality.


Squid is mainly implementation of SNAT.

But still the client has to make connections , only the network address translation would be taken care by Squid.
The original poster wants to know as whether we can pool HTTP connections to as server.
 
Joe Ess
Bartender
Posts: 9426
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rahul Bhattacharjee:


Squid is mainly implementation of SNAT.


Not quite. It caches remote content so one doesn't have to do the full round-trip to the remote server. Saves one a lot of bandwidth and time.

Originally posted by Rahul Bhattacharjee:

The original poster wants to know as whether we can pool HTTP connections to as server.


Yep. And my answer is that it is not necessary.
Database connections are designed to be persistent. We get connections through a driver and release them manually when no longer needed. This makes them easy to pool. By contrast, HTTP connections are designed to be transient. HTTP is a single round trip protocol (request-response). This is reflected in Java's HTTP API (URL, URLConnection, HTTPConnection). No provision is made to persist the connection at the API level.
Rajendra, have you analyzed your application and determined that it is establishing HTTP connections that is a bottleneck (I'd wager that the answer is "no", and if you did analyze your application, the answer would be "no"). If you do have a substantial delay in establishing a connection, the problem is likely your network and you'd get far better return on investment upgrading that than attempting a code workaround.
If the bottleneck in your application is throughput (i.e. it takes a long time to download data) than pooling connections would not help anyway. Your best bet would be the previously mentioned caching proxy (if you keep requesting the same data over and over) or upgrading the network.
Remember: "premature optimization is the root of all evil"-Knuth, Donald
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!