jbrown
jbrown

Reputation: 7996

How to limit the number of actors of a particular type?

I've created an actor to send messages to a chat server. However, the chat server only permits 5 connections per user. If I hammer my scala server I get error messages because my chat clients get disconnected.

So how can I configure akka so that my XmppSenderActors only use a maximum of 5 threads? I don't want to restrict the rest of the actor system, only this object (at the path /XmppSenderActor/).

I'm trying this config since I think it's the dispatcher I need to configure, but I'm not sure:

akka.actor.deployment {
  /XmppSenderActor {
    dispatcher = xmpp-dispatcher
  }

  xmpp-dispatcher {
    fork-join-executor.parallelism-min = 2
    fork-join-executor.parallelism-max = 3
  }
}

This gives me an error though: akka.ConfigurationException: Dispatcher [xmpp-dispatcher] not configured for path akka://sangria-server/user/XmppSenderActor

Upvotes: 2

Views: 1492

Answers (1)

Aurélien Thieriot
Aurélien Thieriot

Reputation: 5923

I would probably try to configure a Router instead.

http://doc.akka.io/docs/akka/2.0/scala/routing.html

A dispatcher seems to deal with sending messages to the inbox rather than the actual number or Actor targets.

That configuration in particular could work for you:

akka.actor.deployment {
  /router {
    router = round-robin
    nr-of-instances = 5
  }
}

The nr-of-instances will create 5 childrens from the get going and therefore fill your needs. You might need to find the right Router implementation though.

Upvotes: 3

Related Questions