continuations

Trust the GC

May 22, 2006 8:14:00.394

Via Don Box, I see that Ian Griffiths has a few issues with continuation based web applications. One issue he brings up is resource usage:

Sometimes the user just walks away. I might get part way through the purchasing sequence on a web site and then decide to stop. The web server never gets any positive indication that I closed the browser window. It merely stops hearing from me.

What does this mean in a world where I’m using continuations to help model user journeys as sequential code? It means that sometimes my functions just stop part way through without reaching the end.

On the plus side, it is predictable where this will happen: it can only occur at boundaries where I choose to construct a continuation and then relinquish control for now. But at every such boundary, I need to be aware that sometimes, the continuation will never execute.

This is very much not analogous to the function returning or throwing an exception. In the world of our chosen abstraction - that of sequential execution of a method - it looks like our thread has hung.

The problem with this is that a lot of the techniques we have learned for resource management stop working. Resource cleanup code may never execute because the function is abandoned mid-flow.

I don't know why this would be a problem, given a halfway decent GC system. The stale session will eventually time out, and take any lingering state down with it. I can see being worried about the memory required by this, in the face of a lot of users, but not in the basic mechanics. In a Smalltalk server - either VisualWorks or Squeak based - Ian's worry is a non-problem. Then he has an issue with thread affinity:

Traditionally, any particular invocation of a function runs on a single thread from start to finish. We’re not accustomed to mid-function thread switches, and it will render some hitherto safe practices unworkable. Using objects with thread affinity will become particularly hazardous, for example - we will need to be mindful of the potential switch points and make sure we never use such objects across such a boundary.

Actually, in this server, I've got requests that end up invoking new processes now, without continuations. They are managed with a class called Promise, but it's pretty simple - it's just a matter of delaying the waiting process and using a signal to inform the waiting process that results are ready. The pre-existing class makes that easy for me, but the code isn't hard to follow either way. Running multiple threads with shared objects is a comlex problem for any kind of application, whether continuations are involved or not.

Then he's got a long riff on how Continuations might break in the face of the Back button. Hmm - that was one of the problems that this approach was designed to solve. So far as I know, this simply isn't a problem in Seaside.

Comments

Continuations that timeout?

[] May 22, 2006 10:41:46.000

I don't know why this would be a problem, given a halfway decent GC system. The stale session will eventually time out, and take any lingering state down with it.

Do you have any references to papers describing these continuations that can timeout? (FWIW, I don't know *anything* about continuation based web frameworks, but I always assumed they worked by serializing the continuations and sending them to the client, to completely eliminate any possibility of lingering state on the server.)

Timeouts

[ James Robertson] May 22, 2006 11:03:07.152

Comment by James Robertson

The session would timeout. The session is the strong reference to any objects that hold the continuation, so when the session gets blown away (because it's removed from any attachment to "system roots"), then it (and everything associated with it) becomes eligible for GC. This has nothing to do with Continuations.

[Adam Vandenberg] May 22, 2006 17:07:35.633

"The session will time out" makes me nervous.

It gives me awful flashbacks to e-commerce sites implemented with Vingette.

Simply browsing the product catalog, getting a phone call, going for a drink of water, and coming back was enough to blow away your session.

 

 

Re: Trust the GC

[ James Robertson] May 22, 2006 17:53:07.058

Comment by James Robertson

How long a session is allowed to live is typically an application level issue.

Continuations, GC, and Threading

[IanG on Tap] May 23, 2006 6:04:23.018

Trackback from IanG on Tap Continuations, GC, and Threading

Follow the link for the reference

...

 Share Tweet This
-->