Idle timeout for Akka actors and naming of receiveTimeout variable

748 views
Skip to first unread message

Andrey Popp

unread,
Sep 26, 2010, 1:17:14 PM9/26/10
to akka...@googlegroups.com
Hello,

two days ago I've prototyped some simple web presence solution using
Akka's actors and that gave me to the thoughts, I want to discuss
about Akka. But first, let me explain how my presence actors might
work in... Erlang.

Consider Erlang function, which I will spawn in separate process each
time user goes online (one process per user):

presence_tracker() ->
receive i_am_here -> presence_tracker() % just reset timeout on receive
after 30000 -> stop % process exit and so user goes offline after 30
seconds of inactivity.

At another end, on client machine, some js code sends server Ajax
request, which will trigger 'i_am_here' message to be send to
corresponding process and that's how it works.

Now, using Akka, I can't do the same, simply because Akka has only
timeout for initial message receive by actor. Of course, I've done it
by using separate ScheduledFuture, which I handle explicitly in
actor's receive code. While it's also appropriate solution, I think,
Erlang version feels more natural and I've implement the same thing
for Akka at http://github.com/andreypopp/akka along with specs. But, I
still think this code is just proof of concept.

By introducing idleTimeout code below:

val presennceActor = actorOf(new Actor {
self.idleTimeout = Some(30000L)

protected def receive = {
case PresenceContinues =>
() // reset timeout
case ReceiveTimeout =>
handleUserOffline // user goes offline
}
}).start

will work the same as Erlang version.

The other use cases of this feature — well, any logic, that require
handling of idle state.

Also, receiveTimeout name for variable that just means *initial*
receive timeout seems confusing to me — why not introduce
initialReceiveTimeout for that purpose and mark receiveTimeout as
deprecated.

--
Andrey Popp

phone: +7 911 740 24 91
e-mail: 8ma...@gmail.com

Irmo Manie

unread,
Sep 27, 2010, 3:57:47 AM9/27/10
to akka...@googlegroups.com
Hi Andrey,

Thanks for notifying.

If we make it an idleTimeout as you suggest, would there then still be a need for an initial timeout?
We could also flag the ReceiveTimeout object itself marking it initial or not. 

I've created a ticket for this so we'll pick it up for the next milestone.

Cheers,
Irmo



--
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To post to this group, send email to akka...@googlegroups.com.
To unsubscribe from this group, send email to akka-user+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/akka-user?hl=en.


Jonas Bonér

unread,
Sep 27, 2010, 4:37:42 AM9/27/10
to akka...@googlegroups.com
Hi Andrey, I like your suggestion. 
--
Jonas Bonér

work: http://akkasource.org
code: http://github.com/jboner
blog:  http://jonasboner.com
twtr:  @jboner




Andrey Popp

unread,
Sep 27, 2010, 1:31:44 PM9/27/10
to akka...@googlegroups.com
Hi Irmo,

I, personally, don't see any reason to have both idle and initial
timeouts, but if you care about backward compatibility you should keep
the last one, although 1.0 is a good reason to break bwc. :-)

About marking ReceiveTimeout object with the reason it was received — I'm +1.

On Mon, Sep 27, 2010 at 11:57 AM, Irmo Manie <irmo....@gmail.com> wrote:
> Hi Andrey,
> Thanks for notifying.
> If we make it an idleTimeout as you suggest, would there then still be a
> need for an initial timeout?
> We could also flag the ReceiveTimeout object itself marking it initial or
> not.
> I've created a ticket for this so we'll pick it up for the next milestone.
> http://www.assembla.com/spaces/akka/tickets/446-make-receivetimeout-work-as-in-erlang

--

Jonas Bonér

unread,
Sep 28, 2010, 4:06:34 AM9/28/10
to akka...@googlegroups.com
I'd go for only idle. 

--
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To post to this group, send email to akka...@googlegroups.com.
To unsubscribe from this group, send email to akka-user+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/akka-user?hl=en.

Viktor Klang

unread,
Oct 4, 2010, 2:51:41 PM10/4/10
to akka...@googlegroups.com
Hey Andrey,

