You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/RealTimeProgramming.md
+5-3
Original file line number
Diff line number
Diff line change
@@ -16,8 +16,8 @@ One can find a few developer checklists for real-time programming such as [this]
16
16
17
17
- Take care when designing your own code and implementing your own **algorithms**:
18
18
19
-
- Select algorithms by their **worst-case latency** and not their average latency
20
-
-**Split your code** into parts that have to be **real-time** and a **non real-time** part
19
+
- Select algorithms by their **worst-case run-time** and not their average run-time (see also [here](https://www.cs.odu.edu/~zeil/cs361/latest/Public/averagecase/index.html)). Keep in mind though that these latency are derived from asymptotic analysis for a large number of elements and only up to a constant (which can be quite large): Two O(n) algorithms might be very different in terms of computational speed (number of instructions and CPU cycles taken), just their scaling will be similar and similarly a O(n²) algorithm might be faster for smaller container sizes. Therefore in particular for smaller or fixed size containers it is necessary to benchmark the chosen algorithm. For small containers the cache locality and memory allocation of an algorithm will be far more important than its asymptotic scaling behavior.
20
+
-**Split your code** into parts that have to be **real-time** and a **non real-time** part and make them communicate with lockless programming techniques
21
21
22
22
-**Set a priority** (nice values) to your real-time code (see [here](https://medium.com/@chetaniam/a-brief-guide-to-priority-and-nice-values-in-the-linux-ecosystem-fb39e49815e0)). `80` is a good starting point. It is not advised to use too high priorities as this might result in problems with kernel threads:
23
23
@@ -116,6 +116,8 @@ One can find a few developer checklists for real-time programming such as [this]
116
116
117
117
- Take care when relying on external libraries to time events and stop times, e.g. [`std::chrono`](https://www.modernescpp.com/index.php/the-three-clocks/).
118
118
119
-
- Benchmark performance of your code and use tracing library to track you real-time performance. You can always test with simulated load.
119
+
- **Benchmark** performance of your code and use tracing library to track you real-time performance. You can always test with simulated load.
120
+
121
+
- For network applications that require to communicate over a high-speed NIC look into **kernel-bypass** instead of relying on POSIX sockets (see e.g. [here](https://blog.cloudflare.com/kernel-bypass) and [here](https://medium.com/@penberg/on-kernel-bypass-networking-and-programmable-packet-processing-799609b06898))
120
122
121
123
A good resource for real-time programming is the book ["Building Low Latency Applications with C++"](https://www.packtpub.com/product/building-low-latency-applications-with-c/9781837639359) as well as [this CppCon 2021 talk](https://www.youtube.com/watch?v=Tof5pRedskI). You might also want to have a look at the following two-part guide for audio-developers ([1](https://www.youtube.com/watch?v=Q0vrQFyAdWI) and [2](https://www.youtube.com/watch?v=PoZAo2Vikbo)).
0 commit comments