Let me explain the situation.
I have a servlet that redirects outgoing GET / POST to another project in another domain (some kind of proxy), whose task is to process it and return some things (params and gif). I am using HttpClient 4.0.3 for this.
There are several GET / POST sent by my application at startup, so I set it once, when ThreadSafeClientConnManager processes several threads this way.
cm_params = new BasicHttpParams(); ConnManagerParams.setMaxTotalConnections(cm_params, 200); ConnPerRouteBean connPerRoute = new ConnPerRouteBean(); HttpHost localhost = new HttpHost("localhost"); connPerRoute.setMaxForRoute(new HttpRoute(localhost), 50); ConnManagerParams.setMaxConnectionsPerRoute(cm_params, connPerRoute); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register( new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); cm = new ThreadSafeClientConnManager(cm_params, schemeRegistry);
Then I create a new HttpClient with these parameters, which should be enough to handle a bunch of the request at the same time. Of course, I do this in public void service () for each GET / POST, but I use the same Httpclient object after creating it.
httpclient = new DefaultHttpClient(cm, cm_params);
After that, I create my POST and send it via execute, with all the required parameters and with such triple confirmation.
HttpPost httpPost = new HttpPost(target+tmpString); httpPost.setHeader("Host", request.getHeader("host")); httpPost.setHeader("User-Agent", request.getHeader("user-agent")); httpPost.setHeader("Accept-Encoding", request.getHeader("accept-encoding")); httpPost.setHeader("Accept", request.getHeader("accept")); ..etc.. UrlEncodedFormEntity urlEncodedFormEntity = new UrlEncodedFormEntity(params); urlEncodedFormEntity.setContentEncoding(HTTP.UTF_8); httpPost.setEntity(urlEncodedFormEntity); HttpResponse response = httpclient.execute(httpPost);
Finally, I read the stream and processed the entities ...
OutputStream os = res.getOutputStream(); InputStream is = response.getEntity().getContent(); byte[] buf = new byte[1024]; for(int n;(n=is.read(buf))!=-1;) { os.write(buf, 0, n); }
So my problem is that the code works fine when I load my page. 4 requests sent (1 GET, 3 POST). Initially, I return some parameters and 1 small gif, which I print on my page.
But as soon as I begin to experience a stress test of my application, I.E. loading the same page in 4-5 tabs, my application seems to accidentally fit when I execute several POSTs at the same time. I thought that I would not have problems, even if I use the same Httpclient object , since I correctly formulated my ThreadSafeClientConnManager (I think?), So that it works with multiple threads.
Does anyone know what I'm doing wrong? If I load my tabs 1 on 1, it does not freeze. Just when I update more than one tab at a time.
Who has the key ?: S (sry english is not my first language ^^;)