HTTP Connection pooling


Performance and scalability: HTTP Connection pooling

  1. HTTP Connection pooling (6 messages)

    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.setRequestProperty("Connection", "Keep-Alive");
    os = httpconn.getOutputStream();
    printOnServer = new PrintWriter(os);

    for (int index = 1; index < 4; index++) {
       // Send request
       String s = "Some data";

       // get response
       is = httpconn.getInputStream();
       isr = new InputStreamReader(is);
       // Process response

    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.

    Threaded Messages (6)

  2. 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.
  3. Well, Thanks for the help. I am using Tomcat and I doubt wheather its available there.
  4. HTTP Connection pooling[ Go to top ]

    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.
  5. HTTP Connection pooling[ Go to top ]

    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.
  6. Performance of HTTP Client[ Go to top ]

    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.
  7. Performance of HTTP Client[ Go to top ]

    If you type "httpclient performance" into google, you will find the documentation about how to make it go fast. It will go very fast.