views:

232

answers:

2

I'm quite impressed by what Lift 2.0 brings to the table with Actors and StatefulSnippets, etc, but I'm a little worried about the memory overhead of these things. My question is twofold:

  1. How does Lift determine when to garbage collect state objects?
  2. What does the memory footprint of a page request look like?

If a web crawler dances across the footprint of the site, are they going to be opening up enough state objects to drown out a modest VPS (512M)? The question is very obviously application dependent, but I'm curious if anyone has any real world figures they can throw out at me.

+1  A: 

I think the question about memory footprint was once answered somewhere on the mailing list, but I can’t find it at the moment.

Garbage collection is done after some idle time. There is, however, an example on the wiki which uses some better heuristics to kill off sessions spawned by web crawlers.

Of course, for your own project it makes sense to check memory consumption with something like VisualVM while spawning a couple of sessions yourself.

Debilski
Hadn't heard of VisualVM, thanks!
Stefan Mai
Don't forget VisualGC inside the jvmstat tool.
michael.kebe
+4  A: 

Lift stores state information in a session, so once the session is destroyed the state associated with that session goes away.

Within the session, Lift tracks each page that state is allocated for (e.g., mapping between an ajax button in the browser and a function on the server) and have a heart-beat from the browser. Functions for pages that have not seen the heartbeat in 10 minutes are unreferenced so the JVM can garbage collection them. All of this is tunable, so you can change heart-beat frequency, function lifespan, etc., but in practice the defaults work quite well.

In terms of session explosion, yeah... that's a minor issue. Popular sites (including http://demo.liftweb.net/ ) experience it. The example code (see http://github.com/lift/lift/tree/master/examples/example/ ) detects sessions that were created by a single request and then abandoned and expires those early. I'm running demo.liftweb.net with 256MB of heap size (that'd fit in a 512MB VPS) and occasionally, the session count rises over 1,000, but that's quickly tamped down for search engine traffic.

David Pollak
Answer from the author, I'm honored. Thanks for the details and for a wonderful project!
Stefan Mai