Libevent is a very useful C language network library, it also uses the reactor model, just can be compared with Muduo.
This paper uses ping pong test to compare the throughput of Muduo and Libevent2, and the test results show that Muduo throughput is over 18% higher than libevent2, and individual cases reach 70%.
Test object
Libevent 2.0.6-RC (http://monkey.org/~provos/libevent-2.0.6-rc.tar.gz)
Muduo 0.1.1 (http://muduo.googlecode.com/files/muduo-0.1.1-alpha.tar.gz) SHA1 Checksum: a446ea8a22915f439063d2bc52eb2dc4b9caf92d
test environment and test methods
The test environment is the same as the previous "Muduo and boost ASIO throughput comparison".
I wrote my own libevent2 ping pong test code with the address in http://github.com/chenshuo/recipes/tree/master/pingpong/libevent/. Since this test code does not use multiple threads, this test only compares the performance of the single thread.
The test content is: The client and the server are running on the same machine, are single-threaded, test the throughput when the concurrent connection number is 1/10/100/1000/10000.
The reason for testing throughput on the same machine:
Now the CPU is fast, even a single threaded TCP connection can run the bandwidth of Gigabit Ethernet full. If you use two machines, all the throughput test results will be mib/s, losing the meaning of contrast. (You might be able to compare which libraries account for less CPU.) )
Test on the same machine, you can in the same CPU resources, compared to the efficiency of the network library alone. In other words, the server and the client each account for 1 CPUs, comparing which library has high throughput.
Test results
Single-threaded throughput testing, the larger the number the better:
The above results make people surprised, Muduo incredibly faster than libevent 70%! Tracing Libevent2 's source code found that it reads up to 4096 bytes of data from the socket each time (evidence in the buffer.c Evbuffer_read () function), no wonder throughput is much smaller than Muduo. Because in this test, Muduo reads 16384 bytes at a time, the system calls a higher cost-performance ratio.
BUFFER.C: #define Evbuffer_max_read 4096