[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [Libevent-users] Beginners' question: multi-threaded HTTP service



On Mon, Nov 19, 2012 at 12:43 PM, Pander <pander@xxxxxxxxxxxxxxxxxxxxx> wrote:
On 2012-11-16 15:19, Nick Mathewson wrote:
>
>
>
> On Fri, Nov 16, 2012 at 5:49 AM, Pander <pander@xxxxxxxxxxxxxxxxxxxxx
> <mailto:pander@xxxxxxxxxxxxxxxxxxxxx>> wrote:
>
>     Hi all,
>
>     I am new to libevent and am wondering what to choose for a
>     multi-threated minimal and fast HTTP service that will run custom C code
>     for the POST requests it will get.
>
>     Both libevent/http and lighttpd are candidates for my service that has
>     to be able to cope with *many* requests.
>
>     Several examples of libevent/http and lighttpd plugin services are out
>     there and I am looking for some well tested and actively maintained
>     minmal and fast HTTP service in which I can easily add my custom code.
>
>     What would you all advise me to use?
>
>
> Check out Mark Ellzey's libevhtp.
>
>    https://github.com/ellzey/libevhtp
>
> It uses Libevent as a backend, but it's (IMO) better engineered and more
> performance than Libevent's built-in evhttp server code.

Thanks. Another candidate I found is this one:
  http://www.roncemer.com/multi-threaded-libevent-server-example

I don't think this is a good example for using libevent (maybe I do not understand what it does correctly).

That server creates one event loop for accepting connections, and then one event loop for each connection. Since the event loops are run from worker threads, your server is actually a standard threaded server, and you don't get the benefits of event based servers. For example, you can serve only limited amount of connections in the same time.

One event loop for doing all IO will probably be fine for your minimal and fast http server. Add worker threads for cpu bound tasks or working with blocking apis, and use queues to pass jobs to the workers and back to the io thread.

If one IO thread is not enough, you can use one event loop for each core. This is how ngix works:
http://www.aosabook.org/en/nginx.html