Muduo (http://code.google.com/p/muduo) is a reactor-Based C ++ network library. I didn't write it with high concurrency and high throughput as the main goal, but unexpectedly, ping pong test shows that muduo throughput ratio is boost. ASIO is 15% or higher.
Test Object
- ASIO 1.4.3 in boost 1.40
- ASIO 1.4.5 (http://think-async.com/Asio/Download)
- Muduo 0.1.1 (http://muduo.googlecode.com/files/muduo-0.1.1-alpha.tar.gz) sha1 checksum: a446ea8a22915f439063d2bc52eb2dc4b9caf92d
Test Environment
Hardware: Dell 490 workstation, dual intel quad core Xeon e5320 CPU, 16 GB memory
Operating System: Ubuntu Linux Server 10.04.1 lts x86_64
Compiler: G ++ 4.4.3
Test Method
According to the ASIO Performance Test http://think-async.com/Asio/LinuxPerformanceImprovements, ping pong protocol is used to test the throughput.
In short, the ping pong protocol implements the echo protocol for both the client and server. When a TCP connection is established, the client sends some data to the server, the server returns the data, and then the client returns the data back to the server. The data will be transmitted back and forth between the client and the server like table tennis until one party is disconnected. This is a common way to test throughput.
ASIO TestingCodeFromHttp://asio.cvs.sourceforge.net/viewvc/asio/asio/src/tests/performance/, Not changed.
The muduo test code is in the 0.1.1 package, path is examples/pingpong/, the code is shown in the http://gist.github.com/564985.
Muduo and ASIO optimized compilation parameters are-O2-Finline-Limit = 1000
$ Build_type = release./build. Sh # compile the muduo optimized version.
I mainly did two tests:
- For a single-thread test, the throughput of the number of concurrent connections is 1/10/100/1000/10000.
- Multi-threaded testing. The number of concurrent connections is 100 or 1000, and the number of threads on the server and client is set to 1/2/3/4 at the same time. (Because I have only one 8-core server in my house and the server and client are running on the same machine, it makes no sense to have more than 4 threads .)
In all tests, the pong Message Size is 16 kb. The shell script for testing can be downloaded from the http://gist.github.com/564985.
Test Results
The larger the number, the better:
The result of multi-threaded testing, the larger the number, the better:
The test results show that the average muduo throughput is more than 15% higher than that of ASIO.
Discussion
Muduo unexpectedly boasts superior performance than ASIO, and I think it mainly relies on its simple design and concise code.
ASIO is not doing well in multi-threaded testing. I guess the main reason is that the test code only uses one io_service. If we use "io_service per CPU", the performance should be improved. My understanding of ASIO is limited to understanding its code. I hope that ASIO experts can write the ping pong test of "io_service per CPU" to make a fair comparison with muduo.
The Ping Pong test is easy to implement. You are welcome to add other Network Libraries (such as Ace, Poco, and libevent) to the comparison. We look forward to the success of these libraries.