Question

I have done some research with the disruptor patern and there's one thing I can't wrap my head arround.

There are the producers, which provide the entry's for the ring buffer. There is the ringbuffer, basically a fixed but endless array. There are the consumers (basically sperate threads), handling the entries from the ringbuffer.

I'm trying to relate how the disruptor patern can be used in a real case scenario of a stock market.

Usually you would have the orderbook containing all orders. How I see it, a producer would receive a new order from a broker. The producer places the order in the ringbuffer. After the order has been placed in the ringbuffer, a consumer fetches the order and cross-checks it with the orderbook.

Now here is the part where I'm having a bit of trouble understanding the advantage. If there would be multiple consumers, which is what you want for scalable system, how can there be multiple consumers handing orders?

The orderbook has to be locked when accessed by a consumer to ensure integrity. What I'm looking for is an answer to this question and a rough idea how a order matching engine could possibly benefit from this patern.

LMAX has their own order matching engine, so there has to be something I'm overlooking.

Thank you

Was it helpful?

Solution

they have a single consumer handling the orders themselves. the rest of the consumers act on this order processors' output - things like returning responses, writing logs, writing to database etc. actual order processing takes place on a single thread, which is the only thread to access the orderbook and so does not need to lock it.

they claim to be able to do up to 6 million orders/sec on this single thread.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top