thomas created HTTPCLIENT-1334:
----------------------------------
Summary: PoolingClientConnectionManager Performance issue
Key: HTTPCLIENT-1334
URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1334
Project: HttpComponents HttpClient
Issue Type: Test
Components: HttpConn
Affects Versions: 4.2.2
Environment: mac osx
Reporter: thomas
I have the following code which use a PoolingClientConnectionManager:
public static void main(String[] args) {
int NoOfSimultaneousRequest = 1000;
int poolsize =1000;
try{
if (poolsize>0){
mgr = new PoolingClientConnectionManager();
mgr.setMaxTotal(poolsize);
mgr.setDefaultMaxPerRoute(poolsize);
httpclient = new DefaultHttpClient(mgr);
}
Thread [] tr = new Thread[NoOfSimultaneousRequest];
for(int i=0;i<NoOfSimultaneousRequest;i++){
MultipleThreadsTest multiTest = new MultipleThreadsTest();
Thread t = new Thread(multiTest);
tr[i] = new Thread(multiTest);
}
for(int i=0;i<NoOfSimultaneousRequest;i++){
tr[i].start();
}
for(int i=0;i<NoOfSimultaneousRequest;i++){
tr[i].join();
}
}catch (Exception e){
e.printStackTrace();
}finally{
if (mgr!=null){
mgr.shutdown();
}
if (httpclient!=null){
httpclient.getConnectionManager().shutdown();
}
}
}
public void run() {
if (mgr==null){ //if no connection manager then create multiple
instances of defaulthttpClient
HttpClient hc = new DefaultHttpClient();
response = invokeWebService(hc,"http://urltoPost") ;
}else{ //if connection manager is used then use only one instance
of httpclient
response = invokeWebService(httpclient,"http://urltoPost") ;
}
}
private static String invokeWebService(HttpClient httpClient,String url){
HttpPost httpPost = new HttpPost(new URI(url));
try{
String response = httpClient.execute(httpPost,new
BasicResponseHandler());
return response;
}catch(Exception e){
}finally{
if (httpPost != null) {
httpPost.releaseConnection();
}
}
}
My problem is , when I turn off pooling (by setting poolSize<=0) the code
performs much faster compared to pooling on (poolSize>0) .The only difference
between these two versions is , when using pooling , there is only one instance
of httpClient created (Apache recomended) and when pooling off , multiple
instances of httpclient is created .The code is supposed to perform better when
I use http conection pooling . But that is not happening . Do you see any issue
in the usage of connection manager?
Thanks & Regards Thomas
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]