OnixS ICE iMpact Multicast Price Feed Handler C++ library 8.18.0
Users' manual and API documentation
Loading...
Searching...
No Matches
Setting Up Feed Engine

The Feed Engine concept encapsulates network-related aspects, allowing the Handler to focus on market data processing. It also provides advanced facilities for utilizing system resources used by the Handler to achieve optimal performance and latency characteristics.

Previously, there were no shared services between the Handler instances. Thus, system resources were allocated exactly for and by a particular instance. That caused certain inefficiencies in resource utilization. For example, each Handler instance used from one to two threads to manage incoming market data processing. As a result, the number of threads used by multiple Handler instances was multiplied by the number of those instances and significantly exceeded the resources required to solve the market data processing task.

The concept of the Feed Engine was introduced to make things more efficient. The Feed Engine machinery is used by the Handler to receive and process market data starting from the recent major release. Multiple Handler instances can share a single Feed Engine instance.

Using Feed Engine

The FeedEngine class represents the Feed Engine concept. The Feed Engine events are reported through an instance of the FeedEngineListener class, which is associated with the Feed Engine instance during construction.

The following code sample depicts primary aspects of using the Feed Engine with two Handler instances:

// STEP 1: is to set configuration parameters.
FeedEngineSettings feedEngineSettings;
feedEngineSettings.threadCount = NUMBER_OF_WORKING_THREADS;
// STEP 2: is to construct a shared feed engine.
FeedEngine feedEngine(feedEngineSettings);
// STEP 3: is to bind the feed engine to Handler instances.
HandlerSettings handlerSettings;
Handler handler(handlerSettings);
handler.bindFeedEngine(feedEngine);
Note
Market data processing is performed in the Feed Engine's worker threads. The size of the internal thread pool is defined by the FeedEngineSettings::threadCount parameter.

Feed Engine Events

All Feed Engine events are encapsulated in the FeedEngineListener interface. The FeedEngine class accepts an instance of a listener upon construction.

The following list uncovers Feed Engine events:

  • onFeedEngineThreadBegin

    Invoked by the Feed Engine working thread before entering a master processing loop.

    The event callback is invoked in the context of the working thread, allowing the subscriber to perform thread-specific tuning, such as setting affinity or priority.

  • onFeedEngineThreadEnd

    Invoked by the Feed Engine when the working thread is about to end.

    The given event callback is invoked in the context of the working thread, allowing the subscriber to perform thread-specific cleanup, such as deleting data stored in thread-local storage.

  • onFeedEngineThreadIdle

    Invoked by the Feed Engine when the working thread is idle.

    During an active phase, the Feed Engine working thread runs a market data processing loop. The working thread may wait for incoming market data using an appropriate I/O operation.

    A working thread raises the given event if no incoming data is detected for a certain time interval (defined by the FeedEngineSettings::dataWaitTime parameter). The FeedEngineThreadIdleReasons::DataWaitTimeout is passed as a reason for the idle state.

    It may happen that a thread misses entering the waiting state for incoming data because other threads have already been doing that for all active feeds, and there are no other tasks like processing already received market data. In such a case, the working threads spin for a certain time (defined by the FeedEngineSettings::spinBeforeIdleTime parameter value) while waiting for any pending tasks to be executed. If no pending tasks were found, the working thread enters an idle state with the FeedEngineThreadIdleReasons::Redundant reason.

    The given event callback also exposes a parameter variable whose value indicates the time interval the working thread is suggested to spend sleeping to reduce races between working threads when executing pending tasks (data reception, data processing, etc.) and thus reduce CPU load. The parameter value can be modified inside the callback body.

    Note
    It's not recommended to change the sleep interval when the working thread enters the idle state after waiting for incoming data, to avoid overflowing the buffer used for incoming data.
    Warning
    There's no predictability in firing the given event by the Feed Engine. Each working thread may wait for incoming data, receive incoming data, or process data previously received by that or any other threads. The availability of active tasks executed by the working threads depends on many factors, including bound Handler instances, system capacity, the number of allocated working threads, clock resolution, and others.