Java:是否使用 Disruptor。 。

发布于 2024-12-22 04:25:16 字数 699 浏览 0 评论 0原文

Hy,

目前我正在开发一个程序,该程序从 amq 队列中获取 2 个值并对它们执行一系列数学计算。已在 amq 服务器上创建一个主题,我的程序通过回调(侦听器)订阅并接收消息。

现在,每当消息到达时,就会从 SynchronizedDescriptiveStatistics 对象中取出并添加两个值。每次添加到值列表后,整个计算序列都会重新执行(这实际上是要求的一部分)。

我现在面临的问题是,由于我使用监听器,有时在计算过程中会收到一条或多条消息。尽管 SynchronizedDescriptiveStatistics 会自行处理所有与线程相关的问题,但当它脱离锁定或其他情况时,它会立即将所有等待值添加到其数字列表中。虽然我的问题是添加一个值,然后对其执行计算,然后执行第二个值,依此类推。

我想出的解决方案是在我的程序中使用作业队列(而不是 amq 队列)。通过这种方式,每当计算结束时,程序就会在队列中查找更多作业并相应地继续进行。

由于我也在寻找效率和速度,因此我认为 Disruptor 框架可能适合解决这个问题,并且它针对线程情况进行了优化。但我不确定在我的应用程序中实施 Disruptor 是否值得,因为常规标准队列可能足以满足我想要做的事情。

我还告诉您,需要执行计算的数据很多,并且会不断出现,并且每次添加单个值都需要以连续方式重新执行整个计算。因此,请牢记效率和海量数据,您认为从长远来看什么是有用的。

等待回复。 。 。

问候。

Hy,

Currently I am developing a program that takes 2 values from an amq queue and performs a series of mathematical calculations on them. A topic has been created on the amq server to which my program subscribes and receive messages via callbacks (listeners).

Now whenever a message arrives the two values are taken out of and added to the SynchronizedDescriptiveStatistics object. After each addition to the list of values the whole sequence of calculations is performed all over again (this is part of the requirement actually).

The problem I am facing right now is that since I am using listeners, sometimes a single or more messages are received in the middle of calculations. Although SynchronizedDescriptiveStatistics takes care of all the thread related issues it self but it adds all the waiting values in its list of numbers at once when it comes out of lock or something. While my problem was to add one value then perform calcls on it then second value and on and on.

The solution I came up with is to use job queues in my program (not amq queues). In this way whenever calcs are over the program would look for further jobs in the queue and goes on accordingly.

Since I am also looking for efficiency and speed I thought the Disruptor framework might be good for this problem and it is optimized for threaded situations. But I am not sure if its worth the trouble of implementing Disruptor in to my application because regular standard queue might be enough for what I am trying to do.

Let me also tell you that the data on which the calcs need to be performed is a lot and it will keep on coming and the whole calcs will need to be performed all over again for each addition of a single value in a continuous fashion. So keeping in mind the efficiency and the huge volume of data what do you think will be useful in the long run.

Waiting for a reply. . .

Regards.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

醉态萌生 2024-12-29 04:25:16

我将给出这个问题的典型答案:首先进行测试,然后根据结果做出决定。

虽然你谈到了效率,但你并没有具体说性能是一个基本要求。如果您了解自己的性能要求,则可以使用队列与 Disruptor 的基本实现来模拟一个简单的原型,并测量两者的性能。

如果一个人的表现比另一个人好得多,那就是你的答案。然而,如果需要付出更多的努力来实施,特别是如果它也无法为您提供所需的效率,或者您没有任何硬性能要求,那么这表明该解决方案不是正确的解决方案。

首先测量,然后根据结果做出决定。

I'll give our typical answer to this question: test first, and make your decision based on your results.

Although you talk about efficiency, you don't specifically say that performance is a fundamental requirement. If you have an idea of your performance requirements, you could mock up a simple prototype using queues versus a basic implementation of the Disruptor, and take measurements of the performance of both.

If one comes off substantially better than the other, that's your answer. If, however, one is much more effort to implement, especially if it's also not giving you the efficiency you require, or you don't have any hard performance requirements, then that suggests that solution is not the right one.

Measure first, and decide based on your results.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文