Hi,
I have a problem where I need to connect to another server through HTTP and the concurrent user count could be over 1000. I'd like to reuse the connections since I think opening and closing the connections would be a waste of resources. The problem can be solved I think with HTTP connection pooling.
Or are there any other solutions? Is HttpURLConnection pooling connections behind the scene? If I hold on to 1000 connected HttpURLConnections will there be 1000 connections to the backend server? Or just 100?
Regards
MZ
-
Pooling HTTP Connections... (9 messages)
- Posted by: jason priestly
- Posted on: June 14 2002 07:12 EDT
Threaded Messages (9)
- Pooling HTTP Connections... by Q Werty on June 14 2002 07:36 EDT
- Pooling HTTP Connections... by jason priestly on June 14 2002 08:01 EDT
-
Pooling HTTP Connections... by Q Werty on June 14 2002 09:36 EDT
- Pooling HTTP Connections... by jason priestly on June 14 2002 12:49 EDT
-
Pooling HTTP Connections... by Q Werty on June 14 2002 09:36 EDT
- Pooling HTTP Connections... by jason priestly on June 14 2002 08:01 EDT
- Pooling HTTP Connections... by Kenny MacLeod on June 19 2002 10:52 EDT
- Pooling HTTP Connections... by Brian Chan on June 20 2002 15:55 EDT
- Pooling HTTP Connections... by jason priestly on June 23 2002 04:30 EDT
- Pooling HTTP Connections... by Wilfred Springer on June 24 2002 02:25 EDT
- Pooling HTTP Connections... by Kenny MacLeod on June 24 2002 05:51 EDT
- Pooling HTTP Connections... by Brian Chan on June 20 2002 15:55 EDT
-
Pooling HTTP Connections...[ Go to top ]
- Posted by: Q Werty
- Posted on: June 14 2002 07:36 EDT
- in response to jason priestly
Pooling HTTP connection il similar to other pooling object.
Basically :
- use a factory to get an instance of your HTTP connections
- dont forget to release it, via the factory, to your pool when no more used
- in your pool management don't forget to check and close your connections.
I don't advise you to re-code all pool management, but rather use existing librairies like
Jakarta Commons-pool -
Pooling HTTP Connections...[ Go to top ]
- Posted by: jason priestly
- Posted on: June 14 2002 08:01 EDT
- in response to Q Werty
How will this work in a J2EE environment. I guess the pooling class stops threads that try to get a connection when there is no free connection. Is this ok in a J2EE environment?
Has someone tried this with HTTP connections?
-
Pooling HTTP Connections...[ Go to top ]
- Posted by: Q Werty
- Posted on: June 14 2002 09:36 EDT
- in response to jason priestly
What's happen when there is no more free object depend on your choices. Jakarta Commons-pool enable you :
- to reject immediatly demand of new HTTP connection with a "pool exhausted exception"
- to increase pool size despite his limits
- to wait during N ms, expecting a free HTTP connection (exception after delay).
Keep in mind Jakarta Commons-pool was designed for server side applications, so may be thread safe. For exemple it's used in Tomcat 4.1.x series for it's database pooling (DBCP).
(NOTE : I'am not a Jakarta member, just a user ...) -
Pooling HTTP Connections...[ Go to top ]
- Posted by: jason priestly
- Posted on: June 14 2002 12:49 EDT
- in response to Q Werty
I tried the apache commons library and it looks. But I found out that I cannot use HttpURLConnection. Since calling HttpURLConnection.setRequestProperty throws an exception after getting an InputStream from it. I need to set the Cookie header field for each request since the connection can be reused by a different user.
But I guess I can use the Socket class with the commons library instead and set the cookie header every time. -
Pooling HTTP Connections...[ Go to top ]
- Posted by: Kenny MacLeod
- Posted on: June 19 2002 10:52 EDT
- in response to jason priestly
I doubt you'll have much luck in pooling HTTP connections. HTTP is not a persistent protocl, it's not designed for multi requests/responses on the same connection.
Butr it seems to me that pooling connections isn't really what you want. Rather, you want to limit the number of simultaneous connections. You could configure commons-pool to open and close the connections when they are requested/returned to the pool. It would also allow you to limit the number of simultaneous connections, and block if there are none immediately available. -
Pooling HTTP Connections...[ Go to top ]
- Posted by: Brian Chan
- Posted on: June 20 2002 15:55 EDT
- in response to Kenny MacLeod
I agree with Kenny. HTTPURLConnection is stateless. Every time you create a URL connection, it's associated with the resource(ie jsp/servlet/...) you are fetching. Limiting user connections to your second server is a good way to solve your problem. -
Pooling HTTP Connections...[ Go to top ]
- Posted by: jason priestly
- Posted on: June 23 2002 04:30 EDT
- in response to Brian Chan
I also think that pooling connections might be difficult/impossible now that I have looked in to the problem. I just have to wait for a new protocol or version of HTTP. -
Pooling HTTP Connections...[ Go to top ]
- Posted by: Wilfred Springer
- Posted on: June 24 2002 02:25 EDT
- in response to Kenny MacLeod
HTTP 1.1 *does* support persistent connections. In other words, you *can* reuse the same TCP/IP connection to access several resources. -
Pooling HTTP Connections...[ Go to top ]
- Posted by: Kenny MacLeod
- Posted on: June 24 2002 05:51 EDT
- in response to Wilfred Springer
The protocol might support it to some extent, but HttpURLConnection doesn't. HTTP 1.1 has the ability to grab a bunch of stuff from one connection (e.g. the web page + images), but it's still not designed for multi-requests across a long period of time.