OnixS C++ B3 BOE Binary Order Entry  1.2.0
API Documentation
Threading Models

The handler supports the following threading models for usual sockets:

The OnixS::B3::BOE::ThreadingModel::External mode supports the Solarflare TCPDirect technology that is described in the Solarflare TCPDirect section.

The model is configured via the OnixS::B3::BOE::SessionSettings::threadingModel(ThreadingModel::Enum value) method.

Dedicated

In OnixS::B3::BOE::ThreadingModel::Dedicated mode the Handler creates a dedicated receiving thread and a dedicated sending thread for each OnixS::B3::BOE::Session instance.

The receiving thread receives and processes incoming SBE messages.

The Handler tries to send an outgoing application-level message in the thread that calls the OnixS::B3::BOE::Session::send method. If the message cannot be sent immediately, then it is saved to the queue for the subsequent sending by the sending thread. This behavior can be changed using the OnixS::B3::BOE::Session::messageGrouping method.

The following table shows which thread could fire a particular callback.

Callback Application threadSending thread Receiving thread
OnixS::B3::BOE::SessionListener::onError No Yes Yes
OnixS::B3::BOE::SessionListener::on*(messageName) No No Yes
OnixS::B3::BOE::SessionListener::onReceivedBytes No No Yes
OnixS::B3::BOE::SessionListener::onMessageSending Yes Yes Yes
OnixS::B3::BOE::SessionListener::onStateChange Yes Yes Yes
OnixS::B3::BOE::SessionListener::onWarning Yes Yes Yes

Pool

In OnixS::B3::BOE::ThreadingModel::Pool mode the Handler creates the thread pool and shares it between all sessions. The maximum number of threads in the pool is configured via the OnixS::B3::BOE::SessionSettings::threadPoolSize parameter. The default value (0) of this parameter means that the thread pool's size will be equal to the CPU's number. In the thread pool, each thread performs read/write operations and can process a number of different FIXP connections, which are distributed equally among all threads. The thread pool is used also to perform the asynchronous TCP connect when the OnixS::B3::BOE::Session::connectAsync() method is called.

External

In OnixS::B3::BOE::ThreadingModel::External mode the Handler does not create I/O threads. Such mode means that user creates additional threads himself (or uses the main thread), then performs event dispatching in a loop by calling the OnixS::B3::BOE::SessionReactor::dispatchEvents() routine. This mode supports the Solarflare's TCPDirect and regular TCP connections. For TCPDirect connections, one should use the OnixS::B3::BOE::TcpDirectStack as a reactor. For regular TCP connections, one should use OnixS::B3::BOE::TcpStandardStack as a reactor.

Note
The TCPDirect technology is NOT thread-safe. Therefore, the event dispatching and message sending should be performed from the same thread.
OnixS::B3::BOE::ThreadingModel::External mode is set automatically when an external reactor is provided to the session's constructor, regardless of which threading model was specified by SessionSettings. If OnixS::B3::BOE::ThreadingModel::External mode is configured, but an external reactor is not provided during Session's construction, an exception will be thrown.

Additional Threads That Can Be Spawned

If the configured threading model equals OnixS::B3::BOE::ThreadingModel::Dedicated and the OnixS::B3::BOE::Session::connectAsync() method is used, the Handler creates a separate thread to perform the asynchronous TCP connect. Each such thread is started when the OnixS::B3::BOE::Session::connectAsync() method is called and is stopped when the asynchronous TCP connect is completed.

If the OnixS::B3::BOE::SessionStorageType::AsyncFileBased value is passed to the OnixS::B3::BOE::Session constructor, the Handler creates an additional thread for each Session instance. This thread performs session storage operations.

When a session has some network issues, the Handler will restore the FIXP connection. For this purpose, a separate thread is created to avoid blocking Handler's IO threads in non-TCPDirect connection modes.