Many venues have limits of sending messages per time unit (throttling). If an application sends messages too often, then they can be rejected. To not exceeds the limits, there is the OnixS::FIX::Session::throttle method. This method performs the throttling of a session. It must be called before each send function call. If the count of messages per time unit exceeds the throttling limit, the function will be blocked until the given time interval is passed. The waiting is performed in the busy-wait (spin) mode to exclude the context switching overhead. The OnixS::FIX::Session::throttlingLimit method is used to set throttling limit parameters:
Also, there is the OnixS::FIX::Session::tryThrottle method. It checks the throttling of a session, but it does not block the execution. If the count of messages per time unit exceeds the throttling limit, the function returns the delay (in milliseconds) until the sending becomes possible. Otherwise, it returns 0. The resetWhenDelay
flag indicates if the calculation of messages per throttling interval should be reset and started again when a delay is returned. This method can be helpful when one needs to detect that the message's rate exceeds the limit and react in some specific way:
Additionally, the OnixS::FIX::Throttler class can simplify implementing the throttling (rate limiting) in specific scenarios. This class has similar OnixS::FIX::Throttler::throttle / OnixS::FIX::Throttler::tryThrottle methods that can be used similarly. However, unlike the session's functionality, different throttler objects with different throttling limit parameters can be created and used independently of a session. This can help to implement the throttling on the acceptor's side or perform the different throttling for different message types: