jnan77 / jsonrpc4j

Automatically exported from code.google.com/p/jsonrpc4j
0 stars 0 forks source link

JsonRpcHttpClient Opens a New Connection for Every Request #42

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

I was performing a load test which makes RPC calls repeatedly using a single 
JsonRpcHttpClient instance. After about 50000 calls, the system ran out of 
ports and started throwing exceptions. A closer look at the source code 
revealed that JsonRpcHttpClient never closes the InputStream returned by the 
HttpURLConnection. Therefore every time URL.openConnection is called, a brand 
new connection is opened at the lower layers. This is slow, leads to poor 
connection reuse and if done long enough, will drive the system out of sockets.

I made a small tweak in the JsonRpcHttpClient class to close the InputStream, 
and after that was able to successfully run my load test (which executes well 
over 300,000 RPC calls)

What is the expected output? What do you see instead?

The system shouldn't run out of sockets due to repeated RPC calls.

What version of the product are you using? On what operating system?

Version 0.25 on Ubuntu Linux

Please provide any additional information below.

Java 1.7

Original issue reported on code.google.com by hiranya...@gmail.com on 7 Nov 2012 at 11:46

GoogleCodeExporter commented 8 years ago
Some of the exceptions thrown:

java.lang.reflect.UndeclaredThrowableException
    at $Proxy5.echoString(Unknown Source)
    at edu.ucsb.cs.rpc.json.client.JsonClient.echoString(JsonClient.java:80)
    at edu.ucsb.cs.rpc.base.RPCEvaluation.invoke(RPCEvaluation.java:69)
    at edu.ucsb.cs.rpc.base.RPCEvaluation.run(RPCEvaluation.java:56)
    at edu.ucsb.cs.rpc.base.Main.main(Main.java:90)
Caused by: java.net.ConnectException: Cannot assign requested address
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
    at java.net.Socket.connect(Socket.java:579)
    at sun.net.NetworkClient.doConnect(NetworkClient.java:175)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:378)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:473)
    at sun.net.www.http.HttpClient.<init>(HttpClient.java:203)
    at sun.net.www.http.HttpClient.New(HttpClient.java:290)
    at sun.net.www.http.HttpClient.New(HttpClient.java:306)
    at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:995)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:974)
    at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:849)
    at com.googlecode.jsonrpc4j.JsonRpcHttpClient.openConnection(JsonRpcHttpClient.java:193)
    at com.googlecode.jsonrpc4j.JsonRpcHttpClient.invoke(JsonRpcHttpClient.java:133)
    at com.googlecode.jsonrpc4j.ProxyUtil$3.invoke(ProxyUtil.java:187)
    ... 5 more
java.lang.reflect.UndeclaredThrowableException
    at $Proxy5.echoString(Unknown Source)
    at edu.ucsb.cs.rpc.json.client.JsonClient.echoString(JsonClient.java:80)
    at edu.ucsb.cs.rpc.base.RPCEvaluation.invoke(RPCEvaluation.java:69)
    at edu.ucsb.cs.rpc.base.RPCEvaluation.run(RPCEvaluation.java:56)
    at edu.ucsb.cs.rpc.base.Main.main(Main.java:90)
Caused by: java.net.ConnectException: Cannot assign requested address
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
    at java.net.Socket.connect(Socket.java:579)
    at sun.net.NetworkClient.doConnect(NetworkClient.java:175)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:378)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:473)
    at sun.net.www.http.HttpClient.<init>(HttpClient.java:203)
    at sun.net.www.http.HttpClient.New(HttpClient.java:290)
    at sun.net.www.http.HttpClient.New(HttpClient.java:306)
    at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:995)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:974)
    at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:849)
    at com.googlecode.jsonrpc4j.JsonRpcHttpClient.openConnection(JsonRpcHttpClient.java:193)
    at com.googlecode.jsonrpc4j.JsonRpcHttpClient.invoke(JsonRpcHttpClient.java:133)
    at com.googlecode.jsonrpc4j.ProxyUtil$3.invoke(ProxyUtil.java:187)
    ... 5 more
