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

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



Hi Azat,
Thanks for your reply.
Using one event_base per thread is an idea I haven't thought of - Interesting. One drawback that comes to mind with this design is that a network connection
will stay with the same thread forever.
If connections are long lived and the activity on connections
varies over there lifetime the server will not be able to distribute the
load over all threads in the thread pool. I will need to think a bit more about this.

About bufferevents and built-in openssl support.
Yes I looked at this and it would certainly simply my code, but with
my original design idea all the SSL encryption would have been done in the
thread running the event_base so that's why I ruled it out.
With your idea of an event_base per thread things come in a different light.

Thanks again for you input.
You have given me some new ideas to think about.

/Leif

On 2017-12-08 10:40, Azat Khuzhin wrote:
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.

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