I am trying to write a client application which is going to communicate to a HTTP server. From this client I am expecting heavy number of requests like 1000 requests per second. I want to avoid batch requests for some reason. I opened a connection with the server using following code snippet:
===============================================
// Address
String address = "http://myhost:8080//servlet/SomeServlet";
url = new URL(address);
httpconn = (HttpURLConnection) url.openConnection();
httpconn.setRequestMethod("POST");
httpconn.setDoOutput(true);
httpconn.setRequestProperty("Connection", "Keep-Alive");
httpconn.setUseCaches(false);
httpconn.connect();
os = httpconn.getOutputStream();
printOnServer = new PrintWriter(os);
for (int index = 1; index < 4; index++) {
// Send request
String s = "Some data";
printOnServer.print(s);
printOnServer.flush();
// get response
is = httpconn.getInputStream();
isr = new InputStreamReader(is);
// Process response
printOnServer.close();
}
===============================================
I am getting the response from server for first iteration of the for loop. I am expecting some repetitive response from the server.
I am planning to avoid the connection establishment time by connection pool. Can somebody tell me how to create a HTTP Connection pool.
-
HTTP Connection pooling (6 messages)
- Posted by: Sachin Dharmapurikar
- Posted on: November 10 2005 07:47 EST
Threaded Messages (6)
- Provoking: write a JCA connector! by Fl??vio Stutz on November 12 2005 21:09 EST
- Provoking: write a JCA connector! by Sachin Dharmapurikar on November 14 2005 21:04 EST
- HTTP Connection pooling by hanuman gahlot on November 12 2005 21:34 EST
- HTTP Connection pooling by Eric Bowman on November 13 2005 20:07 EST
- Performance of HTTP Client by Sachin Dharmapurikar on November 14 2005 21:03 EST
- Performance of HTTP Client by Eric Bowman on November 17 2005 08:27 EST
- Performance of HTTP Client by Sachin Dharmapurikar on November 14 2005 21:03 EST
-
Provoking: write a JCA connector![ Go to top ]
- Posted by: Fl??vio Stutz
- Posted on: November 12 2005 21:09 EST
- in response to Sachin Dharmapurikar
Depending on your scalability needs, may be you would write a JCA connector to use the pooling management done by the J2EE container.
I know this is not easy, but with little read at the specs you will be amazed.
Tell me what you think about this!
Good work. -
Provoking: write a JCA connector![ Go to top ]
- Posted by: Sachin Dharmapurikar
- Posted on: November 14 2005 21:04 EST
- in response to Fl??vio Stutz
Well, Thanks for the help. I am using Tomcat and I doubt wheather its available there. -
HTTP Connection pooling[ Go to top ]
- Posted by: hanuman gahlot
- Posted on: November 12 2005 21:34 EST
- in response to Sachin Dharmapurikar
You can only create the URL object and can cache it, since HTTP is the stateless protocol you will have to open the connection every time and you won't be able to cache it. -
HTTP Connection pooling[ Go to top ]
- Posted by: Eric Bowman
- Posted on: November 13 2005 20:07 EST
- in response to Sachin Dharmapurikar
Do NOT use HttpURLConnection for this. It's not built for it, and it's very hard to deal with. I used it for a high performance application, and it was like a boat anchor around my neck.
Use HttpClient from Jakarta Commons instead. It's a much more sensible architecture, and you can extend it in any way you want, and since it's open source, you can fix it where it's broken (which it isn't). Trying to fix bugs in HttpURLConnection, or understand why it retries for any IOException, is a losing proposition. -
Performance of HTTP Client[ Go to top ]
- Posted by: Sachin Dharmapurikar
- Posted on: November 14 2005 21:03 EST
- in response to Eric Bowman
Well, I wanted to build my own implementation which is very lightweight. Now even I am loosing time hence I am not in position to re-invent the wheels. Will you please guide me about the performance of the HTTPClient? For such high number of requests, won't it be little fat? If anybody is having any experience it will be welcome. -
Performance of HTTP Client[ Go to top ]
- Posted by: Eric Bowman
- Posted on: November 17 2005 08:27 EST
- in response to Sachin Dharmapurikar
If you type "httpclient performance" into google, you will find the documentation about how to make it go fast. It will go very fast.