Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reuse TCP connections for JSON-RPC calls within an ethereum node #253

Closed
utzig opened this issue Nov 15, 2016 · 6 comments · Fixed by #350
Closed

Reuse TCP connections for JSON-RPC calls within an ethereum node #253

utzig opened this issue Nov 15, 2016 · 6 comments · Fixed by #350

Comments

@utzig
Copy link
Contributor

utzig commented Nov 15, 2016

When running multiple raiden nodes on a single Linux machine, somewhere between 20 and 30 nodes, will cause exhaustion of available TCP ports. The default for Linux is to use ports between 32768 - 61000 which gives a total of around 28K ports. Every time a new RPC connection is made new TCP port is opened for that connection and stays in TIME_WAIT state. The default recycle time for Linux is big enough that available ports are exhausted.

For doing orchestrated runs I added two extra sysctl configuration options:

net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1

That is good enough for running in orchestration but a better solution should be devised. The best option would probably be to reuse the same connections that were already opened before.

@utzig
Copy link
Contributor Author

utzig commented Nov 15, 2016

Btw, the error after exhausting available ports is this one:

ConnectionError: HTTPConnectionPool(host='127.0.0.1', port=8545): Max retries exceeded with url: / (Caused by NewConnectionError('<requests.packages.urllib3.connection.HTTPConnection object at 0x0000000006f51a28>: Failed to establish a new connection: [Errno 99] Cannot assign requested address',))

@hackaugusto
Copy link
Contributor

hackaugusto commented Dec 21, 2016

So, we have these three dependencies:

The problem is that request (as of 2.12.4) creates a fresh Session for each high-level call. We need to patch tinyrpc to create a Session object instead of relying in the high-level request's api, by reusing a session we will benefit of connection reuse provided by urllib3 (if supported by the ethereum node)

@hackaugusto
Copy link
Contributor

Note: The configuration is only a work around for orchestration, it must not be used with a standard raiden/ethereum node.

Reference: https://vincent.bernat.im/en/blog/2014-tcp-time-wait-state-linux.html

@hackaugusto hackaugusto changed the title Reuse previously opened RPC connection for new RPC calls Reuse TCP connections for JSON-RPC calls within an ethereum node Dec 21, 2016
@LefterisJP
Copy link
Contributor

Yes I also agree regarding the sysctl configuration.

Regarding tinyrpc that's quite strange that it does not support sessions at all. At least I can't see anything in its documentaiton. In that case maybe a less hackish idea would be to resort to a different library for RPC, one that would support connection reuse via sessions?

@konradkonrad
Copy link
Contributor

I believe this should be raised against the tinyrpc upstream. I guess a PR there wouldn't hurt.

@konradkonrad
Copy link
Contributor

see my PR mbr/tinyrpc#31 -- until this get's merged (and backported!), we can probably get away with monkey-patching send_message to mirror the PR's version on our side.

konradkonrad added a commit to konradkonrad/raiden that referenced this issue Jan 25, 2017
This modifies the `tinyrpc` transport of the jsonrpc client to reuse addresses.

See the linked issue for details.
konradkonrad added a commit to konradkonrad/raiden that referenced this issue Jan 25, 2017
konradkonrad added a commit to konradkonrad/raiden that referenced this issue Jan 25, 2017
konradkonrad added a commit to konradkonrad/raiden that referenced this issue Jan 27, 2017
This modifies the `tinyrpc` transport of the jsonrpc client to reuse addresses.

See the linked issue for details.
konradkonrad added a commit to konradkonrad/raiden that referenced this issue Jan 27, 2017
konradkonrad added a commit to konradkonrad/raiden that referenced this issue Jan 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants