tarcieri/nio4r — Issue #1: locking in reactor severely limits usage for network clients
Author: chrisochs
Created: 2012-03-03 22:42:11+00:00
State: open

If you have clients that are making a lot of network calls, the locking around registering io objects will cap you to a very low concurrency. We do exactly that on a large jruby + rails application, and I've been looking for an alternative to eventmachine when I found this. Unfortunately, those locks would kill us.

Two solutions I can think of.

- Add an option to disable the locking. This would work for a lot of us. Especially for jruby apps, you often just run a reactor in it's own thread anyways. In some cases you might run a small pool of reactors to take advantage of multiple cores. We use zeromq to communicate between our app threads and the reactor thread.

- For jruby, use ConcurrentHashMap instead of a mutex. Not free, but much less expensive then synchronize and you will get much higher concurrencies.

The problem with ConcurrentHashMap approach is that anything that's using a reactor pattern for clients, is probably running at a high enough concurrency where even ConcurrentHashMap will have issues.

Chris