From 67757b425acc58a885c324fe38060d030e81bda4 Mon Sep 17 00:00:00 2001 From: Michael Peter Christen Date: Tue, 28 May 2013 11:38:45 +0200 Subject: [PATCH] use a retry handler with retryCount=0 because we usually expect requests to fail if we access non-permanently available resources (peers, web pages) and want to fail fast without repeating the same request which is doomed to fail. The previous appearance of http client connection had a 1-2-4-8-second timeout scheme, which caused that connection attempts lasted for 16 seconds. --- .../net/yacy/cora/federate/solr/instance/RemoteInstance.java | 2 ++ source/net/yacy/cora/protocol/http/HTTPClient.java | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/source/net/yacy/cora/federate/solr/instance/RemoteInstance.java b/source/net/yacy/cora/federate/solr/instance/RemoteInstance.java index 8bd736c82..e590191ca 100644 --- a/source/net/yacy/cora/federate/solr/instance/RemoteInstance.java +++ b/source/net/yacy/cora/federate/solr/instance/RemoteInstance.java @@ -51,6 +51,7 @@ import org.apache.http.impl.auth.BasicScheme; import org.apache.http.impl.client.BasicAuthCache; import org.apache.http.impl.client.BasicCredentialsProvider; import org.apache.http.impl.client.DefaultHttpClient; +import org.apache.http.impl.client.DefaultHttpRequestRetryHandler; import org.apache.http.impl.conn.PoolingClientConnectionManager; import org.apache.http.protocol.HttpContext; import org.apache.solr.client.solrj.SolrServer; @@ -140,6 +141,7 @@ public class RemoteInstance implements SolrInstance { HttpHost targetHost = new HttpHost(u.getHost(), u.getPort(), u.getProtocol()); authCache.put(targetHost, basicAuth); context.setAttribute(ClientContext.AUTH_CACHE, authCache); + this.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(0, false)); // no retries needed; we expect connections to fail; therefore we should not retry return context; } }; diff --git a/source/net/yacy/cora/protocol/http/HTTPClient.java b/source/net/yacy/cora/protocol/http/HTTPClient.java index d98dda4e3..d1358385c 100644 --- a/source/net/yacy/cora/protocol/http/HTTPClient.java +++ b/source/net/yacy/cora/protocol/http/HTTPClient.java @@ -84,6 +84,7 @@ import org.apache.http.entity.mime.content.ContentBody; import org.apache.http.entity.mime.content.StringBody; import org.apache.http.impl.client.BasicCredentialsProvider; import org.apache.http.impl.client.DefaultHttpClient; +import org.apache.http.impl.client.DefaultHttpRequestRetryHandler; import org.apache.http.impl.conn.PoolingClientConnectionManager; import org.apache.http.message.BasicHeaderElementIterator; import org.apache.http.params.BasicHttpParams; @@ -197,7 +198,8 @@ public class HTTPClient { ((DefaultHttpClient) httpClient).addRequestInterceptor(new GzipRequestInterceptor()); // uncompress gzip ((DefaultHttpClient) httpClient).addResponseInterceptor(new GzipResponseInterceptor()); - + // remove retries; we expect connections to fail; therefore we should not retry + ((DefaultHttpClient) httpClient).setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(0, false)); if (idledConnectionEvictor == null) { idledConnectionEvictor = new IdledConnectionEvictor(clientConnectionManager); idledConnectionEvictor.start();