[plt-scheme] Memory management of web-server

From: Adam Wick (awick at cs.utah.edu)
Date: Tue Dec 7 16:31:00 EST 2004

At Tue, 07 Dec 2004 16:10:38 -0500, David Van Horn wrote:
> The latter is more difficult.  First, I haven't been able to get the 3m 
> version of mzscheme working, 

Where are you running into problems?

> but assuming I do get it working, I don't see how 
> to use `custodian-limit-memory' to restart the server once the threshold has 
> been crossed.

Something like this seems like it'd work:

(module safe-serve mzscheme
  (require (lib "web-server.ss" "web-server"))

  (let loop ()
    (let ([serve-thread (parameterize ([current-custodian (make-custodian)])
			  (custodian-limit-memory (current-custodian)
			    (* 512 1024 1024) (current-custodian))
			  (thread (lambda () (serve ...))))])
      (thread-wait serve-thread)


Haven't tested this, though. This loop should work as follows. The loop
starts, creates a new custodian, limits that custodian to 512M, and then
starts a thread to run the web server in that custodian. The loop then
blocks until the thread halts -- and the only reason it should halt is if
the accounting system shuts down the custodian (and thus the thread) --
at which point it restarts.


Posted on the users mailing list.