OnixS C++ FIX Engine  3.25.0
API Documentation
Low Latency Best Practices

Session Tuning-up

Selecting Right Storage

Using OnixS::FIX::SessionStorageType::MemoryBased instead of OnixS::FIX::SessionStorageType::FileBased boosts performance, since FIX messages are stored directly in memory. Alternatively, it's possible to use a custom pluggable storage (Using OnixS::FIX::SessionStorageType::Pluggable ) which does nothing on FIX message-related operations, as soon as no resend requests are to be supported. Also you can use the Asynchronous File-Based Session Storage if you need to keep the file based storage functionality and the good-performance.

Manipulating Threads Affinity

By default, threads are used by FIX session to send and receive FIX messages; they can be executed on any of available processors/cores. Specifying CPU affinity for each session thread may give a significant performance boost:

Session::receivingThreadAffinity(...);
Session::sendingThreadAffinity(..);

Using receive spinning timeout

OnixS::FIX::Session::receiveSpinningTimeoutUsec method can be used to decrease the latency of the data receiving. If the value is zero (by default), the receiving thread will wait a new FIX message in the blocking wait mode. If the value greater than zero, the receiving thread will wait a new FIX message in the spin loop mode before switching to the blocking wait mode. The method parameter specifies the spin loop period in microseconds. OnixS::FIX::Session::receiveSpinningTimeoutUsec using makes sense when your session receives FIX messages frequently in this case waiting in the loop is cheaper than the thread context switch to the blocking wait mode. However please note that the spin wait increases the CPU usage and blocks the thread from which OnixS::FIX::Session::send method is called, so the spin wait period should not be too long.

Using send spinning timeout

OnixS::FIX::Session::sendSpinningTimeoutUsec method can be used to decrease the latency of the data sending. If the value is zero (by default) and the outgoing message cannot be sent immediately it is placed to the outgoing queue. If the value greater than zero, the OnixS::FIX::Session::send method waits for the socket sending buffer availability in the spin loop mode before placing the message to the outgoing queue (to be sent later by the sending thread). The method parameter specifies the spin loop period in microseconds. OnixS::FIX::Session::sendSpinningTimeoutUsec using makes sense when your session sends FIX messages frequently in this case waiting in the loop is cheaper than the thread context switch. However please note that the spin wait increases the CPU usage so the spin wait period should not be too long.

Using session warmup

OnixS::FIX::Session::warmUp method can be used to warm up the sending path. It makes sense if your session sends FIX messages infrequently, in this case the sending path and associated data structures will not be in a cache and this can increase the send latency. You can periodically (a recommended period is 500 usec and less) call the OnixS::FIX::Session::warmUp to avoid cache misses and keep the sending path fast. OnixS::FIX::SerializedMessage object is required to warm up the sending path including the FIX message assembling and it will not be actually sent.

Using session send batch

OnixS::FIX::Session::send method can be used to send messages in a batch, it can decrease the send latency because all messages in the batch will be sent in a one TCP packet. This ability is available for OnixS::FIX::Message and OnixS::FIX::SerializedMessage classes. Also you can decrease the send latency a little more by using OnixS::FIX::Session::sendAsIs methods. These methods send serialized message(s) without any fields updating, you can prepare message(s) before sending by setting all necessary fields and using the OnixS::FIX::Session::preFill methods.

Updating Engine Configuration

Disabling Resend Requests Functionality

If no messages are re-sent on counterparty's Resend Request messages, then it is possible to set the Resending Queue size to zero to increase overall performance.

EngineSettings settings;
settings.resendingQueueSize(0);

Disabling FIX Messages Validation

Validation significantly reduces performance due to miscellaneous checks, performed on each FIX message. To disable FIX messages validation the following settings should be used:

settings.validateFieldValues(false);
settings.validateRequiredFields(false);
settings.validateUnknownFields(false);
settings.validateUnknownMessages(false);

Optimizing FIX Dictionaries

When FIX Message is constructed, a space for all the fields, defined for the message, is allocated. The latest FIX specifications define a lot of fields for each message type. Even when most of the fields are not used, FIX Engine reserves space for them, and this has a negative effect on FIX Engine's performance.

Editing Dictionaries Descriptions and excluding messages and fields (especially repeating groups) which are not used by application, have a direct influence onto the FIX messages processing speed. In this way, it decreases general latency of the FIX message related processing.

Manipulating FIX messages

While constructing FIX messages, each time message, that has to be sent,is not efficient, because it involves memory allocation and subsequent destruction. The OnixS::FIX::Message class provides ability to reuse a message of a particular type. It exposes the OnixS::FIX::Message::clear method, which wipes out all the FIX fields, assigned to the given instance. This method does not deallocate all memory occupied, it just brings the message to the initial state as it was just constructed. However, after the previously allocated memory is reused, thus, the second use of the object allows to setup FIX fields faster.

Reusing FIX message instance

A common strategy is to use the same message instance for sending multiple times. As soon as a message of a certain type is constructed, it is updated with common fields for the subsequent re-use. Afterwards, before sending it to the counterparty, it is updated with mutable fields (like price or quantity) exactly for the case, and sent to the counterparty.

As mutable fields are updated, each time message is about to be sent to counterparty.

Using preserialized FIX messages

As an advance for reusing FIX messages, the concept of pre-Serialized FIX Message has been developed. In general, it follows the same approach of updating only mutable fields, before sending a message to the counterpart.

The only difference is that the message is serialized into 'tag=value' presentation in advance, and the serialization is not required, when the message is actually sent.

Using Solarflare Onload Features

Please see the Solarflare Onload Features.