views:

568

answers:

1

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?

+8  A: 

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.

oxbow_lakes
Thank you. I might have overlooked that sentence in the book. And what about the way to increase the worker threads stack size - just curious?
kd304
have a look at: http://lampsvn.epfl.ch/trac/scala/browser/scala/tags/R_2_7_5_final/src/actors/scala/actors/FJTaskScheduler2.scala?view=markup. You'll see that you can define system properties like "actors.maxPoolSize" etc
oxbow_lakes
Although the point is to let the FJTaskScheduler decide on how much concurrency your system supports (i.e. how many available processors there are)
oxbow_lakes
I don't see an option setting the Thread stack size there. But thanks.
kd304
Sorry - wasn't reading your comment properly. Surely thread stacks sizes are controlled at the JVM level and hence configurable as any Java program would be (-Xss or something like that)
oxbow_lakes
-Xss is a way. I thought more like a ThreadFactory similarly as in java's ThreadPoolExecutor.
kd304
I didn't realize you could set stack size in a java executor
oxbow_lakes