[plt-scheme] Runaway Memory in Web Server

From: Henk Boom (lunarc.lists at gmail.com)
Date: Wed May 28 23:36:17 EDT 2008

Hi, I'm using the PLT Web Server included with 370 to serve a servlet
I'm writing (just nabbed some shared hosting space with Webfaction
where I can use it). I'm having a problem though, and that is that the
web server seems to gobble more and more memory the longer it runs and
the more requests it responds to.

If I make a request, wait for the memory to go back down with a
garbage collection, then make a new request, the memory usage is
usually several MB higher than it was after the first request. After
the first few requests it sits at around 50MB, but it eventually gets
significantly higher than 150MB.

Putting a print statement in the top-level of my servlet module, I see
that the servlet does get re-evaluated after the collection, which if
I understand correctly means that my servlet is not carrying data with
it over this time. Also, my servlet does not make use of
continuations. What can I do to find out what is using the memory?

Here's the launch script I use, and please let me know if there is
other information I should give.

---- run.ss
; This file is intended to be copied and/or modified and used as a template.
(module run mzscheme
  (require (lib "cmdline.ss")
           (lib "file.ss")
           (lib "web-server.ss" "web-server")
           (lib "responders.ss" "web-server" "configuration")
           (lib "mime-types.ss" "web-server" "private")
           (lib "url.ss" "net")
           (prefix fsmap: (lib "filesystem-map.ss" "web-server" "dispatchers"))
           (prefix timeout: (lib "dispatch-timeout.ss" "web-server"
           (prefix files: (lib "dispatch-files.ss" "web-server" "dispatchers"))
           (prefix filter: (lib "dispatch-filter.ss" "web-server"
           (prefix lift: (lib "dispatch-lift.ss" "web-server" "dispatchers"))
           (prefix log: (lib "dispatch-log.ss" "web-server" "dispatchers"))
           (prefix sequencer: (lib "dispatch-sequencer.ss"
"web-server" "dispatchers"))
           (prefix lang: (lib "dispatch-lang.ss" "web-server" "dispatchers"))
           (prefix stat: (lib "dispatch-stat.ss" "web-server" "dispatchers")))

  (define server-root-path (make-parameter (string->path "./root")))
  (define port (make-parameter 8080))

       [("-p" "--port")
        ,(lambda (flag the-port) (port (string->number the-port)))
        (,(format "Specify a different port (default: ~a)"
(number->string (port)))
       [("-r" "--root")
        ,(lambda (flag path) (server-root-path (normalize-path
(string->path path))))
        (,(format "Specify a different server root path (default: ~a)"
(path->string (server-root-path)))
    (lambda (flag-accum) (void))

  (define default-host-path (build-path (server-root-path) "conf"))
  (define file-not-found-file (build-path default-host-path "not-found.html"))
  (define servlet-error-file (build-path default-host-path

  (define url->path
      (build-path (server-root-path) "htdocs")))

  (define site-url->path
    (let ((sys (fsmap:make-url->path (server-root-path))))
      (lambda (url)
        (sys (string->url "http://localhost:8080/servlets/site.ss")))))

  (define gc-thread (stat:make-gc-thread 30))

  (serve #:port (port)
           (timeout:make (* 5 60))
           (files:make #:url->path url->path
                       #:path->mime-type (make-path->mime-type
(build-path (server-root-path) "mime.types"))
                       #:indices (list "index.html" "index.htm"))
           (lang:make #:url->path site-url->path
(gen-servlet-responder servlet-error-file)
                      #:responders-servlet (gen-servlet-responder
           (lift:make (gen-file-not-found-responder file-not-found-file))))


Posted on the users mailing list.