在HFT是否有意义尝试并行处理的订单? [英] in HFT does it make sense to try to parallel orders processing?

查看:223
本文介绍了在HFT是否有意义尝试并行处理的订单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我想这是为那些谁与HFT familar更多的理论问题。我从快速接收订单并对其进行处理。我收到大约每秒2-3上千份订单。但问题是,如果我应该尝试对它们进行处理同步或异步



我每次收到下一个订单,我需要做以下几点:




  • 相应仪器的更新手持订单

  • 更新依赖于该订单

  • 指数和指标
  • 更新战略和计划的一些行动(如有需要买/卖东西等)



要做到这一点同步我有大约200-300微秒(能够每秒处理3000订单)。这应该是足够,我认为。



只是安排异步任务,我花我觉得〜30微秒



赞成利弊:



同步:




  • ++并不需要同步事<!/ LI>
  • ++延迟命令被接收和行动采取之间是减少,因为不需要安排任务或传递数据/工作到另一个处理(在很重要HFT)

  • ! - 但是订单收到操作可能会延迟,因为我们可以在套接字缓冲区等待等待以前为了处理



异步:




  • ++利用现代服务器的强大能力(我的服务器例如具有24个核心)

  • ++在某些情况下更快,因为同时被处理之前的消息不要等待。

  • ++可以处理更多的消息或可以做更多的每封邮件的复杂的事情

  • - 需要同步的很多东西有什么可以减慢程序



同步的例子:我们收到MSFT为了更新,然后INTC为了更新而在不同的线程处理它们。在这两种情况下,我们触发纳斯达克指数重新计算。所以纳斯达克指数计算应同步。
但是这个特殊的问题可以workarounded避免同步...这只是可能的同步的例子。



所以,问题是,我应该处理订单同步更新或异步的。到目前为止,我处理这些异步的,我有专门的每台仪器线程。因为我可以处理实现异步双更新不同仪器(MSFT和INTC),但对于一台仪器(MSFT)两个更新应该处理的同步。


解决方案

我收到的订单快速并处理它们。我收到每秒


约2-3上千份订单

真的吗?您在交流工作?监守严重的是,我从5交换数据,但这些AREN OT订单;)我建议你让你在一个中期 - 你得到2-3万元的事件,但我真的怀疑你拿到订单



你有没有想过做一个多级处理的设置?即你在2线程的数据,把它交给另一个线程来IRT在发现仪器(ID而不是字符串),把它交给另一个线程来更新订单,把它交给另一个线程做指标,手与X线做策略?



没有必要安排任务人lthe时候,只需同步队列一个塔斯他们每个人的处理消息。 。可超fficient用无锁的方法



残酷地讲:我完全支持多线程,但都在核心处理必须保持基数,这样经典的多线程是出。为什么?我需要完全重复处理,使单元测试得到确定的输出。




到目前为止,我处理这些异步的,我有专门的每台仪器线程




您不交易了很多,对不对?我的意思是,我跟踪有关200.000仪表(5完整的交换)。分配200.000线程是 - 啊 - 望而却步;)



GO上演管道 - 这意味着核心循环可以很小,可以将它们分发到足够多的核心,你是很多更具扩展性。然后正确地优化 - 例如它是一个器械的更新很常见的进来紧接着又更新为相同的仪器(例如多次执行而大型顺序执行)。利用这一点。


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.

解决方案

I receive orders from FAST and process them. I receive about 2-3 thousands orders per second

Really? You work at an exchange? Becuase seriously, I get data from 5 exchanges, but those aren ot orders ;) I suggest you get your term in line - you get 2-3 thousand EVENTS, but I really doubt you get ORDERS.

Have you ever thought of doing a multi stage processing setup? I.e. you get data in 2 thread, hand it over to another thread to find the instrument (id instead strings), hand it over to another thread to update order book, hand it over to another thread to do indicators, hand irt over to X threads to do strategies?

No need to schedule tasks al lthe time, just synced queues with one tas processing messages on each of them. Can be super fficient with a no-lock approach.

Brutally speaking: I am all for multi threaded, but all in core processing must maintain cardinality, so classical multi threading is out. Why? I need fully repeatable processing, so that unit tests get determined output.

So far I process them asynchronous and I have dedicated thread per instrument

You do not trade a LOT, right? I mean, I track about 200.000 instruments (5 complete exchanges). Allocating 200.000 threads would be - ah - prohibitive ;)

GO staged pipeline - that means that the core loops can be small and you can distribute them to enough cores that you are a lot more scalable. THen properly optimize - for example it is quite common for updates of one instrument to come followed by another update for the SAME instrument (for example multiple executions while a large order executes). Take advantage of that.

这篇关于在HFT是否有意义尝试并行处理的订单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