Fork me on GitHub
cougar from Betfair

Threading, Sync, Async and Timeouts

Overview

Over time, as Cougar has grown up, the threading model has been adjusted and tweaked, new transports (both client and server) have been developed, and everything has become rather complex. This page attempts to explain away some of this complexity and enable Cougar users to make informed decisions on how to configure/develop their applications.

Async core

One thing to remember as you read all this and wonder about the complexities: Cougar is asynchronous at it’s core

We provide synchronous constructs to hide the complex nature of asynchronous implementation, but it does affect how things work, and to truly understand Cougar and how your app will work within it you need to be aware of this.

Abbreviations used

EV - Execution venue

Server concerns

Server interface / implementation style

Async

EV thread:

Any thread may call the onXXX methods on the observer, allowing the EV thread to be freed during calls that suffer from wait on external resources (DB, remote call etc), which then:

Sync

Server transports

Jetty transport (for HTTP based protocols)

The jetty threads also flush the data back after handoff from the EV after the service has returned

Socket transport

The MINA threads also write the serialised response to the wire after the service has returned

Client concerns

Generated client implementations

Sync

Async

Client transports

Socket

Does the following on the calling thread:

Does the following on the ?? thread pool:

Sync HTTP

Does everything on the calling thread:

Async HTTP

Does the following on the calling thread:

Does the following on it’s internal thread pool (CoUGAR.socket.transport.client:name=asyncHttpWorkerExecutor in JMX):

Observations

Once we know all of the above, we can make some observations on sensible / unwise combinations..

TODO