On Wed, Apr 08, 2009 at 01:04:16PM -0700, Phoenix Sol <[email protected]> 
wrote:
> With libevent and it's 'evhttp' thing, a pool of worker threads or processes

Last I looked, libevent didn't support threads (not even cooperative ones)
on the same event loop, and I really doubt it supports it right now, so I
really doubt you can do that (I mean, youc an do that, and accept crashes
and stuff...)

> can all listen on the same port, by calling evhttp_accept_socket(evhttp,
> fd).

evhttp_accept_socket just starts a read watcher. you can do that under
libev just fine.

> I like this so that I don't have to explicitly manage which worker answers
> which connection, passing a fd every time.

I don't see why you would have to do that otherwise?

> Can I do this with the current libev?

Yes, just add a read watcher on the accept fd and call accept in the
callback.

Note that, just like with libevent, you cannot use a pool of preemptive
threads on the same event loop in any sensible way.

> What would be the best way to build a preforking server with libev?

That depends on your operating system etc - some really want you to call
accept blockingly, some do not. Some work by using a separate semaphore,
some do not etc. etc. It also depends on your program.

Unlike libevent, libev supports all those modes quite well, including
using worker threads e.g. for the accept (which is much more difficult as
libevent doesn't support thread communicaitons between loops in any way),
which libevent doesn't support itself.

> Assume that upon every connection, a long-running connection handler is
> launched in a lightweight, cooperative coroutine. I want a preforking server
> so that these coroutines are efficiently spread across all available
> processor cores.

That really depends on your problem, your OS etc. You might look at e.g.
apache sources, because they have implemented various strategies to work
well on various operating systems. If your app is similar, it might want to
use the same algorithms.

-- 
                The choice of a       Deliantra, the free code+content MORPG
      -----==-     _GNU_              http://www.deliantra.net
      ----==-- _       generation
      ---==---(_)__  __ ____  __      Marc Lehmann
      --==---/ / _ \/ // /\ \/ /      [email protected]
      -=====/_/_//_/\_,_/ /_/\_\

_______________________________________________
libev mailing list
[email protected]
http://lists.schmorp.de/cgi-bin/mailman/listinfo/libev

Reply via email to