You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-commits@lucene.apache.org by sh...@apache.org on 2009/04/13 10:42:05 UTC
svn commit: r764371 - in /lucene/solr/trunk: CHANGES.txt
src/java/org/apache/solr/handler/SnapPuller.java
Author: shalin
Date: Mon Apr 13 08:42:04 2009
New Revision: 764371
URL: http://svn.apache.org/viewvc?rev=764371&view=rev
Log:
SOLR-1096 -- Introduced httpConnTimeout and httpReadTimeout in replication slave configuration to avoid stalled replication
Modified:
lucene/solr/trunk/CHANGES.txt
lucene/solr/trunk/src/java/org/apache/solr/handler/SnapPuller.java
Modified: lucene/solr/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/CHANGES.txt?rev=764371&r1=764370&r2=764371&view=diff
==============================================================================
--- lucene/solr/trunk/CHANGES.txt (original)
+++ lucene/solr/trunk/CHANGES.txt Mon Apr 13 08:42:04 2009
@@ -193,6 +193,8 @@
34. SOLR-1095: Fixed performance problem in the StopFilterFactory and simplified code. Added tests as well. (gsingers)
+35. SOLR-1096: Introduced httpConnTimeout and httpReadTimeout in replication slave configuration to avoid stalled
+ replication. (Jeff Newburn, Noble Paul, shalin)
Optimizations
----------------------
Modified: lucene/solr/trunk/src/java/org/apache/solr/handler/SnapPuller.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/handler/SnapPuller.java?rev=764371&r1=764370&r2=764371&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/handler/SnapPuller.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/handler/SnapPuller.java Mon Apr 13 08:42:04 2009
@@ -98,15 +98,23 @@
*/
private AtomicBoolean pollDisabled = new AtomicBoolean(false);
- private static final HttpClient client;
+ // HttpClient shared by all cores (used if timeout is not specified for a core)
+ private static HttpClient client;
+ // HttpClient for this instance if connectionTimeout or readTimeout has been specified
+ private final HttpClient myHttpClient;
- static {
+ private static synchronized HttpClient createHttpClient(String connTimeout, String readTimeout) {
+ if (connTimeout == null && readTimeout == null && client != null) return client;
MultiThreadedHttpConnectionManager mgr = new MultiThreadedHttpConnectionManager();
// Keeping a very high number so that if you have a large number of cores
// no requests are kept waiting for an idle connection.
mgr.getParams().setDefaultMaxConnectionsPerHost(10000);
mgr.getParams().setMaxTotalConnections(10000);
- client = new HttpClient(mgr);
+ mgr.getParams().setSoTimeout(connTimeout == null ? 5000 : Integer.parseInt(connTimeout)); //5 secs
+ mgr.getParams().setConnectionTimeout(readTimeout == null ? 10000 : Integer.parseInt(readTimeout)); //10 secs
+ HttpClient httpClient = new HttpClient(mgr);
+ if (client == null && connTimeout == null && readTimeout == null) client = httpClient;
+ return httpClient;
}
public SnapPuller(NamedList initArgs, ReplicationHandler handler, SolrCore sc) {
@@ -121,6 +129,9 @@
String compress = (String) initArgs.get(COMPRESSION);
useInternal = INTERNAL.equals(compress);
useExternal = EXTERNAL.equals(compress);
+ String connTimeout = (String) initArgs.get(HTTP_CONN_TIMEOUT);
+ String readTimeout = (String) initArgs.get(HTTP_READ_TIMEOUT);
+ myHttpClient = createHttpClient(connTimeout, readTimeout);
if (pollInterval != null && pollInterval > 0) {
startExecutorService();
} else {
@@ -168,7 +179,7 @@
private NamedList getNamedListResponse(PostMethod method) throws IOException {
try {
- int status = client.executeMethod(method);
+ int status = myHttpClient.executeMethod(method);
if (status != HttpStatus.SC_OK) {
throw new SolrException(SolrException.ErrorCode.SERVICE_UNAVAILABLE,
"Request failed for the url " + method);
@@ -965,7 +976,7 @@
if (bytesDownloaded > 0) {
post.addParameter(OFFSET, "" + bytesDownloaded);
}
- client.executeMethod(post);
+ myHttpClient.executeMethod(post);
InputStream is = post.getResponseBodyAsStream();
//wrap it using FastInputStream
if (useInternal) {
@@ -1062,4 +1073,8 @@
public static final String INTERVAL_ERR_MSG = "The " + POLL_INTERVAL + " must be in this format 'HH:mm:ss'";
private static final Pattern INTERVAL_PATTERN = Pattern.compile("(\\d*?):(\\d*?):(\\d*)");
+
+ private static final String HTTP_CONN_TIMEOUT = "httpConnTimeout";
+
+ private static final String HTTP_READ_TIMEOUT = "httpReadTimeout";
}