I want to do a multi-agent simulation containing about 10.000 agents (machine and product agents) using the Scala Actor framework.
As I understand, if there are lots of actors passing messages around, can it run out of stack due the recursion?
If so, how can I increase the stack sizes for the underlying worker threads?
We've already covered some instances where the Actor Model isn't ideal. Such as when you need a sequential order of things to happen. If you find yourself sending multiple messages and then needing to rollback those processes if one fails, you might want to reconsider using the Actor Model.
The fundamental idea of the actor model is to use actors as concurrent primitives that can act upon receiving messages in different ways: Send a finite number of messages to other actors. Spawn a finite number of new actors. Change its own internal behavior, taking effect when the next incoming message is handled.
The Actor Framework is a software library that supports the writing of applications in which multiple VIs run independently while communicating with each other.
The Actor Model provides a higher level of abstraction for writing concurrent and distributed systems. It alleviates the developer from having to deal with explicit locking and thread management, making it easier to write correct concurrent and parallel systems.
The actor framework has been designed to handle this - in fact, it can handle this with only one thread, assuming you use the loop-react
pattern as follows:
import actors._
import actors.Actor._
val a = actor {
loop {
react {
case ABC => //Handle here
}
}
}
On pp 590-593 of Programming in Scala this is discussed in more detail: basically the react
method never returns normally (it terminates with an exception) and therefore its call stack does not need to be preserved. You can think of it as looping forever.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With