OnixS Eurex ETI Handler C++ library 9.29.0
Users' manual and API documentation
Loading...
Searching...
No Matches
Throttling

Introduction

The Handler supports throttling, a mechanism to control the number of requests sent to Eurex. The implementation of throttling is based on the Sliding Window algorithm.

High-level Overview

The throttling works as follows:

  • The Handler keeps track of the number of requests sent to Eurex within a certain time interval;
  • When the number of requests exceeds the Handler's limit, which is the limit set by Eurex less the throttle message margin, the Handler blocks Handler::send call in the caller's thread;
  • The Handlers starts waiting until the time interval is finished;
  • When the time interval is finished, the Handler sends a blocked request;
  • The Handler returns the control to the caller's thread.

Sliding Window Algorithm

The Sliding Window algorithm is used to keep track of the number of requests sent to Eurex. The algorithm works as follows:

  • For each request the Handler remembers its timestamp;
  • When the Handler receives a new transaction, it checks the number of requests sent within the time interval;
  • If the number of requests exceeds the Handler's limit, the Handler calculates the time to wait and starts waiting;
  • To calculate the time to wait, the Handler uses the following formula:

    \[ T_w = T_i - (T_c - S_{fr}) \]

    Where,
    • \(T_w\) – time to wait;
    • \(T_i\) – time interval;
    • \(T_c\) – current time;
    • \(S_{fr}\) – timestamp of the first request in the window. After Eurex lowers the limit, the window can hold more requests than the new limit; then it is the timestamp of the N-th latest request, where N is the new limit.
  • When the time to wait is finished, the Handler sends a blocked request.

Eurex Messages

Eurex provides information related to the throttling in the following messages:

  • Session Logon Response;
  • Throttle Update Notification.

When the Handler receives any of these messages it updates its internal settings to the new one according to the following fields:

  • ThrottleTimeInterval - is used to set throttle time interval in number of milliseconds applicable for transaction limit;
  • ThrottleNoMsgs - is used to set transaction limit per ThrottleTimeInterval. If set to 0, throttling will be switched off.

The requests sent within the current ThrottleTimeInterval before an update, or before a reconnection, still count against the new limits. Requests sent while throttling is switched off are not counted. When an update lengthens the interval, requests older than the previous interval may not be counted.

Heartbeats are not counted either, as Eurex does not count them, and a heartbeat does not wait when the limit is reached. It still goes out only after a request that is already waiting for the limit.

Throttle Message Margin

The Handler keeps to a limit lower than the one set by Eurex: it subtracts HandlerSettings::throttleMessageMargin, 3 by default, from ThrottleNoMsgs. For example, when Eurex sets ThrottleNoMsgs to 50, the Handler sends at most 47 requests per ThrottleTimeInterval.

Eurex counts the requests by the time they enter the gateway, not by the time the Handler sends them: it rejects a request when the gateway has already received ThrottleNoMsgs requests within the ThrottleTimeInterval before it. Jitter on the network path can bunch requests that the Handler spaced out, so that more of them arrive within one interval than the Handler sent within any interval. The margin absorbs this. On a path with uneven latency, such as a VPN, a wide-area link or a loaded host, the default margin can be too small: Eurex then rejects requests with SessionRejectReason::ThrottleLimitExceeded although the Handler keeps to its limit. The Handler reports such a reject through AdminListener::onReject. After throttleDisconnectLimit consecutive rejects, as reported by SessionListener::onThrottleSettingsChanged, Eurex disconnects the session.

If this happens, raise the margin, for example to 10, and then lower it step by step for as long as no such rejects occur. The Handler takes the margin from the settings it is constructed with, so each new margin needs a new Handler. Keep the margin below the ThrottleNoMsgs set by Eurex.

If the first Session Logon Response a Handler receives sets a limit, other than 0, that does not exceed the margin, or sets a limit with a ThrottleTimeInterval that is not positive, the logon fails. Later limits never fail the session: if a later limit does not exceed the margin, the Handler allows one request per ThrottleTimeInterval. If a later ThrottleTimeInterval is not positive, the Handler keeps the current interval, or 1000 milliseconds if Eurex has not sent a valid one yet. In both cases the Handler logs a warning and reports it through WarningListener::onWarning with WarningCode::General.

Handler Callbacks

The Handler provides the following callbacks related to the throttling:

When the Handler receives either Session Logon Response or Throttle Update Notification it calls SessionListener::onThrottleSettingsChanged.

When the Handler detects that the number of requests is higher than its limit it calls SessionListener::onThrottleDelayStarted and starts waiting. When waiting is finished, the Handler calls SessionListener::onThrottleDelayFinished and sends a blocked request.