SOLR-4451: SolrJ, and SolrCloud internals, now use SystemDefaultHttpClient under the covers -- allowing many HTTP connection related properties to be controlled via 'standard' java system properties. (hossman)

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1445945 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Chris M. Hostetter 2013-02-13 21:45:57 +00:00
parent dc7bec58b1
commit f16037ec2d
13 changed files with 41 additions and 29 deletions

View File

@ -48,7 +48,7 @@
<jetty.version>8.1.8.v20121106</jetty.version>
<slf4j.version>1.6.4</slf4j.version>
<tika.version>1.2</tika.version>
<httpcomponents.version>4.1.3</httpcomponents.version>
<httpcomponents.version>4.2.3</httpcomponents.version>
<!-- RandomizedTesting library system properties -->
<tests.iters>1</tests.iters>

View File

@ -71,6 +71,10 @@ New Features
* SOLR-4370: Allow configuring commitWithin to do hard commits.
(Mark Miller, Senthuran Sivananthan)
* SOLR-4451: SolrJ, and SolrCloud internals, now use SystemDefaultHttpClient
under the covers -- allowing many HTTP connection related properties to be
controlled via 'standard' java system properties. (hossman)
Bug Fixes
----------------------

View File

@ -1 +0,0 @@
16cf5a6b78951f50713d29bfae3230a611dc01f0

View File

@ -0,0 +1 @@
37ced84d839a02fb856255eca85f0a4be95aa634

View File

@ -1 +0,0 @@
31cc0a151d458c4b99476805ede9c8accafb734c

View File

@ -0,0 +1 @@
5e92ec56abe188b865642a14e1a037c1253fc42e

View File

@ -1 +0,0 @@
d97e400d31bbeb36c1c60d2c3a9bbf2cdccf85a8

View File

@ -0,0 +1 @@
118ae1bc7f3aeeddfe564f0edfd79c11d09d17d1

View File

@ -21,9 +21,9 @@
<dependencies>
<dependency org="org.apache.zookeeper" name="zookeeper" rev="3.4.5" transitive="false"/>
<dependency org="org.apache.httpcomponents" name="httpcore" rev="4.1.4" transitive="false"/>
<dependency org="org.apache.httpcomponents" name="httpclient" rev="4.1.3" transitive="false"/>
<dependency org="org.apache.httpcomponents" name="httpmime" rev="4.1.3" transitive="false"/>
<dependency org="org.apache.httpcomponents" name="httpcore" rev="4.2.3" transitive="false"/>
<dependency org="org.apache.httpcomponents" name="httpclient" rev="4.2.3" transitive="false"/>
<dependency org="org.apache.httpcomponents" name="httpmime" rev="4.2.3" transitive="false"/>
<dependency org="commons-io" name="commons-io" rev="${commons-io.version}" transitive="false"/>
<dependency org="org.slf4j" name="jcl-over-slf4j" rev="1.6.4" transitive="false"/>
<dependency org="org.codehaus.woodstox" name="wstx-asl" rev="3.2.7" transitive="false"/>

View File

