views:

157

answers:

1

I'm considering using Actors in a system to wrap some storage (could be a database, could be an in-memory collection). The reason I want to do this is because I don't want calls to the store to be blocking from the code that's calling it and I intend to push a high volume of messages through.

Could an actor's inbound message queue handle hundreds of thousands of messages? What difference in performance would there be between code directly calling a method on an object and placing an actor with a queue in the middle?

Cheers

Joe

+3  A: 

The actor mailbox is a dequeue implemented as a mutable doubly-linked list. The size is only bound by available memory. If you send too many messages faster than the actor can process them you will receive an OutOfMemoryError.

A sending a message to an actor is calling a method. There's overhead associated with enqueueing the message, notifying the actor, assigning the actor a thread, etc. So there's a lot of stuff going on with that message send and thus a fair amount of overhead compared to a plain old synchronous method call. Of course if the method sits there and blocks for a while it will end up being slower, at least by wall time.

Erik Engbrecht