java.lang.reflect.UndeclaredThrowableException
    at $Proxy5.echoString(Unknown Source)
    at edu.ucsb.cs.rpc.json.client.JsonClient.echoString(JsonClient.java:80)
    at edu.ucsb.cs.rpc.base.RPCEvaluation.invoke(RPCEvaluation.java:69)
    at edu.ucsb.cs.rpc.base.RPCEvaluation.run(RPCEvaluation.java:56)
    at edu.ucsb.cs.rpc.base.Main.main(Main.java:90)
Caused by: java.net.ConnectException: Cannot assign requested address
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
    at java.net.Socket.connect(Socket.java:579)
    at sun.net.NetworkClient.doConnect(NetworkClient.java:175)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:378)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:473)
    at sun.net.www.http.HttpClient.<init>(HttpClient.java:203)
    at sun.net.www.http.HttpClient.New(HttpClient.java:290)
    at sun.net.www.http.HttpClient.New(HttpClient.java:306)
    at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:995)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:974)
    at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:849)
    at com.googlecode.jsonrpc4j.JsonRpcHttpClient.openConnection(JsonRpcHttpClient.java:193)
    at com.googlecode.jsonrpc4j.JsonRpcHttpClient.invoke(JsonRpcHttpClient.java:133)
    at com.googlecode.jsonrpc4j.ProxyUtil$3.invoke(ProxyUtil.java:187)
    ... 5 more
java.lang.reflect.UndeclaredThrowableException
    at $Proxy5.echoString(Unknown Source)
    at edu.ucsb.cs.rpc.json.client.JsonClient.echoString(JsonClient.java:80)
    at edu.ucsb.cs.rpc.base.RPCEvaluation.invoke(RPCEvaluation.java:69)
    at edu.ucsb.cs.rpc.base.RPCEvaluation.run(RPCEvaluation.java:56)
    at edu.ucsb.cs.rpc.base.Main.main(Main.java:90)
Caused by: java.net.ConnectException: Cannot assign requested address
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
    at java.net.Socket.connect(Socket.java:579)
    at sun.net.NetworkClient.doConnect(NetworkClient.java:175)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:378)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:473)
    at sun.net.www.http.HttpClient.<init>(HttpClient.java:203)
    at sun.net.www.http.HttpClient.New(HttpClient.java:290)
    at sun.net.www.http.HttpClient.New(HttpClient.java:306)
    at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:995)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:974)
    at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:849)
    at com.googlecode.jsonrpc4j.JsonRpcHttpClient.openConnection(JsonRpcHttpClient.java:193)
    at com.googlecode.jsonrpc4j.JsonRpcHttpClient.invoke(JsonRpcHttpClient.java:133)
    at com.googlecode.jsonrpc4j.ProxyUtil$3.invoke(ProxyUtil.java:187)
    ... 5 more
java.lang.reflect.UndeclaredThrowableException
    at $Proxy5.echoString(Unknown Source)
    at edu.ucsb.cs.rpc.json.client.JsonClient.echoString(JsonClient.java:80)
    at edu.ucsb.cs.rpc.base.RPCEvaluation.invoke(RPCEvaluation.java:69)
    at edu.ucsb.cs.rpc.base.RPCEvaluation.run(RPCEvaluation.java:56)
    at edu.ucsb.cs.rpc.base.Main.main(Main.java:90)
Caused by: java.net.ConnectException: Cannot assign requested address
    at java.net.PlainSocketImpl.socketConnect(Native Meth

Original comment by hiranya...@gmail.com on 7 Nov 2012 at 11:58

GoogleCodeExporter commented 8 years ago
Attaching the simple fix I made. 

Original comment by hiranya...@gmail.com on 8 Nov 2012 at 12:01

Attachments:

GoogleCodeExporter commented 8 years ago
If the new JsonRpcHttpAsyncClient class attached to issue#43 is integrated, it 
also solves this problem.

Original comment by brett.wo...@gmail.com on 22 Nov 2012 at 6:32

GoogleCodeExporter commented 8 years ago
Thanks for catching this, i'll add it to the next release

Original comment by brian.di...@gmail.com on 28 Nov 2012 at 7:53

GoogleCodeExporter commented 8 years ago
Included in next release.

Original comment by brian.di...@gmail.com on 28 Nov 2012 at 8:35