[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [Libevent-users] Two event base in multi threaded application vs one event base?
On Fri, Sep 7, 2012 at 12:00 PM, Parvez Shaikh <pshaikh.world@xxxxxxxxx> wrote:
> Hi experts,
>
> While setting socket FD in event loop, should FD be set non-blocking (using
> fcntl)?
Almost certainly.
You can also use evutil_make_socket_nonblocking(), which is a little
more portable.
> Further I am confused about how to use libevent and would really appreciate
> some technical inputs on below.
>
> I am in a process of designing multi-threaded application and would like a
> main thread - a thread that calls event_base_dispatch to do both read and
> write on FD (potentially around 100 FDs).
>
> However I am in a dilemma, should I have two threads running
> event_base_dispatch - one that polls for EV_READ and another for EV_WRITE
> for same FD set or one thread that polls for EV_READ as well as EV_WRITE?
>
> First approach would not let READ operations getting delayed due to much
> time being spent in WRITE operations(due to large data pending) while
> second approach appears more cleaner there is only one thread that is
> polling for events.
Generally it makes more sense to use one thread unless you've got some
reason to go with more. If you're only looking at hundreds fds here,
one thread running event_base_dispatch will do just fine.
yrs,
--
Nick
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users in the body.