简体   繁体   English

如何使用 LMAX 干扰器在数组中查找最大元素

[英]How to find max element in array using LMAX disruptor

您能否提供有关使用 LMAX Disruptor 模式实现并行排序或并行最大查找的代码示例的链接。

It's not really applicable.它不是真的适用。 The disruptor is essentially behaving like a pipe with a handler visiting every item in isolation, but it's implemented very differently for avoiding locks and improving locality of references.干扰器本质上就像一个管道,带有一个单独访问每个项目的处理程序,但它的实现方式非常不同,以避免锁定和改进引用的局部性。

To find the max, this handler would have to "leak" information in a central place, thus colliding with other threads trying to produce their own value.为了找到最大值,这个处理程序必须在一个中心位置“泄漏”信息,从而与试图产生自己的值的其他线程发生冲突。 To sort, I wouldn't even know where to begin... you want each handler to do some insertion sort into separate array somewhere else and merge later?要排序,我什至不知道从哪里开始……您希望每个处理程序对其他地方的单独数组进行一些插入排序,然后再合并? That's just so not a good fit.那太不合适了。

Besides, some thread has to put the data in the ring, which is pretty much the linear search you could have done in the first place.此外,某些线程必须将数据放入环中,这几乎是您最初可以完成的线性搜索。 If the ring could be built directly over an existing array (to skip publishing), then what's the point of the disruptor?如果可以直接在现有阵列上构建环(跳过发布),那么破坏者的意义何在? You would be better off with a bunch of threads given a sub range of the array.给定数组的子范围,使用一堆线程会更好。

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

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