if i want to implement am http server.
i create new actor per request. So it can scale up as my cpu updated.
but will it cause memory usage problem? it is said that actor have some strange behavior while gc. the code will be somehow like that:
class Worker extends Actor {
def act = react {
case req : Request => perform(req);exit()
}
}
class HttpEventHandler{
def onConnect(conn) = {
new Worker ! createRequest(conn)
}
}
Edit: i made a test about this, check my test in detail http://jilen.iteye.com/blog/1231178
Lift had some problems with Scala's built-in actor library a couple of years ago, which prompted them to write their own actor library. I have no idea whether Scala's built-in actors still have the same problems the Lift community experienced back then. You'll have to do your own testing to find out. (Or maybe someone with recent experience can chime in).
I do recommend checking out the Akka Actors library. Overall, I think it's an improvement to Scala's built-in implementation. It even has a spawn
function, which does exactly what you're doing here (creating an actor to process a single message and die).
Edit:
You code listing in particular will probably leak actors, since you do not explicitly exit()
your actors when you're done with them.
Edit 2:
Turns out that Scala itself has a spawn
function (Thanks Stefan). I don't know if it behaves any better than Scala actors.
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