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

Fwd: [Libevent-users] Using libevent in multi-threaded server



On Thu, Dec 7, 2017 at 4:38 PM, Leif Thuresson <leif.thuresson@xxxxxxxx> wrote:
> Hi,
> Seeking advice from experienced libevent users.
>
> I'm working on a server doing SSL socket I/O and I want to hand off the
> CPU hungry SSL read/write to threads in a threadpool to gain performance.
> I want to have read events pending all the time but write events only
> when there is something in queue for output.
> To be able to switch read and write events on/off independently  I think the
> standard solution
> is to create two separate event object for each file descriptor.
> In the server one thread is running the event-loop and the event callback
> hand off the
> execution of a secondary application I/O callbacks to a thread in the
> threadpool that
> performs the actual I/O.
> A problem with using two separate event objects is that I risk getting both
> a read and
> a write application callback running at the same time in different threads
> which will crash the SSL I/O.

Hi,

So you have a thread pool, and hence you can just add event_base per
thread in this pool, and so when you server accept the fd, you just
pass it to the event_base of that thread and that's it. Because in
this case EV_READ/EV_WRITE cannot be run in parallel. And I think that
this is the most optimal choice.

Also didn't you looked at bufferevent_openssl_socket_new(), maybe this
could simplify your code.

  Azat.
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users    in the body.