Search code examples
c++boostserverboost-asiolow-latency

Can Boost ASIO be used to build low-latency applications?


Can Boost ASIO be used to build low-latency applications, such as HFT (High Frequency Trading)?

  • So Boost.ASIO uses platform-specific optimal demultiplexing mechanism: IOCP, epoll, kqueue, poll_set, /dev/poll

  • Also can be used Ethernet-Adapter with TOE (TCP/IP offload engine) and OpenOnload (kernel-bypass BSD sockets).

But can Low-latency application be built by using Boost.ASIO + TOE + OpenOnload?


Solution

  • I evaluated Boost Asio for use in high frequency trading a few years ago. To the best of my knowledge the basics are still the same today. Here are some reasons why I decided not to use it:

    1. Asio relies on bind() style callbacks. There is some overhead here.
    2. It is not obvious how to arrange certain low-level operations to occur at the right moment or in the right way.
    3. There is rather a lot of complex code in an area which is important to optimize. It is harder to optimize complex, general code for specific use cases. Thinking that you will not need to look under the covers would be a mistake.
    4. There is little to no need for portability in HFT applications. In particular, having "automatic" selection of a multiplexing mechanism is contrary to the mission, because each mechanism must be tested and optimized separately--this creates more work rather than reducing it.
    5. If a third-party library is to be used, others such as libev, libevent, and libuv are more battle-hardened and avoid some of these downsides.

    Related: C++ Socket Server - Unable to saturate CPU