I just pushed support for Erlang-style receive timeout to master.

You will have to explicitly set: self.receiveTimeout = None to stop the recurring of timeouts.

Check it out and get back to me

Cheers,

On Sun, Sep 26, 2010 at 7:17 PM, Andrey Popp <8ma...@gmail.com> wrote:
--
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To post to this group, send email to akka...@googlegroups.com.
To unsubscribe from this group, send email to akka-user+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/akka-user?hl=en.




--
Viktor Klang,
Code Connoisseur
Work:   www.akkasource.com
Code:   github.com/viktorklang
Follow: twitter.com/viktorklang
Read:   klangism.tumblr.com

Andrey Popp

unread,
Oct 4, 2010, 3:42:02 PM10/4/10
to akka...@googlegroups.com
Hello, Viktor,

it's all ok, looking forward 1.0 release. Thanks!

Jonas Bonér

unread,
Oct 4, 2010, 3:53:44 PM10/4/10
to akka...@googlegroups.com
Good job.
--
Jonas Bonér
Specialist at Large
http://akkasource.org
twtr: @jboner

"Viktor Klang" <viktor...@gmail.com> wrote:

>> akka-user+...@googlegroups.com<akka-user%2Bunsu...@googlegroups.com>

Irmo Manie

unread,
Oct 5, 2010, 1:36:58 AM10/5/10
to akka...@googlegroups.com
NIce one Viktor :)

Garrick Evans

unread,
Oct 6, 2010, 1:19:13 PM10/6/10
to Akka User List
Should self.stop automatically reset receiveTimeout to None? Right now
it's required explicitly to prevent an exception.


On Oct 4, 10:36 pm, Irmo Manie <irmo.ma...@gmail.com> wrote:
> NIce one Viktor :)
>
>
>
> On Mon, Oct 4, 2010 at 9:53 PM, Jonas Bonér <jo...@jonasboner.com> wrote:
> > Good job.
> > --
> > Jonas Bonér
> > Specialist at Large
> >http://akkasource.org
> > twtr: @jboner
>
> > "Viktor Klang" <viktor.kl...@gmail.com> wrote:
>
> > >Hey Andrey,
>
> > >I just pushed support for Erlang-style receive timeout to master.
>
> > >You will have to explicitly set: self.receiveTimeout = None to stop the
> > >recurring of timeouts.
>
> > >Check it out and get back to me
>
> > >Cheers,
>
> > >On Sun, Sep 26, 2010 at 7:17 PM, Andrey Popp <8may...@gmail.com> wrote:
>
> > >> Hello,
>
> > >> two days ago I've prototyped some simple web presence solution using
> > >> Akka's actors and that gave me to the thoughts, I want to discuss
> > >> about Akka. But first, let me explain how my presence actors might
> > >> work in... Erlang.
>
> > >> Consider Erlang function, which I will spawn in separate process each
> > >> time user goes online (one process per user):
>
> > >> presence_tracker() ->
> > >>  receive i_am_here -> presence_tracker() % just reset timeout on receive
> > >>  after 30000 -> stop % process exit and so user goes offline after 30
> > >> seconds of inactivity.
>
> > >> At another end, on client machine, some js code sends server Ajax
> > >> request, which will trigger 'i_am_here' message to be send to
> > >> corresponding process and that's how it works.
>
> > >> Now, using Akka, I can't do the same, simply because Akka has only
> > >> timeout for initial message receive by actor. Of course, I've done it
> > >> by using separate ScheduledFuture, which I handle explicitly in
> > >> actor's receive code. While it's also appropriate solution, I think,
> > >> Erlang version feels more natural and I've implement the same thing
> > >> for Akka athttp://github.com/andreypopp/akkaalong with specs. But, I
> > >> still think this code is just proof of concept.
>
> > >> By introducing idleTimeout code below:
>
> > >>  val presennceActor = actorOf(new Actor {
> > >>    self.idleTimeout = Some(30000L)
>
> > >>    protected def receive = {
> > >>      case PresenceContinues =>
> > >>        () // reset timeout
> > >>      case ReceiveTimeout =>
> > >>        handleUserOffline // user goes offline
> > >>    }
> > >>  }).start
>
> > >> will work the same as Erlang version.
>
> > >> The other use cases of this feature — well, any logic, that require
> > >> handling of idle state.
>
> > >> Also, receiveTimeout name for variable that just means *initial*
> > >> receive timeout seems confusing to me — why not introduce
> > >> initialReceiveTimeout for that purpose and mark receiveTimeout as
> > >> deprecated.
>
> > >> --
> > >> Andrey Popp
>
> > >> phone: +7 911 740 24 91
> > >> e-mail: 8may...@gmail.com
>
> > >> --
> > >> You received this message because you are subscribed to the Google
> > Groups
> > >> "Akka User List" group.
> > >> To post to this group, send email to akka...@googlegroups.com.
> > >> To unsubscribe from this group, send email to
> > >> akka-user+...@googlegroups.com<akka-user%2Bunsubscribe@googlegroups .com>
> > <akka-user%2Bunsu...@googlegroups.com<akka-user%252Bunsubscribe@googleg roups.com>
>
> > >> .
> > >> For more options, visit this group at
> > >>http://groups.google.com/group/akka-user?hl=en.
>
> > >--
> > >Viktor Klang,
> > >Code Connoisseur
> > >Work:  www.akkasource.com
> > >Code:   github.com/viktorklang
> > >Follow: twitter.com/viktorklang
> > >Read:   klangism.tumblr.com
>
> > >--
> > >You received this message because you are subscribed to the Google Groups
> > "Akka User List" group.
> > >To post to this group, send email to akka...@googlegroups.com.
> > >To unsubscribe from this group, send email to
> > akka-user+...@googlegroups.com<akka-user%2Bunsubscribe@googlegroups .com>
> > .
> > >For more options, visit this group at
> >http://groups.google.com/group/akka-user?hl=en.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Akka User List" group.
> > To post to this group, send email to akka...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > akka-user+...@googlegroups.com<akka-user%2Bunsubscribe@googlegroups .com>

Viktor Klang

unread,
Oct 6, 2010, 3:48:24 PM10/6/10
to akka...@googlegroups.com
Hey Garrick,

Open a ticket, I'll fix it tomorrow.
Thanks!

Cheers,

Viktor Klang
Code Connoisseur
www.akkasource.com

> To unsubscribe from this group, send email to akka-user+...@googlegroups.com.

√iktor Klang

unread,
Oct 7, 2010, 8:02:37 AM10/7/10
to akka...@googlegroups.com
Garrick,

this should be fixed in master,
thanks for reporting it.

Cheers,

Garrick Evans

unread,
Oct 7, 2010, 10:44:32 AM10/7/10
to Akka User List
thanks viktor. was going to open a ticket this morning. you're too
fast
> > >>>>> for Akka athttp://github.com/andreypopp/akkaalongwith specs. But, I

Jonas Bonér

unread,
Oct 7, 2010, 10:49:50 AM10/7/10
to akka...@googlegroups.com
Viktor is like the lightning, moves faster than the sound of the commits.
--
Jonas Bonér
Specialist at Large
http://akkasource.org
twtr: @jboner

"Garrick Evans" <buk...@gmail.com> wrote:

>To unsubscribe from this group, send email to akka-user+...@googlegroups.com.

Garrick Evans

unread,
Oct 7, 2010, 10:56:03 AM10/7/10
to Akka User List
he'd gotta keep himself busy since he never travels to all the cool
conferences

On Oct 7, 7:49 am, Jonas Bonér <jo...@jonasboner.com> wrote:
> Viktor is like the lightning, moves faster than the sound of the commits.
> --
> Jonas Bonér
> Specialist at Largehttp://akkasource.org
> >> > >>>>> for Akka athttp://github.com/andreypopp/akkaalongwithspecs. But, I

Jonas Bonér

unread,
Oct 7, 2010, 11:33:52 AM10/7/10
to akka...@googlegroups.com
True. On the other hand I never get to complete anything.
--
Jonas Bonér
Specialist at Large
http://akkasource.org
twtr: @jboner
Reply all
Reply to author
Forward
0 new messages