Skip to content

Latest commit

 

History

History
33 lines (23 loc) · 1.77 KB

2014-01-08.md

File metadata and controls

33 lines (23 loc) · 1.77 KB

hemant

Just noticed Hammerspace

Really interesting solution for storing translations out of Ruby HEAP and yet make them available via simple Ruby hash like interface without involving network or any kind of Socket IO.

It uses sparkey for heavy lifting though.

Epoll Oneshot

When using non-blocking IO to build high performance servers one problem people face is, how to leverage multiple cores available on machine to even speed things up further.

Usually people come with following solutions

  1. Run polling loop in one thread and have a thread pool for off loading long running processes. No IO is ever performed into polling thread from thread pool threads though and hence has limited scalability.

  2. Another approach is have two separate selectors for Read and writes and hence two different threads. But this requires careful locking because often you want to observe read or write events on same file descriptor.

  3. EPOLLONESHOT is another approach (which I learnt today morning) which solves this problem elegantly. What it does is - when you add a file descriptor to monitoring list via epoll_ctl you set this flag. And when this file descriptor is ready with an event (either read, write or connect) then the file descriptor is automatically disabled for further notifications until it is added back via epoll_ctl again.

This allows multiple threads to process events returned by epoll_wait because only one thread will ever receive a file descriptor. More details is explained in this stack overflow thread - http://stackoverflow.com/questions/5541054/how-to-correctly-read-data-when-using-epoll-wait