This page is no longer maintained — Please continue to the home page at www.scala-lang.org

acting like a thread pool

1 reply
Razvan Cojocaru 2
Joined: 2009-11-20,
User offline. Last seen 42 years 45 weeks ago.

Is this the equivalent of the classic thread pool + work requests in the
actor model or is there an off-the-shelf load-balancer thing?

class Engine {

import Actor._

// load balancer
val processor : Actor = actor {
var i = 0
loop {
react {
case Exit => {
exit ();
processors foreach (_ ! Exit)
}
case m @ _=> { processors(i) ! m; i = (i+1) % 5 }
}}
}

val processors : Array[Actor] = Array.fill (5) {actor {
loop { react {
...
}

-----
Razvan Cojocaru,
Work: http://www.sigma-systems.com
Playground: http://wiki.homecloud.ca
Latest cool toy: http://scripster.codewitter.com
Follow me: http://feeds.razie.com/RazvanTech RSS Feed ,
http://twitter.com/razie Twitter , http://github.com/razie GitHub .

Viktor Klang
Joined: 2008-12-17,
User offline. Last seen 1 year 27 weeks ago.
Re: acting like a thread pool
Hello Razvan,

The Akka-framework has this for you:

Code:
http://github.com/jboner/akka/blob/master/akka-core/src/main/scala/routing/Routers.scala#L33

And if you want a brief intro:
http://klangism.tumblr.com/

On Wed, May 19, 2010 at 2:40 PM, Razvan Cojocaru <razie@razie.com> wrote:

Is this the equivalent of the classic thread pool + work requests in the
actor model or is there an off-the-shelf load-balancer thing?


class Engine {

 import Actor._

 // load balancer
 val processor : Actor = actor {
   var i = 0
   loop {
      react {
        case Exit => {
           exit ();
           processors foreach (_ ! Exit)
        }
        case m @ _=> { processors(i) ! m; i = (i+1) % 5 }
   }}
 }

 val processors : Array[Actor] = Array.fill (5) {actor {
   loop { react {
...
}



-----
Razvan Cojocaru,
Work: http://www.sigma-systems.com
Playground: http://wiki.homecloud.ca
Latest cool toy: http://scripster.codewitter.com
Follow me:  http://feeds.razie.com/RazvanTech RSS Feed ,
http://twitter.com/razie Twitter ,  http://github.com/razie GitHub .

--
View this message in context: http://scala-programming-language.1934581.n4.nabble.com/acting-like-a-thread-pool-tp2222759p2222759.html
Sent from the Scala - User mailing list archive at Nabble.com.



--
Viktor Klang
| "A complex system that works is invariably
| found to have evolved from a simple system
| that worked." - John Gall

Akka - the Actor Kernel: Akkasource.org
Twttr: twitter.com/viktorklang

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland