High-performance server using libEvent

c++, libevent

Solution

`libevent` is the way to go if you want to stay cross-platform.

If you want to be highly efficient, I would recommend platform specific API's like IO completion ports (which you have working on Windows) and epoll in Linux:

Note that libevent uses epoll internally for Linux anyway.

As for your question of mulithreaded design, I hope you are not using one thread to handle each incoming client connection... you would be defeating the purpose of using an event-driven model if you did! You should design your code so that a handful of client connections are being handled by a single thread, and increase the number of threads as the number of concurrent connections increases.

I would also not do any heavy-duty computational work on the data that clients sends in the threadpool that is doing the IO receiving the data. I would separate the task of doing network intensive IO and doing any CPU intensive computation into two separate threadpools

Problem

I'm designing a high-performance server (not an HTTP server) and am considering my design options. The server should support a large number of incoming connections (in thousands), and to compile on both windows and linux. On the windows side, I've implemented a IO Completion Port server, which so far seem to handle the stress. Since the linux demand popped, I now try to find a cross-platform library that gives me a way to use the accept / read events with a thread pool. So far, libEvent seems like the right choice (something like "Example code: an echo server" in this link). But quoting from another page in the libEvent docs: If an event_base is set up to use locking, it is safe to access it between multiple threads. Its loop can only be run in a single thread, however. If you want to have multiple threads polling for IO, you need to have an event_base for each thread. My basic design is to have a thread pool reacting to accept and read events. This quote, if I understand it correctly, says I can't do that. Does anyone has any experience with high-perf. servers based on libEvent? Should I maybe use a different library? An example code for such a server would be perfect

Original source