Linux low-latency
Linux low-latency related knowledge
An attempt to gather resources on low-latency linux. Musicians use low-latency linux for recording and live performance. In stock market ticker data streaming one will need low-latency on per packet processing.
A resource on preparing UbuntuStudio specially for musicians.
First things first, if you need lower latency, get away from ubuntu and use Debian or Redhat (small footprint) OS image + kernel.
Zero-copy Zero copy lets you avoid redundant data copies between intermediate buffers and reduces the number of context switches between user-space and kernel-space. Ideal Zero copy (zero cpu copy) is possible when your hardware (disk drive, network card, graphic card, sound card) supports DMA (Direct Memory Acess).
File system zero-copy: reduce user-space, kernel-space interaction for file copying Check this code in github Filesystem zero-copy in C/Java.
Q: How to install the low-latency kernel in Ubuntu 16.04? following might work
sudo apt-get install linux-image-lowlatency
Playing with sysctl flags (offered by kernel to configure)</b>
Two servers located in two different data center. Both server deals with a lot of concurrent large file transfersa. But network performance is very poor for large files and performance degradation take place with a large files. How do I tune TCP under Linux to solve this problem? Documentation
Here are some of the sysctl flags to adjust kernel behavior.
These are some simple guidelines on selecting the right kernel that fits your need (in a particularorder)–by ubuntu fan askubuntu
- If you do not require low latency for your system then please use the -generic kernel.
- If you need a low latency system (e.g. for recording audio) then please use the -preempt kernel as a first choice. This reduces latency but doesnt sacrifice power saving features. It is available only for 64 bit systems (amd64).
- If the -preempt kernel does not provide enough low latency for your needs (or you have an 32 bit system) then you should try the -lowlatency kernel.
- If the -lowlatency kernel isn't enough then you should try the -rt kernel
- If the -rt kernel isn't enough stable for you then you should try the -realtime kernel
The most relevant kernel options if you want to recompile your kernel yourself to have a low-latency desktop:
PREEMPT=y
and:
CONFIG_1000_HZ=y
To add some powersaving check this one:
CONFIG_NO_HZ=y
Additionally, preemt, lowlatency or the rt kernel wont make your system faster (for general tasks?). They are slightly slower than generic kernel.
Good references
- https://blog.cloudflare.com/how-to-achieve-low-latency/
- redhat tuning: Redhat low-latency config guide
- Linux tcp tuning: https://www.cyberciti.biz/faq/linux-tcp-tuning/