Hi Tim,

The reason why this is O(n^2) because unstashAll puts back all stashed
elements to the mailbox again which is O(n) and in worst case you will do
this for every Nth element resulting in the quadratic behavior.

In such cases I recommend to use instead an explicit internal queue where
you drain elements to from the mailbox instead of putting onto the stash.
This complicates your actor a bit but in this case the queuing behavior is
part of your business logic.

-Endre

On Tue, Mar 22, 2016 at 1:28 PM, Tim Pigden <[email protected]> wrote:

> I've got an FSM with Stash, something like this
>
> when (Idle)
>   case Event(cmd: ...)
>     process() // asynchronous activity
>     goto Processing
>
>
> when(Processing)
>   case Event(updated:...)
>     // do something with result
>     unstashAll()
>     goto (Idle)
>   case Event(cmd: ..)
>     stash()
>     stay
>
>
> There are periods where my process() cannot keep up with the incoming
> queue. This is not an intrinsic problem. But a problem appears to exist
> that if the queue gets sufficiently big, I spend more time doing unstashAll
> and restashing all the messages than I do processing. If my queue consists
> of n elements then I end up with O(n^2) stash and process events.
>
> I guess this means stash should not be used in cases other than queue is
> unlikely to get big. Is there a standard alternative or should I just go
> and write my own BigQueueStash ?
>
> I should add I don't think it ever gets so big that I should worry about
> back pressure - it's just queue management
>
>
>
>
>
>
>
>
>
>
>
>
> --
> >>>>>>>>>> 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 [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/akka-user.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Akka Team
Typesafe - Reactive apps on the JVM
Blog: letitcrash.com
Twitter: @akkateam

-- 
>>>>>>>>>>      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 [email protected].
To post to this group, send email to [email protected].
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