I am reading a single data item from a UDP port. It’s essential that this read be the lowest latency possible. At present I’m reading via the boost::asio library’s async_receive_from method. Does anyone know the kind of latency I will experience between the packet arriving at the network card, and the callback method being invoked in my user code?
Boost is a very good library, but quite generic, is there a lower latency alternative?
All opinions on writing low-latency UDP network programs are very welcome.
EDIT: Another question, is there a relatively feasible way to estimate the latency that I’m experiencing between NIC and user mode?
Your latency will vary, but it will be far from the best you can get. Here are few things that will stand in your way to the better latency:
Boost.ASIO
mutexlocking/unlocking in order to support a broken mix of async and sync approaches.All in all,
asiois a good library for high-level application developers, but it comes with a big price tag and a lot of CPU cycle eating gremlins. Another alternative islibevent, it is a lot better, but still aims to support many notification mechanisms and be platform-independent. Nothing can beat native mechanisms, i.e.epoll.Other things
I cannot tell you exact numbers, but assuming that you won’t be getting a lot of traffic, using Boost and a regular Linux kernel, with a regular hardware, your latency will range somewhere between ~50 microseconds to ~100 milliseconds. It will improve a bit as you get more data, and after some point start dropping, and will always be ranging. I’d say that if you are OK with those numbers, don’t bother optimizing.