epoll_wait on several Threads faster?

Filipe Santos picture Filipe Santos · Sep 18, 2012 · Viewed 7.4k times · Source

I am thinking of programming a tcp server based on epoll. To achieve the best performance i want to implement multi core support too. But during my researches the following question came up: Is it faster to call two epoll_wait()-Calls from two different threads, each observing their own file descriptors on a dual core? Or is this as fast as calling just one single epoll_wait() which observes all file descriptors?

Since the Kernel observes the file descriptors, i think it doens't matter how much threads i use on user space calling epoll_wait()?

Answer

cmeerw picture cmeerw · Sep 18, 2012

You can even call epoll_wait concurrently on multiple threads for the same epoll_fd as long as you use edge-triggered (EPOLLET) mode (and be careful about synchronisation). Using that approach you can get real performance benefits on multi-core machines compared to a single-threaded epoll event loop.

I have actually done performance measurements some time ago, see my blog postings for the results: