[plt-scheme] Web Server Send/Suspend/Finish questions

From: Noel Welsh (noelwelsh at yahoo.com)
Date: Wed Oct 18 04:58:57 EDT 2006

To answer your question directly:  set the timeout once,
when the servlet is loaded.

However, I recommend two things:

  - update to 352.7.  All the cool kids are using it. 
We've been running it for, oh, half a day now with now

  - Use the v2-transitional servlet interface which gives
you much greater control over continuation expiry.  Example
code is below.  The definition of manager is the main thing
to look at.


(module sbcs mzscheme

   (lib "main.ss" "sbcs")
   (lib "response.ss" "web-server")
   (lib "servlet.ss"  "web-server")
   (lib "lru.ss" "web-server" "managers")

  (provide interface-version
  (define interface-version 'v2-transitional)
  (define timeout +1800.0)
  ;; start : request -> response
  (define (start initial-request)
      (go initial-request)))
  (define (instance-expiration-handler request)
    (handle-expired-instance request))

    ;; manager : LRU-manager
  ;; An instance (or continuation?) is allowed to live a
  ;; maximum of 6 hours (30 minutes x 12), and a minimum of
  ;; 1 minute (5 seconds x 12).  Lifetime is controlled by
  ;; memory usage.  Usage above 256MB will result is more
  ;; rapid death.  This caps the max size of uploaded files
  ;; to around 100MB, which should still be plenty.
  (define manager
     ;; Called when an instance has expired.
     ;; The condition below is checked every 5 seconds
     ;; One 'life point' is deducted every 30 minutes
     (* 30 60)
     ;; If this condition is true a 'life point' is
     ;; from the instance (or is it continuation?)
     (lambda ()
       (>= (current-memory-use)
           (* 256 1024 1024)))
     ;; The number of 'life points' an instance (or
continuation?) starts with
     #:initial-count 12
     ;; Logging done whenever an instance (or
     ;; is collected
     #:inform-p (lambda (removed)
                  (printf "Collected instance: ~S  memory
use: ~SM~n"
                          (round (/ (current-memory-use)
                                    (* 1024 1024)))))))

--- Hans Oesterholt-Dijkema <hdnews at gawab.com> wrote:

>       How should I use
>       __|adjust-timeout!|__
> To set the timeout value in a servlet. Do I need to
> repeat it before each suspend?
> --Hans

Email: noelwelsh <at> yahoo <dot> com   noel <at> untyped <dot> com
AIM: noelhwelsh
Blogs: http://monospaced.blogspot.com/  http://www.untyped.com/untyping/

Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 

Posted on the users mailing list.