The Feed Engine concept encapsulates data delivery aspects to let the Handler focus on market data processing. It also provides advanced facilities on utilizing system resources to achieve the best performance and latency characteristics.
The SDK offers the OnixS::CME::ConflatedUDP::SocketFeedEngine class as the primary and default implementation of the Feed Engine concept to receive market data transmitted through the multicast feeds.
The following code sample depicts how to construct an instance of the Feed Engine, link it with an instance of the Handler, and run the Feed Engine machiner to let the Handler process incoming market data and other events.
Multiple Handler instances can share a single instance of the Feed Engine:
If the implementation of the Feed Engine concept supports multithreaded processing, then it's possible to take advantage of distributing Feed Engine machinery tasks across multiple threads.
The SDK exposes a ready-to-use service which cyclically invokes the OnixS::CME::ConflatedUDP::NetFeedEngine::process member function of the associated instance of the OnixS::CME::ConflatedUDP::NetFeedEngine class by a set of threads. The functionality is encapsulated in the OnixS::CME::ConflatedUDP::FeedEngineThreads class.
The given class manages a pool of threads. When an instance of the class is created, it spawns working threads. The number of threads is defined by the ThreadPoolSettings::size parameter, which can be accessed through the OnixS::CME::ConflatedUDP::FeedEngineThreadSettings::pool member. Each thread cyclically calls the OnixS::CME::ConflatedUDP::NetFeedEngine::process member for the instance of the OnixS::CME::ConflatedUDP::NetFeedEngine class delivered to the service (class) at construction time.
All events exposed by the service encapsulated into the OnixS::CME::ConflatedUDP::FeedEngineThreadListener class. Subscribing to events is done at the service construction time.
The following table uncovers meaning of each event:
Event | Description |
---|---|
OnixS::CME::ConflatedUDP::FeedEngineThreadListener::onFeedEngineThreadBegin | Invoked by the working thread before entering master processing loop. Event callback is invoked in the context of working thread allowing the subscriber to perform thread-specific turning like setting affinity or priority for the thread. |
OnixS::CME::ConflatedUDP::FeedEngineThreadListener::onFeedEngineThreadEnd | Invoked by when a particular 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 like deleting data stored in thread local storage. |
OnixS::CME::ConflatedUDP::FeedEngineThreadListener::onFeedEngineThreadIdle | Invoked when the working thread is idle. At an active phase, a working thread is running market data processing loop. It analyses the returned value of OnixS::CME::ConflatedUDP::NetFeedEngine::process call. If neither OnixS::CME::ConflatedUDP::NetFeedEngineProcessResult::ioWaited nor OnixS::CME::ConflatedUDP::NetFeedEngineProcessResult::eventsDispatched flags are raised for a predefined number of iterations the working thread invoked the OnixS::CME::ConflatedUDP::NetFeedEngine::process member, then the thread raises the given event. The given callback assumes returning a boolean value which indicates whether a working thread invoked the given callback should sleep for a bit of time in order to reduce load onto CPU or resume processing without any delay.
|
OnixS::CME::ConflatedUDP::FeedEngineThreadListener::onFeedEngineThreadIssue | Invoked when a working thread experiences an issue while carrying out its tasks of if invocation of the OnixS::CME::ConflatedUDP::NetFeedEngine::process member leaded to exception throwing. |