Get NoHttpResponseException for load testing

I run load tests for my application. I have two servers: one with my application and a dummy server that is responsible for the responses.

In my dummy server, I have the following jsp code:

<%@ page import="java.util.Random" %> <%@ page language="java" %> <%@ page session="false" %> <% String retVal = "some json string"; Thread.sleep(50); %> 

I am running an application with tomcat7. My server.xml connection pool (on both servers) looks like this:

 <Executor name="tomcatThreadPool" namePrefix="catalina-exec-" maxThreads="1500" minSpareThreads="1000" prestartminSpareThreads="true" /> <Connector port="9031" protocol="HTTP/1.1" connectionTimeout="20000" maxConnections="4000" executor="tomcatThreadPool" redirectPort="8443" /> 

The java code that I run from the servers:

  HttpPost post = new HttpPost(bidderUrl); post.setHeader("Content-Type", "application/json"); // I'm using http client with ThreadSafeClientConnManager // total conn = 500, max conn per route = 100, timeout=500millis HttpClient httpClient = httpClientFactory.getHttpClient(); try { post.setEntity(new StringEntity(jsobBidRequest)); HttpResponse response = httpClient.execute(post); ... catch (NoHttpResponseException e){ log.error(e); } 

I run Jmetter with 50 parallel threads (no loop) and get many exceptions like this:

 org.apache.http.NoHttpResponseException The target server failed to respond 

So far, I only run 5 or 10 simultaneous threads, everything is working fine.

Could you advise me what might be wrong in my setup? As far as I understand, I see no errors for 50 concurrent thread requests.

+14
java tomcat
May 13 '12 at 9:26
source share
3 answers

I found the root cause of the problem.

For some reason, the connection becomes invalid and the pool does not know about it.

In this case, a NoHttpResponseException is NoHttpResponseException , and the request simply fails. I thought that such problems should be resolved in the pool of HTTP client pools and transparent to my code, but that’s not how it works.

To solve this problem, the HttpRequestRetryHandler client in the HTTP client should be redefined:

 ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(schemeRegistry); ... DefaultHttpClient httpClient = new DefaultHttpClient(cm, params); httpClient.setHttpRequestRetryHandler(new HttpRequestRetryHandler() { @Override public boolean retryRequest(IOException exception, int executionCount, HttpContext context) { if (executionCount > 3) { LOGGER.warn("Maximum tries reached for client http pool "); return false; } if (exception instanceof org.apache.http.NoHttpResponseException) { LOGGER.warn("No response from server on " + executionCount + " call"); return true; } return false; } }); 
+30
May 21 '12 at 6:48 a.m.
source

This solution is for HttpClient 4.5 and later. DefaultHttpClient is deprecated.

 HttpClientBuilder clientBuilder = HttpClients.custom(); clientBuilder.setRetryHandler(new DefaultHttpRequestRetryHandler(3, false)); 
+4
Jan 19 '17 at 16:24
source

I sent a comment to the defect registered at https://issues.apache.org/jira/browse/HTTPCLIENT-1610 . As you can see, as soon as I reduce the inactive HTTP connection time before reuse from 2000 ms to 100 ms, I no longer see any NoHttpResponseException exception. I have not tested to find out what the threshold value is in my environment in order to invalidate the use of a static connection, but 100 ms is definitely short enough in my environment.

+1
Dec 14 '16 at 15:34
source



All Articles