-
Notifications
You must be signed in to change notification settings - Fork 4
Network
Should we continue to use a threaded socket model or convert to an event-driven model (or even a hybrid model supporting both threads and select())? There is the EventMachine library for Ruby, but it is an external dependency. I would like to use the Ruby Standard Library to keep things clean/simple. The standard library does contain select() should we want to use it however.
The advantages of the current threaded model is that users can take advantage of native threading if using JRuby (http://www.jruby.org/). Furthermore, the JVM that ships with JRuby supports thread pooling or thread reuse which helps cut down on the creation of new threads (creation of new threads can be expensive.) See Why Jruby? for more information. Writing code is also simpler to handle each client. Lastly, since each client has its own thread, calls that block would not block the entire process. The disadvantages to this model are:
- New threads are expensive to create
- Killed off threads can be a waste
- May be more resource intensive with a lot of simultaneous connections
- Synchronization may be required/need to watch out for race conditions/and working with mutexes/semaphores
The advantages of the event-driven model (poll()/epoll()/kqueue()/select()) are:
- High performance
- One single process/no new thread for every client
- No synchronization required
The disadvantages are:
- Code may be more difficult to write to handle client connections
- Calls that block may block the entire server process
- Not as hip/cool as threads ;)