Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

epoll_wait on several Threads faster?

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()?

like image 963
Filipe Santos Avatar asked Sep 18 '12 16:09

Filipe Santos


1 Answers

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:

  • http://cmeerw.org/blog/748.html#748
  • http://cmeerw.org/blog/746.html#746
like image 148
cmeerw Avatar answered Oct 22 '22 01:10

cmeerw