如何提高 Scala Actor 中的邮箱扫描时间

发布于 2024-09-30 11:10:39 字数 565 浏览 1 评论 0原文

我在 Scala 中创建了以下 Actor 示例: http://pastebin.com/pa3WVpKy 如果没有按行进行限制(减少 SendMoney 消息数量):

val processed = iterations - counter.getCount/2
if (processed < i - banksCount * 5) Thread.sleep(1)

此测试中的消息处理非常慢(特别是当银行参与者很少时)。

这是因为演员的邮箱里充满了SendMoney消息,接收ReadAccountResponse消息需要很长时间(它们通常几乎在邮箱的末尾,必须扫描整个邮箱)。 在这种情况下如何缩短邮箱扫描时间? 也许可以将某些消息定义为高优先级? 如果有两个邮箱就好了——一个用于普通邮件,另一个用于高优先级邮件。可以首先扫描高优先级邮箱。 另外,“回复”方法可以自动将消息发送到高优先级邮箱。或者也许创建两个邮箱 - 用于日常消息和回复? 你有什么意见?

问候 沃伊切赫·杜尔钦斯基

I created following example of actors in Scala: http://pastebin.com/pa3WVpKy
Without throttling (reducing number of SendMoney messages) that occurs in lines:

val processed = iterations - counter.getCount/2
if (processed < i - banksCount * 5) Thread.sleep(1)

message processing in this test is very slow (especially when there are few bank actors).

That's because actors' mailboxes are full of SendMoney messages and receiving ReadAccountResponse messages takes a long time (they are usually almost at the end of mailbox, and whole mailbox must be scanned).
How to improve mailbox scan time in such cases?
Maybe there is a possibility to define some messages as high priority?
It would be great to have two mailboxes - one for usual messages and one for high priority ones. The high priority mailbox could be scanned first.
Also "reply" method could send messages to high priority mailbox automatically. Or maybe create two mailboxes - for usual messages and responses?
What's your oppinion?

Regards
Wojciech Durczyński

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

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

发布评论

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

评论(2

三生池水覆流年 2024-10-07 11:10:39

Phillip Haller 的半透明函数可能是解决此问题的一个好方法,其中 scala 编译器反射性地公开有关匹配表达式可以匹配哪些类型的对象的信息。然后,参与者邮箱可以按消息类进行索引,并且查找速度可能会大大加快,尤其是在这种“大海捞针”的场景中。

这是 TransluncentFunction 的 API,如您所见,它非常简单。看起来半透明项目已经中断了一段时间,让我们希望它很快能再次复苏!

One potentially good solution to this problem will be Phillip Haller's translucent functions, in which the scala compiler reflectively exposes information about what kinds of objects a match expression can match. Then, actor mailboxes can be indexed by message class and lookup can potentially be drastically faster, especially in this kind of "needle in a haystack" scenario.

Here's the API for TransluncentFunction, as you can see it's pretty straightforward. It seems like the Translucent project has been on hiatus for awhile, let's hope it picks up again soon!

仲春光 2024-10-07 11:10:39

我相信 Lift 的 actor 正是内置了这种优先级:不是覆盖单个“行为”方法,而是有许多不同的方法(不确定确切的名称)可以根据操作的优先级来实现。

我不确定这是否可以解决扫描速度变慢的问题

I believe that Lift's actors have exactly this prioritisation built-in: rather than overriding a single "act" method, there are a number of different methods (not sure of the exact names) which can be implemented dependent on the action's priority.

I'm not sure whether this solves the scanning slowdown issue though

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