[plt-scheme] web-server memory use

From: Jay McCarthy (jay.mccarthy at gmail.com)
Date: Mon Apr 30 10:02:32 EDT 2007

This might answer your question. The use of custodians works like this:

When the server is started, it makes a new custodian (the "server custodian").

When a connection is made, a new custodian is created. This is a child
of the server custodian.

When the server realizes that the connection will make servlet
requests, there are two cases: New instance or old instance. In the
case of a new instance, an INSTANCE custodian is created who's parent
is the server custodian. The `start' method is executed with this
custodian as the current-custodian. However, if the SERVLET has not
yet been loaded, that must be done. When the servlet is loaded, a new
custodian (who's parent is the server custodian) is created. Any
allocation that happens during module loading takes place here, and
the current-custodian of the manager will be this custodian. In the
case of an old instance, the SERVLET custodian is used to get to the
instance data and the continuation. When the continuation is invoked,
the parameterization at the time of continuation capture is used, and
therefore the INSTANCE custodian is in effect.

So. How does this answer your question?

Data reachable by module `define'd variables will be accounted to the
servlet custodian.

There is a bit of a problem, because the continuation manager is
reachable by the servlet custodian, and it touches all your
continuations, which touches all your instance data. So, it seems like
the only memory accounted to the instance custodian will be memory
generated in calculation of responses that is not reachable by
continuations. I don't think we can use weakly-held references to the
continuations, because the whole point of the manager is subvert the
GC and do something different.

Jay

On 4/30/07, Dave Gurnell <d.j.gurnell at gmail.com> wrote:
> Hi again,
>
> We've been getting some fast-expiring continuations using the web-
> server recently. I'm worried it might be a memory consumption thing,
> so I'm trying to find out how much memory instances and continuations
> are taking up.
>
> I tried copying and customising lru.ss to do the following:
>
>    - I added a custodian field to the instance structure:
>
>      (define-struct instance (data k-table use-count custodian))
>
>    - I modified create-instance to store a reference to the current
> custodian
>      (which, looking at dispatch-servlets.ss, ought to be the
> instance's custodian):
>
>      (hash-table-put! instances
>                       instance-id
>                       (make-instance data (create-k-table) 0 (current-
> custodian)))
>
>    - I printed the custodian's memory use in instance-lookup:
>
>      (printf "Memory use: ~a~n" (current-memory-use (instance-
> custodian instance)))
>
> This prints 0 each time. I checked the documentation and it doesn't
> look like this is an effect of memory accounting being switched off
> (although I'm not sure how I'd check that anyway).
>
> Am I heading down the right track here? Are programmer-created data
> structures allocated under the instance custodian or the servlet
> custodian?
>
> Cheers,
>
> -- Dave
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>


-- 
Jay McCarthy <jay.mccarthy at gmail.com>
http://jay.teammccarthy.org


Posted on the users mailing list.