简体   繁体   English

线程池和数据关联

[英]Thread pool and data affinity

I am designing an OMS and trying to use multi-threading techniques to speed up processing. 我正在设计OMS,并尝试使用多线程技术来加快处理速度。

An easy way is to allocate threads statically: one thread for all securities starting with a letter. 一种简单的方法是静态分配线程:对于所有证券,一个线程以一个字母开头。 Obviously some of them could be very busy while others have nothing to do. 显然,其中一些人可能很忙,而其他人则无事可做。 And we don't know in advance what stocks users will enter. 而且我们不预先知道用户将输入哪些股票。

So I turn to thread pool. 所以我转向线程池。 Now time is likely to be distributed more evenly among threads. 现在,时间很可能在线程之间更均匀地分配。 But there is an overhead to be dealt with: I have to lock each order, which certainly is not pleasant. 但是要处理的开销是:我必须锁定每个订单,这当然不愉快。

Any idea about how to minimize lock time and achieve higher throughput? 关于如何最小化锁定时间并实现更高吞吐量的任何想法?

Thanks a lot for suggestions. 非常感谢您的建议。

PS, it'a Unix environment. PS,这是Unix环境。 Language used is C++ 使用的语言是C ++

Generally, thread per task is very bad decision. 通常,每个任务的线程是非常糟糕的决定。 The best way is separating tasks into logical groups with own thread pools (or, may be with 1 thread per task). 最好的方法是将任务分为具有自己的线程池的逻辑组(或者每个任务可以有1个线程)。 Also you should organize communication between tasks for example by queries. 另外,您还应该组织任务之间的通信,例如通过查询。 Do you looking throw existed thread pool implementations like threadpool ? 您是否在寻找现有的线程池实现,例如threadpool

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM