Chapter 4. Application Tuning and Deployment

This chapter contains tips related to enhancing and developing MRG Realtime applications.

Note

In general, try to use POSIX (Portable Operating System Interface) defined APIs. MRG Realtime is compliant with POSIX standards, and latency reduction in the MRG Realtime kernel is also based on POSIX.
Further Reading
For further reading on developing your own MRG Realtime applications, start by reading the RTWiki Article.

4.1. Signal processing in Realtime applications

Traditional UNIX and POSIX signals have their uses, especially for error handling, but they are not suitable for use in realtime applications as an event delivery mechanism. The reason for this is that the current Linux kernel signal handling code is quite complex, due mainly to legacy behavior and the multitude of APIs that need to be supported. This complexity means that the code paths that are taken when delivering a signal are not always optimal, and quite long latencies can be experienced by applications.
The original motivation behind UNIX™ signals was to multiplex one thread of control (the process) between different "threads" of execution. Signals behave somewhat like operating system interrupts - when a signal is delivered to an application, the application's context is saved and it starts executing a previously registered signal handler. Once the signal handler has completed, the application returns to executing where it was when the signal was delivered. This can get complicated in practice.
Signals are too non-deterministic to trust them in a realtime application. A better option is to use POSIX Threads (pthreads) to distribute your workload and communicate between various components. You can coordinate groups of threads using the pthreads mechanisms of mutexes, condition variables and barriers and trust that the code paths through these relatively new constructs are much cleaner than the legacy handling code for signals.
Further Reading
For more information, or for further reading, the following links are related to the information given in this section.