Question

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

Was it helpful?

Solution

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!

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top