title: c/c++ epoll multithreading
body: <p>I know there are many questions about this, yet I still couldn't find the answer that helps me.</p>
  
  <p>Let's take a small tcp server with epoll and we want it to utilize as many cpu cores as possible. I've thought about 2 ways it could be done, but none of them worked really well.</p>
  
  <p>1 - Each thread has its own epoll fd and in a "while(1)" loop uses "epoll_wait()" and processes the requests.</p>
  
  <p>2 - Only one epoll fd and creating a new thread for each request when processing it.</p>
  
  <p>In one single thread I could do around 25k req/s, so I was assuming the first method would help a lot, but in reality when I used 2 epoll fd the app could only process ~10k req/s. Obviously I didn't even consider a 2nd method a real one, it was meant to fail, so yeah.</p>
  
  <p>So basically my question is: how should I implement multithreading so it can <em>really</em> utilize more cpu cores?</p>
  
  <p>The socket is non-blocking, TCP_NODELAY, TCP_FASTOPEN set, and I'm using EPOLLET mode as well.</p>