@ -79,8 +79,7 @@ public class ConcurrentUpdateSolrServer extends SolrServer {
final int threadCount;
/**
* Uses an internal ThreadSafeClientConnManager to manage http
* connections.
* Uses an internaly managed HttpClient instance.
*
* @param solrServerUrl
* The Solr server URL
@ -95,9 +94,7 @@ public class ConcurrentUpdateSolrServer extends SolrServer {
}
/**
* Uses the supplied HttpClient to send documents to the Solr server, the
* HttpClient should be instantiated using a
* ThreadSafeClientConnManager.
* Uses the supplied HttpClient to send documents to the Solr server.
*/
public ConcurrentUpdateSolrServer(String solrServerUrl,
HttpClient client, int queueSize, int threadCount) {

View File

@ -35,8 +35,10 @@ import org.apache.http.client.HttpClient;
import org.apache.http.client.params.ClientParamBean;
import org.apache.http.entity.HttpEntityWrapper;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.SystemDefaultHttpClient;
import org.apache.http.impl.client.DefaultHttpRequestRetryHandler;
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager; // jdoc
import org.apache.http.impl.conn.PoolingClientConnectionManager;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.protocol.HttpContext;
import org.apache.solr.common.params.ModifiableSolrParams;
@ -94,14 +96,12 @@ public class HttpClientUtil {
*
* @param params
* http client configuration, if null a client with default
* configuration (no additional configuration) is created that uses
* ThreadSafeClientConnManager.
* configuration (no additional configuration) is created.
*/
public static HttpClient createClient(final SolrParams params) {
final ModifiableSolrParams config = new ModifiableSolrParams(params);
logger.info("Creating new http client, config:" + config);
final ThreadSafeClientConnManager mgr = new ThreadSafeClientConnManager();
final DefaultHttpClient httpClient = new DefaultHttpClient(mgr);
final DefaultHttpClient httpClient = new SystemDefaultHttpClient();
configureClient(httpClient, config);
return httpClient;
}
@ -153,25 +153,35 @@ public class HttpClientUtil {
/**
* Set max connections allowed per host. This call will only work when
* {@link ThreadSafeClientConnManager} is used.
* {@link ThreadSafeClientConnManager} or
* {@link PoolingClientConnectionManager} is used.
*/
public static void setMaxConnectionsPerHost(HttpClient httpClient,
int max) {
if(httpClient.getConnectionManager() instanceof ThreadSafeClientConnManager) {
// would have been nice if there was a common interface
if (httpClient.getConnectionManager() instanceof ThreadSafeClientConnManager) {
ThreadSafeClientConnManager mgr = (ThreadSafeClientConnManager)httpClient.getConnectionManager();
mgr.setDefaultMaxPerRoute(max);
} else if (httpClient.getConnectionManager() instanceof PoolingClientConnectionManager) {
PoolingClientConnectionManager mgr = (PoolingClientConnectionManager)httpClient.getConnectionManager();
mgr.setDefaultMaxPerRoute(max);
}
}
/**
* Set max total connections allowed. This call will only work when
* {@link ThreadSafeClientConnManager} is used.
* {@link ThreadSafeClientConnManager} or
* {@link PoolingClientConnectionManager} is used.
*/
public static void setMaxConnections(final HttpClient httpClient,
int max) {
if(httpClient.getConnectionManager() instanceof ThreadSafeClientConnManager) {
// would have been nice if there was a common interface
if (httpClient.getConnectionManager() instanceof ThreadSafeClientConnManager) {
ThreadSafeClientConnManager mgr = (ThreadSafeClientConnManager)httpClient.getConnectionManager();
mgr.setMaxTotal(max);
} else if (httpClient.getConnectionManager() instanceof PoolingClientConnectionManager) {
PoolingClientConnectionManager mgr = (PoolingClientConnectionManager)httpClient.getConnectionManager();
mgr.setMaxTotal(max);
}
}

View File

@ -23,8 +23,8 @@ import java.util.concurrent.atomic.AtomicInteger;
import org.apache.http.auth.AuthScope;
import org.apache.http.client.HttpClient;
import org.apache.http.client.params.ClientPNames;
import org.apache.http.impl.conn.PoolingClientConnectionManager;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
import org.apache.http.params.HttpConnectionParams;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.params.SolrParams;
@ -52,9 +52,9 @@ public class HttpClientUtilTest {
params.set(HttpClientUtil.PROP_USE_RETRY, false);
DefaultHttpClient client = (DefaultHttpClient) HttpClientUtil.createClient(params);
assertEquals(12345, HttpConnectionParams.getConnectionTimeout(client.getParams()));
assertEquals(ThreadSafeClientConnManager.class, client.getConnectionManager().getClass());
assertEquals(22345, ((ThreadSafeClientConnManager)client.getConnectionManager()).getMaxTotal());
assertEquals(32345, ((ThreadSafeClientConnManager)client.getConnectionManager()).getDefaultMaxPerRoute());
assertEquals(PoolingClientConnectionManager.class, client.getConnectionManager().getClass());
assertEquals(22345, ((PoolingClientConnectionManager)client.getConnectionManager()).getMaxTotal());
assertEquals(32345, ((PoolingClientConnectionManager)client.getConnectionManager()).getDefaultMaxPerRoute());
assertEquals(42345, HttpConnectionParams.getSoTimeout(client.getParams()));
assertEquals(HttpClientUtil.NO_RETRY, client.getHttpRequestRetryHandler());
assertEquals("pass", client.getCredentialsProvider().getCredentials(new AuthScope("127.0.0.1", 1234)).getPassword());

View File

@ -7,7 +7,6 @@ import static org.junit.Assert.*;
import java.net.MalformedURLException;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.solr.client.solrj.ResponseParser;
import org.junit.Test;
@ -28,6 +27,8 @@ import org.junit.Test;
* limitations under the License.
*/
import org.apache.solr.common.params.ModifiableSolrParams;
/**
* Test the LBHttpSolrServer.
*/
@ -42,14 +43,14 @@ public class LBHttpSolrServerTest {
*/
@Test
public void testLBHttpSolrServerHttpClientResponseParserStringArray() throws MalformedURLException {
LBHttpSolrServer testServer = new LBHttpSolrServer(new DefaultHttpClient(), (ResponseParser) null);
LBHttpSolrServer testServer = new LBHttpSolrServer(HttpClientUtil.createClient(new ModifiableSolrParams()), (ResponseParser) null);
HttpSolrServer httpServer = testServer.makeServer("http://127.0.0.1:8080");
assertNull("Generated server should have null parser.", httpServer.getParser());
ResponseParser parser = new BinaryResponseParser();
testServer = new LBHttpSolrServer(new DefaultHttpClient(), parser);
testServer = new LBHttpSolrServer(HttpClientUtil.createClient(new ModifiableSolrParams()), parser);
httpServer = testServer.makeServer("http://127.0.0.1:8080");
assertEquals("Invalid parser passed to generated server.", parser, httpServer.getParser());
}
}
}