获取负载测试的NoHttpResponseException [英] get NoHttpResponseException for load testing

查看:113
本文介绍了获取负载测试的NoHttpResponseException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的应用程序运行负载测试。我有两个服务器:一个用我的应用程序和一个虚拟服务器负责让我回复。

I'm running load tests for my application. I have two servers: one with my application and a dummy-server that is responsible to get me responses.

在我的虚拟服务器中,我有以下jsp代码:

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);
%>

我正在使用tomcat7运行应用程序。我的server.xml连接池(在两个服务器中)看起来像:

I'm running the application with tomcat7. My server.xml connection pool (in both servers) looks like:

<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" />

我从服务器运行的java代码是:

The java code I'm running from the servers is:

 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);
    }

我正在使用50个并发线程(没有循环)运行Jmetter并获取很多例外情况如下:

I'm running Jmetter with 50 concurrent threads (without a loop) and get a lot of exceptions like this:

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

当我只运行5或10个并发线程时,一切正常。

While I'm running just 5 or 10 concurrent threads everything works ok.

请问我的设置可能有什么问题?据我所知,我没有看到50个并发线程请求有任何错误。

Could you please advice me what could be wrong in my setup? For my understanding, I don't see any errors for the 50 concurrent thread requests.

推荐答案

我找到了根本原因问题。

I've found the root cause of the problem.

由于某种原因,连接变得无效,并且池不知道它。

For some reason the connection becomes invalid and pool is not aware of it.

在这种情况下,抛出 NoHttpResponseException 并且请求完全失败。我认为这些问题应该在HTTP客户端池层中解决,并且对我的代码是透明的,但这不是它的行为。

In this case the NoHttpResponseException is thrown and the request simply fails. I thought that such issues should be resolved in HTTP client pool layer and be transparent to my code, but this is not as it acts.

要解决这个问题,<$应覆盖HTTP客户端中的c $ c> HttpRequestRetryHandler :

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;
      }
   }); 

这篇关于获取负载测试的NoHttpResponseException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