File uploads fail every other attempt using timers.

Enable idle timeouts for servers that don't send Keep-Alive headers.
Bugzilla Id: 56119


git-svn-id: https://svn.apache.org/repos/asf/jmeter/trunk@1572390 13f79535-47bb-0310-9956-ffa450edef68

Former-commit-id: 3effb9b1c0
This commit is contained in:
Sebastian Bazley 2014-02-27 01:49:50 +00:00
parent 891cad4676
commit 18739f71d9
3 changed files with 31 additions and 1 deletions

View File

@ -382,6 +382,14 @@ log_level.jorphan=INFO
# Number of retries to attempt (default 0)
#httpclient4.retrycount=0
# Idle connection timeout (ms) to apply if the server does not send Keep-Alive headers
#httpclient4.idletimeout=0
# Note: this is currently an experimental fix
#---------------------------------------------------------------------------
# Apache HttpComponents HTTPClient configuration (HTTPClient 3.1)
#---------------------------------------------------------------------------
# Number of retries to attempt (default 0)
#httpclient3.retrycount=0

View File

@ -73,6 +73,7 @@ import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.params.ClientPNames;
import org.apache.http.client.params.CookiePolicy;
import org.apache.http.client.protocol.ResponseContentEncoding;
import org.apache.http.conn.ConnectionKeepAliveStrategy;
import org.apache.http.conn.params.ConnRoutePNames;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
@ -85,6 +86,7 @@ import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.AbstractHttpClient;
import org.apache.http.impl.client.DefaultConnectionKeepAliveStrategy;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.DefaultHttpRequestRetryHandler;
import org.apache.http.message.BasicNameValuePair;
@ -129,11 +131,27 @@ public class HTTPHC4Impl extends HTTPHCAbstractImpl {
private static final boolean STRICT_RFC_2616 = JMeterUtils.getPropDefault("jmeter.httpclient.strict_rfc2616", false);
/** retry count to be used (default 1); 0 = disable retries */
/** retry count to be used (default 0); 0 = disable retries */
private static final int RETRY_COUNT = JMeterUtils.getPropDefault("httpclient4.retrycount", 0);
/** Idle timeout to be applied to connections if no Keep-Alive header is sent by the server (default 0 = disable) */
private static final int IDLE_TIMEOUT = JMeterUtils.getPropDefault("httpclient4.idletimeout", 0);
private static final String CONTEXT_METRICS = "jmeter_metrics"; // TODO hack for metrics related to HTTPCLIENT-1081, to be removed later
private static final ConnectionKeepAliveStrategy IDLE_STRATEGY = new DefaultConnectionKeepAliveStrategy(){
@Override
public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
long duration = super.getKeepAliveDuration(response, context);
if (duration <= 0) {// none found by the superclass
log.debug("Setting keepalive to " + IDLE_TIMEOUT);
return IDLE_TIMEOUT;
}
return duration; // return the super-class value
}
};
/**
* Special interceptor made to keep metrics when connection is released for some method like HEAD
* Otherwise calling directly ((HttpConnection) localContext.getAttribute(ExecutionContext.HTTP_CONNECTION)).getMetrics();
@ -629,6 +647,9 @@ public class HTTPHC4Impl extends HTTPHCAbstractImpl {
return new DefaultHttpRequestRetryHandler(RETRY_COUNT, false); // set retry count
}
};
if (IDLE_TIMEOUT > 0) {
((AbstractHttpClient) httpClient).setKeepAliveStrategy(IDLE_STRATEGY );
}
((AbstractHttpClient) httpClient).addResponseInterceptor(new ResponseContentEncoding());
((AbstractHttpClient) httpClient).addResponseInterceptor(METRICS_SAVER); // HACK
((AbstractHttpClient) httpClient).addRequestInterceptor(METRICS_RESETTER);

View File

@ -169,6 +169,7 @@ A workaround is to use a Java 7 update 40 runtime which fixes this issue.
<ul>
<li><bugzilla>55959</bugzilla> - improve error message when Test Script Recorder fails due to I/O problem</li>
<li><bugzilla>52013</bugzilla> - Test Script Recorder's Child View Results Tree does not take into account Test Script Recorder excluded/included URLs. Based on report and analysis of James Liang</li>
<li><bugzilla>56119</bugzilla> - File uploads fail every other attempt using timers. Enable idle timeouts for servers that don't send Keep-Alive headers.</li>
</ul>
<h3>Other samplers</h3>