https://issues.apache.org/bugzilla/show_bug.cgi?id=47603
Summary: Connection Refused when open up 1000 http clients to reach a server url Product: JMeter Version: 2.3.4 Platform: PC OS/Version: Windows XP Status: NEW Severity: major Priority: P2 Component: HTTP AssignedTo: jmeter-dev@jakarta.apache.org ReportedBy: ysxsu...@hotmail.com Hi, For 50% of time, I am getting the exception or something similar when I run 1000 threads to hit some server url. This is the exception stack: <httpSample t="1002" s="false" rc="Non HTTP response code: java.net.ConnectException" rm="Non HTTP response message: Connection refused: connect" tn="getAllCategoryGroup 1-508" sc="1" ec="1" ng="115" na="115"> <responseData class="java.lang.String">java.net.ConnectException: Connection refused: connect
 at java.net.PlainSocketImpl.socketConnect(Native Method)
 at java.net.PlainSocketImpl.doConnect(Unknown Source)
 at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
 at java.net.PlainSocketImpl.connect(Unknown Source)
 at java.net.SocksSocketImpl.connect(Unknown Source)
 at java.net.Socket.connect(Unknown Source)
 at java.net.Socket.connect(Unknown Source)
 at sun.net.NetworkClient.doConnect(Unknown Source)
 at sun.net.www.http.HttpClient.openServer(Unknown Source)
 at sun.net.www.http.HttpClient.openServer(Unknown Source)
 at sun.net.www.http.HttpClient.<init>(Unknown Source)
 at sun.net.www.http.HttpClient.New(Unknown Source)
 at sun.net.www.http.HttpClient.New(Unknown Source)
 at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
 at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
 at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
 at org.apache.jmeter.protocol.http.sampler.HTTPSampler.sample(HTTPSampler.java:490)
 at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1037)
 at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1023)
 at org.apache.jmeter.threads.JMeterThread.process_sampler(JMeterThread.java:346)
 at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:243)
 at java.lang.Thread.run(Unknown Source)
 </responseData> Sometimes, it is another similar exception: <httpSample t="36" s="false" rc="Non HTTP response code: java.net.BindException" rm="Non HTTP response message: Address already in use: connect" tn="getAllCategoryGroup 1-849" sc="1" ec="1" ng="1000" na="1000"> <responseData class="java.lang.String">java.net.BindException: Address already in use: connect
 at java.net.PlainSocketImpl.socketConnect(Native Method)
 at java.net.PlainSocketImpl.doConnect(Unknown Source)
 at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
 at java.net.PlainSocketImpl.connect(Unknown Source)
 at java.net.SocksSocketImpl.connect(Unknown Source)
 at java.net.Socket.connect(Unknown Source)
 at java.net.Socket.connect(Unknown Source)
 at sun.net.NetworkClient.doConnect(Unknown Source)
 at sun.net.www.http.HttpClient.openServer(Unknown Source)
 at sun.net.www.http.HttpClient.openServer(Unknown Source)
 at sun.net.www.http.HttpClient.<init>(Unknown Source)
 at sun.net.www.http.HttpClient.New(Unknown Source)
 at sun.net.www.http.HttpClient.New(Unknown Source)
 at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
 at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
 at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
 at org.apache.jmeter.protocol.http.sampler.HTTPSampler.sample(HTTPSampler.java:490)
 at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1037)
 at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1023)
 at org.apache.jmeter.threads.JMeterThread.process_sampler(JMeterThread.java:346)
 at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:243)
 at java.lang.Thread.run(Unknown Source)
 </responseData> </httpSample> Then I check out the JMeter's code HttpSampler.java at line 490: for (retry = 0; retry <= MAX_CONN_RETRIES; retry++) { try { conn = setupConnection(url, method, res); // Attempt the connection: savedConn = conn; conn.connect(); (======= Line 490 =====) break; } catch (BindException e) { if (retry >= MAX_CONN_RETRIES) { log.error("Can't connect after "+retry+" retries, "+e); throw e; } protected HttpURLConnection setupConnection(URL u, String method, HTTPSampleResult res) throws IOException { ...} The SetupConnection just open a HttpURLConnection, here is the exerpt: conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); //whatever the http method is This is the very high level what setupConnection is doing. Usually, (by my limited java net programming knowledge...), you are ready to get response, but instead, in the calling method at line 490, it immediately calls URLConnection.connect (out of that HttpURLConnection instance. It is like in a short time, you are making two connection out of that socket. After that logic, then it will eventually pull out the response logic. Why is that? I wrote a small program to simulate late, and I also get Connection refused exception, here is the code: import java.net.HttpURLConnection; import java.net.URL; public class HttpUrlConnectionTest { public static void main(String[] args) { int total = 5000; ConnectionThread[] ts = new ConnectionThread[total]; for (int i=0; i<total;i++) { ts[i] = new ConnectionThread(); } for (int i=0; i<total; i++) { ts[i].start(); } System.out.println("all threads are done..."); } public static class ConnectionThread extends Thread { public void run() { try { URL url = new URL("http://localhost:8080/TestPodCast/TestPodCastServlet?test=testAllCategory"); HttpURLConnection conn = (HttpURLConnection)url.openConnection(); conn.setRequestMethod("GET"); conn.setRequestProperty("Connection", "keep-alive"); conn.connect(); // With this line, I am getting that Connection Refused exception. Without this line, the request went ok. } catch (Exception ex) { ex.printStackTrace(); } } } } BTW, my URL just return almost no http body at all. It just simply process a request. The thread group I was using for jmeter is 1000 concurrent thread. Each do around 20 - 200 loops. Can someone let me know if this is truely the jmeter source problem, please do explain why the second connect method call is necessary. Thanks. Shaoxian Yang -- Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are the assignee for the bug. --------------------------------------------------------------------- To unsubscribe, e-mail: jmeter-dev-unsubscr...@jakarta.apache.org For additional commands, e-mail: jmeter-dev-h...@jakarta.apache.org