I agree with Steve, there are definitely situations where using libevent in multithreaded apps makes sense. My only complaint is exactly what Steve mentioned in his earlier post regarding the use of a pipe/socketpair for inter-libevent thread communication. I have a main thread listening for inbound connections which then hands the request off to a worker thread. I generally create 2 * cores number of threads and load balance the inbound requests across them. Each worker thread runs its own event loop and handles communications with many clients at once. The worker performs all the communication necessary to fulfill a given client request.
FWIW, I have a wrapper around the pipe-style message passing that works well for me available at http://www.weirdness.net/code/libevent/. I've been meaning to document it but I haven't got around to it yet. Andrew On 4/13/07, Steven Grimm <[EMAIL PROTECTED]> wrote:
Martin Hedenfalk wrote: > I'm sorry if the above seems harsh, but I really don't see the point > in implementing a multi-threaded libevent server. I can answer that, since I converted memcached from single- to multi-threaded: even if each request completes in a very short time, pile enough of them up in a short period of time and you'll run out of capacity on one CPU. Adding threads lets you make full use of a multiprocessor machine without having to split your application up into separate processes. Splitting into multiple processes not only duplicates whatever constant overhead each instance of your app has, but if the application needs to have globally shared state, you're looking at something like a shared memory region or mmapped file with the same locking issues you have in a multithreaded app. As for how to do it, my approach is documented on the libevent home page (or rather, there's a link there to my explanation) so I won't repeat myself. But I will say it's working well for us -- our memcached instances are handling close to twice the request volume they used to be able to handle when they were single-threaded, and they still have plenty of capacity to spare. -Steve _______________________________________________ Libevent-users mailing list [EMAIL PROTECTED] http://monkey.org/mailman/listinfo/libevent-users
_______________________________________________ Libevent-users mailing list [EMAIL PROTECTED] http://monkey.org/mailman/listinfo/libevent-users
