On Sunday I gave my very first workshop on the Disruptor. The aim was to give people some hands-on coding experience using the syntax. Because time was limited (you can't get people to build an entire application architecture in 2.5 hours) the example is somewhat contrived, and needs a big leap to make it into a proper application context. But the workshop should:
- Give an overview of the Disruptor
- Show how to create a simple one producer, one consumer example.
- Show how to wire up a parallel event handler
- Show how to how (and why) to create a diamond dependency graph.
- Extrapolate beyond these very simple examples to something closer to a real world architecture.
Requirements are:
If you want to work through the examples yourself, start with com.mechanitis.towerdefense.TowerDefence. The starting point code for the workshop is in package com.mechanitis.towerdefense. com.mechanitis.towerdefense1 shows a solution to exercise one, com.mechanitis.towerdefense2 to exercise 2 and so forth. The final package, com.mechanitis.towerdefense4, has some different towers you can play with to see the effects. They don't really show anything special about the Disruptor, but they were fun to write and are interesting to play with.
Trisha - the session was great, the materials and information were superb!
ReplyDeleteThank you!
DeleteHi Trisha:
ReplyDeleteThank you for this perfect demo! I see it now much clearer, how Disruptor can be used! I believe this was missing in the official Disruptor pages.
I still have two questions:
1. I don't understand the usecases for complex pipelines. Could you bring perhaps one more situation where it makes sense to have more than the typical Consumers (Persister/Logger, Business Logic, Outgoing Socket) and the typical Producers (Business Logic, Incoming Socket). I thought long and did come up with one pattern where it may make sense: Say we need to calculate orderbooks for 100 symbols, and the orderbook calculation logic takes quite a long time. Then I have the sockets that give me new quotes; and they are then consumed by two orderbook-restoration consumers. And then the business logic (for example calculate a few indicators based on the status of the orderbooks) runs only after the two orderbook consumers have finished. In this case one orderbook-consumer would be configured to process only symbols starting A-M and the second orderbook-consumer would only process symbols starting N-Z. Any other possible uses for complex
pipelines?
2. Complexity of Data-class in ringbuffer.
For my example above, then the data-class used inside the ring-buffer will get more and more complex; and I am not sure if this is what should be the case.
Also if the ring-buffer is only used as a replacement for a queue, then
the data class will not be optimal. Typically I can imagine that the data
class would be say a enum DataType{Trade=1, Quote=2, TradingSignal=3}, then
the data itselv would be in a "object DataLink" which I imagine introduces
a lot more garbage.
Did I get the point of this issue? Or am I clueless?
3. Threading of Producer and Consumer:
Producers need to manage their own threading; and Consumers run in their
own thread; BUT the managent of this thread is managed by the Disruptor.
Now for Producers I may only use one thread, correct? So if I have one
Thread for each incoming socket, then I need to have as many producers as
sockets?
Thank you
Florian
If for example the sockets
For this reason I would have two order