I think you are trying to overdo it. Linux's epoll architecture was designed for situations where you have thousands of concurrent connections. In such cases, the overhead, as determined by the poll and select system calls, will be the main bottleneck on the server. The decision to use poll or select vs. epoll based on the number of connections, not the amount of data.
For what you are doing, it seems that the people in your editing system are going crazy after you press dozens of simultaneous editors. Using epoll will probably make you crazy; they play some tricks with the API to squeeze extra performance, and you have to carefully process the information you receive from calls.
Such an application looks like it will be network bound, not CPU bound. I would try to write it first as a single-threaded server with poll . When you receive new text, be careful when sending it, and then send it when the socket accepts write calls. Use non-blocking I / O; the only call you want to block is poll .
If you do a significant amount of data processing after receiving it, but before sending it back to clients, you can use multi-threaded. First write a single-threaded version, then if you are attached to the processor (check with top ), and most of the processor’s time is spent on the functions where you process the data (check with gprof ), add multithreading to the data processing.
If you want, you can use channels or sockets of the Unix domain inside the program to communicate between different threads --- this way, everything in the main thread can be event driven and processed through poll . Alternatively, with this model, you could even use multiple processes with fork instead of multiple threads.
source share