Skip to main content

Network Performance

TCP

Compare TCP socket performance via echo server.

Test program

https://github.com/alibaba/PhotonLibOS/blob/main/examples/perf/net-perf.cpp

Build

cmake -B build -D PHOTON_BUILD_TESTING=1 -D PHOTON_ENABLE_URING=1 -D CMAKE_BUILD_TYPE=Release
cmake --build build -j 8 -t net-perf

Run

Server

./build/output/net-perf -port 9527 -buf_size 512

Streaming client

./build/output/net-perf -client -client_mode streaming -ip <server_ip> -port 9527 -buf_size 512

Ping-pong client

./build/output/net-perf -client -client_mode ping-pong -ip <server_ip> -port 9527 -buf_size 512 -client_connection_num 100
note

Of course you can use your own client, as long as it follows the TCP echo protocol.

Measure

You can either monitor the server's network bandwidth via iftop, or print its QPS periodically from the code.

Results

1. Streaming

LanguageConcurrency ModelBuffer SizeConn NumQPSBandwidthCPU util
PhotonC++Stackful Coroutine512 Bytes41604K6.12Gb99%
cocoyaxiC++Stackful Coroutine512 Bytes41545K5.89Gb99%
tokioRustStackless Coroutine512 Bytes41384K5.28Gb98%
acl/lib_fiberC++Stackful Coroutine512 Bytes41240K4.73Gb94%
GoGolangStackful Coroutine512 Bytes41083K4.13Gb100%
libgoC++Stackful Coroutine512 Bytes4770K2.94Gb99%
boost::asioC++Async Callback512 Bytes4634K2.42Gb97%
monoioRustStackless Coroutine512 Bytes4610K2.32Gb100%
Python3 asyncioPythonStackless Coroutine512 Bytes4517K1.97Gb99%
libcoC++Stackful Coroutine512 Bytes4432K1.65Gb96%
zabC++20Stackless Coroutine512 Bytes4412K1.57Gb99%
asyncioC++20Stackless Coroutine512 Bytes4186K0.71Gb98%

2. Ping-pong

LanguageConcurrency ModelBuffer SizeConn NumQPSBandwidthCPU util
PhotonC++Stackful Coroutine512 Bytes1000412K1.57Gb100%
monoioRustStackless Coroutine512 Bytes1000400K1.52Gb100%
boost::asioC++Async Callback512 Bytes1000393K1.49Gb100%
evppC++Async Callback512 Bytes1000378K1.44Gb100%
tokioRustStackless Coroutine512 Bytes1000365K1.39Gb100%
nettyJavaAsync Callback512 Bytes1000340K1.30Gb99%
GoGolangStackful Coroutine512 Bytes1000331K1.26Gb100%
acl/lib_fiberC++Stackful Coroutine512 Bytes1000327K1.25Gb100%
swoolePHPStackful Coroutine512 Bytes1000325K1.24Gb99%
zabC++20Stackless Coroutine512 Bytes1000317K1.21Gb100%
cocoyaxiC++Stackful Coroutine512 Bytes1000279K1.06Gb98%
libcoC++Stackful Coroutine512 Bytes1000260K0.99Gb96%
libgoC++Stackful Coroutine512 Bytes1000258K0.98Gb156%
asyncioC++20Stackless Coroutine512 Bytes1000241K0.92Gb99%
TypeScriptnodejsAsync Callback512 Bytes1000192K0.75Gb100%
ErlangErlang-512 Bytes1000165K0.63Gb115%
Python3 asyncioPythonStackless Coroutine512 Bytes1000136K0.52Gb99%
note
  • The Streaming client is to measure echo server performance when handling high throughput. A similar scenario in the real world is the multiplexing technology used by RPC and HTTP 2.0. We will set up 4 client processes, and each of them will create only one connection. Send coroutine and recv coroutine are running infinite loops separately.
  • The Ping-pong client is to measure echo server performance when handling large amounts of connections. We will set up 10 client processes, and each of them will create 100 connections (totally 1000). For a single connection, it has to send first, then receive.
  • Server and client are all cloud VMs, 64Core 128GB, Intel Platinum CPU 2.70GHz. Kernel version is 6.x. The network bandwidth is 32Gb.
  • This test was only meant to compare per-core QPS, so we limited the thread number to 1, for instance, set GOMAXPROCS=1 for Golang.
  • Some libs didn't provide an easy way to configure the number of bytes we would receive in a single call at server side, which was required by the Streaming test. So we only had their Ping-pong tests run.

Conclusion

Photon socket has the best per-core QPS, no matter in the Streaming or Ping-pong traffic mode.

HTTP

Compare Photon and Nginx when serving static files, using Apache Bench(ab) as the client.

Test program

https://github.com/alibaba/PhotonLibOS/blob/main/net/http/test/server_perf.cpp

Results

File SizeQPSCPU util
Photon4KB114K100%
Nginx4KB97K100%
note

Nginx only enables 1 worker (process).

Conclusion

Photon is faster than Nginx under this circumstance.