You need to slow down the producer, because otherwise messages will fill up
mailboxes (if you use await) or buffers (if you use stash) eventually
resulting in out of memory.

I don't think a router is the right tool here. I would implement this with
an ordinary actor that delegates to the doWork and performs the bookkeeping
of number of jobs in progress. It can pipe to self to know when a job is
done. It has to send acknowledgments back to the producer or requests for
more work to the producer. The producer must behave and not send more than
acknowledged/requested. This is often called "work pulling" if you want to
google for more inspiration.

It can also be good to know that Akka Streams has this kind of async
backpressure built in so it might be easier to use Akka Streams for this
part.

Cheers.
Patrik

On Fri, Mar 24, 2017 at 4:29 AM, Justin du coeur <jduco...@gmail.com> wrote:

> I suspect you're looking for stash(), which is the usual answer to "I want
> to pause my inbox for a bit"...
>
> On Thu, Mar 23, 2017 at 8:47 PM, Sean Callahan <sean.callahan...@gmail.com
> > wrote:
>
>> Hey all. Ive got an Actor set up that when called, takes a little bit of
>> time to run and I want to limit how many "runs" happen at the same time. I
>> have a routing pool above this actor to accomplish that. However, in my
>> current implementation of the actor I am blocking to get that
>> functionality, and I definitely dont want to lose that thread to a blocking
>> call.
>>
>> If I use Future.pipeTo(sender()), the actor than pulls from the mailbox
>> almost immediately causing more work to be run that I would like. Im
>> guessing I am either missing something simple, or there is a better pattern
>> out there to solve this problem?
>>
>> class ArchiveActor (workerClass: Worker) extends Actor with Logging {
>>
>>   import context.dispatcher
>>
>>   private def run(minute: DateTime): Future[ArchiveResult] = {
>>     // work is done here that returns a future
>>     workerClass.doWork(minute)
>>   }
>>
>>   override def receive: Receive = {
>>     case Run(minute) =>
>>       sender().tell(Await.result(run(minute), Duration.Inf),
>> context.parent)
>>   }
>>
>>
>> --
>> >>>>>>>>>> Read the docs: http://akka.io/docs/
>> >>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/c
>> urrent/additional/faq.html
>> >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "Akka User List" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to akka-user+unsubscr...@googlegroups.com.
>> To post to this group, send email to akka-user@googlegroups.com.
>> Visit this group at https://groups.google.com/group/akka-user.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
> --
> >>>>>>>>>> Read the docs: http://akka.io/docs/
> >>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/
> current/additional/faq.html
> >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
> ---
> You received this message because you are subscribed to the Google Groups
> "Akka User List" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to akka-user+unsubscr...@googlegroups.com.
> To post to this group, send email to akka-user@googlegroups.com.
> Visit this group at https://groups.google.com/group/akka-user.
> For more options, visit https://groups.google.com/d/optout.
>



-- 

Patrik Nordwall
Akka Tech Lead
Lightbend <http://www.lightbend.com/> -  Reactive apps on the JVM
Twitter: @patriknw

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to