There are a few fundamental principles you should follow. Your server will

exhibit low latency to the extent you adhere to these principles:



1) Avoid data copying. Prefer zero-copy algorithms. For example, when you

send/receive data through a socket use a ring-buffer with wrapping iterators.

2) Avoid dynamic memory allocation on fast code paths, such as receiving

market

data and sending orders. Preallocate as much as possible. Use mapped memory.

3) Avoid lock contention. Use wait-free and lock-free algorithms if possible,

share as little data as possible between threads.

4) Avoid context switching. Don't have more threads ready to run than

hardware

CPUs. Use fifo realtime process priority, so that your threads do not get

context switched off when it still has data to process.

Click to expand...