Muduo and libevent2 throughput comparison

Source: Internet
Author: User

Libevent is a very easy-to-use C-language network library. It also uses the reactor model, which can be compared with muduo.

In this paper, we use the ping pong test to compare the throughput of muduo and libevent2. The test results show that the average throughput of muduo is more than 18% higher than that of libevent2, and in some cases it reaches 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 method

The test environment is the same as muduo and boost ASIO throughput.

I wrote the ping pong test for libevent2 myself.Code, Address in http://github.com/chenshuo/recipes/tree/master/pingpong/libevent. Because this test code does not use multithreading, this test only compares the performance of a single thread.

The test content is as follows: the client runs on the same machine as the server, all of which are single-threaded. the throughput of the number of concurrent connections is 1/10/100/1000/10000.

Reasons for testing throughput on the same machine:

    • The current CPU is very fast. Even a single-threaded single TCP connection can fully utilize the bandwidth of Gigabit Ethernet. If two machines are used, all the throughput test results will be 100 MIB/s, and the meaning of comparison is lost. (You may be able to compare which database accounts for less CPU .)
    • Testing on the same machine allows you to compare the efficiency of network libraries with the same CPU resources. That is to say, in a single thread, the server and client each occupy one CPU, and the throughput of the database is high.
Test Results

Single-thread throughput test. The larger the number, the better:

The above results make everyone stunned. muduo is 70% faster than libevent! Tracking of libevent2Source codeIt is found that it reads a maximum of 4096 bytes of data from the socket each time (the evidence is in the evbuffer_read () function of buffer. c). No wonder the throughput is much smaller than muduo. In this test, muduo reads 16384 bytes each time, and the cost-effectiveness of system calls is high.

Buffer. C: # define evbuffer_max_read 4096

To be fair, I tested it again. This time, both databases sent 4096-byte messages.

The test results show that the average muduo throughput is more than 18% higher than libevent2.

Discussion

Libevent2 can read a maximum of 4096 bytes from the network each time, which greatly limits its throughput.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.