Well I assume this is more theoretical question for those who familar with hft. I receive orders from FAST and process them. I receive about 2-3 thousands orders per second. The question is if I should try to process them synchronous or asynchronous.
Every time I receive next order I need to do following:
- update orderbook of corresponding instrument
- update indexes and indicators that depends on that order
- update strategies and schedule some actions if required (buy/sell something etc.)
To do that synchronous I have about 200-300 µs (to be able to process 3000 orders per second). That should be enough I think.
Just to schedule asynchronous task I spent I think ~30 µs
Pros and cons:
Synchronous:
- ++ don't need to synchronize things!
- ++ delay between "order is received" and "actions is taken" is less because don't need to schedule tasks or pass data/work to another process (very important in hft!).
- -- however "order is received" action may be delayed because we can wait in socket buffer waiting for previous order to process
Asynchronous:
- ++ ability to use the power of modern servers (my server has 24 cores for example)
- ++ in some scenarios faster, because don't wait while previous message is processed.
- ++ can process more messages or can do more "complex" things per message
- -- need to synchronize a lot of things what can slow-down program
Example of synchronization: We receive MSFT order updated and then INTC order update and process them in different threads. In both cases we trigger NASDAQ index recalculation. So NASDAQ index calculation should be synchronized. However this particular problem can be workarounded to avoid synchronization... It's just an example of possible synchronization.
So the question is should I process orders updates synchronous or asynchronous. So far I process them asynchronous and I have dedicated thread per instrument. Because I can process asynchronous two updated for different instruments (MSFT and INTC), but two updates for one instrument (MSFT) should be processed synchronous.