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 good performance.
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:
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 for a new FIX message in the blocking wait mode. If the value greater than zero, the receiving thread will wait for 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.
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.
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.
Additionally, you can pass warm-up flags to this method to turn on the warmup feature for a specific NIC. Some of such NICs have its own TCP stack implementation and introduce such flags to warm up the sending path of the TCP stack. In order to check that such a flag works as expected you can use the OnixS::FIX::Session::checkWarmupFlags function. This function creates server/client test sockets and tries to send data with the given flag. The OnixS::FIX::Session::checkWarmupFlags function should be called only once during an application initialization or once per a session local network interface if there are sessions that work via different network interfaces, e.g.:
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.
By default, the logging of an outgoing message to the session storage is performed before sending to the wire. This is more reliable because we guarantee that an outgoing message is stored before going to the counterparty and if the application is shut down after sending, for some reasons, the sent message can be resent afterward. However, this approach adds the logging latency to the FIX Engine sending latency. As a result, it increases the tick-to-trade latency. When the latency is more important, one can switch off the logging before sending, by setting the OnixS::FIX::Session::logBeforeSending option to false. In this case, the logging of outgoing messages to the session storage will be performed after sending to the wire. This way, one can exclude the logging latency from the FIX Engine sending latency and as a result, decrease the tick-to-trade latency.
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.
Validation significantly reduces performance due to miscellaneous checks, performed on each FIX message. To disable FIX messages validation the following settings should be used:
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 an application, have a direct influence onto the FIX messages processing speed. In this way, it decreases the general latency of the FIX message related processing.
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 the 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.
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 the counterparty.
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.
Please see the Solarflare Onload Features.