ï
Thanks Tom,
I know there is a simple summary about threading (
http://www.wangafu.net/~nickm/libevent-book/Ref1_libsetup.html),
but it is too general. The goal I am sending this post is that I want to
know is there any code examples I can reference. I suppose such idea is
very common to implement a real-world system, so I don't want to reinvent the
wheel.
Thanks
Michael
tieyingz@xxxxxxxxxx Hi, âSo, I
want to put all of the socket_bufferevents in one event_base, and only one
thread is runing the event_base. When one of the socket_bufferevents can read or
write, the associated callback will pass the read/write data to a thread to
process. I suppose this model is more reasonable, right?â Correct. Please
check http://www.wangafu.net/~nickm/libevent-book/Ref1_libsetup.html
specifically that section about âLocks and threadingâ. You will have to
implement some functions. Once you have implemented these functions you are good
to go. 10x, Tomer. From:
owner-libevent-users@xxxxxxxxxxxxx [mailto:owner-libevent-users@xxxxxxxxxxxxx]
On Behalf Of Michael (Tieying) Zhang Thanks
Tom. "event bases + threads (each thread running an event base)", that is what I
have done. Each connection is a thread with a event_base + a
socket_bufferevent. But when a connection has no communication during
sometime, the associated thread is idle. That's the main problem I concern.
For
example, there are 10 connections with the server, and 10 threads on the server
are responsible for the connections, e.g., thread-1 is associated with
connection-1, with event_base-1 and socket_bufferevent-1. If the client
with the connection-1 stop sending messages to the server, the thread-1 is
stuck. Becuase thread-1 is running dispatch(event_base-1), which is a blocking
API. So, I
want to put all of the socket_bufferevents in one event_base, and only one
thread is runing the event_base. When one of the socket_bufferevents can read or
write, the associated callback will pass the read/write data to a thread to
process. I suppose this model is more reasonable,
right? The
question is how can I implement that with std::thread. Because our project use
std::thread. I see libevent can use pthread (even though there is no
example in the documentation) but I am don't know how to use it with
std::thread. The explaination is so simple I do not know how to implement it
with std::thread. Michael Hi
Michael, Using a
thread for each connection is exactly what libevent (async IO) is trying to
simplify and prevent. The
right way would be to use a single event base with a single thread for all these
connections. If you
want to scale it to multiple cores: you can divide the connections between a
couple of event bases + threads (each thread running an event base).
10x, Tomer. -----Original
Message----- From:
owner-libevent-users@xxxxxxxxxxxxx
[mailto:owner-libevent-users@xxxxxxxxxxxxx]
On Behalf Of Michael Sent:
Tuesday, March 15, 2016 8:58 AM Subject:
[Libevent-users] std::threads Hi
All, This is
Michael from CMU. I am currently using libevent in our database system (https://github.com/cmu-db/peloton/wiki)
to let the cluster nodes to communicate with each
other. I want
to ask how can I use multiple std::threads on the same event_base. For
example, a server has a event_base. When a new connection coming, the
server creates a std::thread with a socket_event, and puts the socket_event into
the event_base. If there are ten connections, there are ten std::threads sharing
the same event_base. (Each
threads has it own socket_event to recv and send
data). Can I
implement that? Is there an example? I
appreciate your help! Best, Michael *********************************************************************** To
unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx
with unsubscribe
libevent-users in the
body. |