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

[Libevent-users] libevent performance problem for detect the socket is readable

ïi all,

ÂI use libevent in my program, but I meet some performance problem.

I create one class named SocketEventBase. SocketEventBase is one thread and use event_base_dispatch() to check socket.

There is one list<socket*> in the SocketEventBase. Use SocketEventBase to listen all the socket in the list.

When the socket is ready to read, libevent framework will remove socket from the list and I will use another thread(named Handler) to deal the request by using
the callback function.

After Handler complete the request, i will add the socket to event base again.

So during the run-time, there are lots of event will be remove from and add to
the event base.

I try to use more event base to get better performance. I use handler-thread-pool-num to control the num of SocketEventBase. Assume handler-thread-pool-num is four, all requests will be dispatch to the four event base.

When i don't use libevent, one thread will service one socket.

After i use libevent, i wish less threads can service same num of socket and will get better performance.

But i test my program as below.

I use 300 client threads to test my program.
(It is a sysbench oltp test, and libevent is used inside a proxy, which is located between the sysbench and backend mysql)

When i don't use libevent, i get 10000~12000 tps.

After i use libevent, different handler-thread-pool-num get different result.

handler-thread-pool-num     Âtps
1 Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1101.17
2 Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 2065.75
4 Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 3354.30
8 Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 3995.18
16 Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â4308.92

Then i monitor my program like below:
| Monitor_point    Â| Cost_time | %   Â|
| session_other    Â| 37462   | 78.36 Â|
| session_svc     Â| 47805   | 100.00 |
| session_switch    | 484    | 1.01  |
| session_work     | 9670   Â| 20.23 Â|

session_svc : all the time of the requests be done
session_switch : the time is when socket is ready to read, move request from SocketEventBase to Handler.
session_work : the time is Handler deal the requests
session_other : the time is from adding socket to SocketEventBase's list to find the socket is ready to read. (The time is also include waiting for sysbench client to send the request, but it still too much, cause the session_work is only 20%, which also
includes the time for backend mysql handle the sql request and send back result )

I don't know why session_other needs so much time. Is libevent need so much time to find the socket is ready?

some other test result as below:

client thread = 30
tps 2696.23
session_other 14.56%

client thread = 60
tps 4323.21
session_other 27.18%

client thread = 90
tps 5019.76
session_other 41.99%

client thread = 120
tps 4893.41
session_other 54.31%