[plt-scheme] Current trunk of web server apparently broken

From: Noel Welsh (noelwelsh at gmail.com)
Date: Sun Apr 29 06:46:30 EDT 2007

I haven't seen the errors you report, so I upgraded to 396.11 (from
.8) and wrote a little test servlet based on some production code.  I
include code below.  Everything works.  Hence, some suggestions:

 - Don't use configure.ss, use instaweb instead.  It gives you a
configuration you can check into your source code repository, and
automates some of the tedious aspects of setting up the web server.

- Don't write unit servlets, use modules instead.  Modules give you
more optimisations and better error messages, and if you use DrScheme,
work better with check syntax

- Don't use the v1 interface, use v2-transitional instead.  In our
site (we get about 10K hits a day; I believe we run the busiest site
using PLT Scheme) the v2-transitional interface has given us much
better control over continuation memory usage.


The servlet (file servlet.ss)

(module servlet mzscheme

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

  (provide interface-version

  (define interface-version 'v2-transitional)

  (define timeout +1800.0)

  ;; start : request -> response
  (define (start initial-request)
    '(html (head (title "Boo-ya!"))
           (body (h1 "Boo-ya!"))))

  (define (instance-expiration-handler request)
    (printf "bye-bye!"))

  ;; manager : LRU-manager
  ;; An 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 deducted
     ;; from the continuation
     (lambda ()
       (let ([memory-use (current-memory-use)])
         (if (>= memory-use (* 256 1024 1024))
             (begin (collect-garbage)
     ;; The number of 'life points' an continuation starts with
     #:initial-count 12
     ;; Logging done whenever an continuation is collected
     #:inform-p (lambda (k) (printf "bye-bye!"))))


The instaweb wrapper (file: run-servlet.ss)

(require (planet "instaweb.ss" ("schematics" "instaweb.plt" 1)))

(print-hash-table #t)
(print-struct #t)
(error-print-width 1024)
(error-print-context-length 50)

(instaweb "servlet.ss" 8765)

Posted on the users mailing list.