Reputation: 31576
I am trying to write some code against a very old database which crashes if its hit very hard.
I am looking for ways in which my actor does not process more than X messages per second.
Right now, I guess the default implementation of the actor is that it processes the messages in its messagebox as fast as possible.
But I wonder if there is a way I can configure my actor so that there is a limit of "X" number of messages per second from the actor message queue.
Upvotes: 1
Views: 700
Reputation: 149636
You're looking for a TimerBasedThrottler
:
val printer = system.actorOf(Props[PrintActor])
// The throttler for this example, setting the rate
val throttler = system.actorOf(Props(
classOf[TimerBasedThrottler],
3 msgsPer 1.second))
throttler ! SetTarget(Some(printer))
And then send messages via the throttler ActorRef
.
Upvotes: 2