Customizing Logging | Table of Content | FIX Engine Thread Safety |
FIX Engine Threading Models |
The FIX Engine supports two threading models: DedicatedThreads and ThreadPool. The model is configured via the ThreadingModel setting.
If this mode is used and there is an active connection the FIX Engine creates receiving and sending threads on each session instance. The receiving thread receives and processes incoming FIX messages. The sending thread processes user's FIX messages which were stored in the internal sending queue. The MessageGrouping parameter affects the sending process. If the parameter is zero (by default) or one, the FIX Engine tries to send a FIX message in the primary application thread and only after a failure, stores it in the sending queue for the next process in the sending thread. If the parameter is greater than one the FIX Engine stores a FIX message in the sending queue immediately and then processes it in the sending thread. The following table explains which callbacks could be called by the each one thread.
Event | Application thread | Sending thread | Receiving thread |
---|---|---|---|
Yes | Yes | Yes | |
No | No | Yes | |
No | No | Yes | |
No | No | Yes | |
No | No | Yes | |
No | No | Yes | |
Yes | Yes | Yes | |
Yes | Yes | Yes | |
Yes | Yes | Yes | |
No | No | Yes | |
Yes | Yes | Yes | |
Yes | Yes | Yes |
If this mode is used the FIX Engine creates the thread pool and shares it between all sessions. The maximum threads number in the thread pool depends on the ThreadPoolSize parameter. One thread, in the thread pool, performs read/write operations and can process some number of different FIX connections. FIX connections are distributed equally between all threads.
Note |
---|
If the ListenPort parameter is greater than zero the FIX Engine creates an addition thread for the incoming connections process. |
Note |
---|
If the AsyncFileBasedStorage value is passed to the session constructor the FIX Engine creates an addition one thread on each session instance. This thread is used to process session storage file operations in the asynchronous mode. |
Note |
---|
When a FIX session has some network issues, the FIX Engine will restore the FIX connection. For this purpose, a separate thread is created to avoid blocking FIX Engine's IO threads. |