Fixing long standing problem with stateless web apps

This commit is contained in:
Jay McCarthy 2010-09-28 12:31:46 -06:00
parent 202af50a5a
commit e4a598ccb2
4 changed files with 9 additions and 23 deletions

View File

@ -25,7 +25,6 @@ These functions optimize the construction of dispatchers and launching of server
[#:stateless? stateless? boolean? #f] [#:stateless? stateless? boolean? #f]
[#:stuffer stuffer (stuffer/c serializable? bytes?) default-stuffer] [#:stuffer stuffer (stuffer/c serializable? bytes?) default-stuffer]
[#:manager manager manager? (make-threshold-LRU-manager #f (* 1024 1024 64))] [#:manager manager manager? (make-threshold-LRU-manager #f (* 1024 1024 64))]
[#:namespace namespace (listof module-path?) empty]
[#:current-directory servlet-current-directory path-string? (current-directory)]) [#:current-directory servlet-current-directory path-string? (current-directory)])
dispatcher/c]{ dispatcher/c]{
@racket[serve/servlet] starts a server and uses a particular dispatching sequence. For some applications, this @racket[serve/servlet] starts a server and uses a particular dispatching sequence. For some applications, this
@ -41,7 +40,7 @@ These functions optimize the construction of dispatchers and launching of server
The servlet is loaded with @racket[manager] as its continuation manager. (The default manager limits the amount of memory to 64 MB and The servlet is loaded with @racket[manager] as its continuation manager. (The default manager limits the amount of memory to 64 MB and
deals with memory pressure as discussed in the @racket[make-threshold-LRU-manager] documentation.) deals with memory pressure as discussed in the @racket[make-threshold-LRU-manager] documentation.)
The modules specified by @racket[servlet-namespace] are shared with other servlets. The servlet is run in the @racket[(current-namespace)].
} }
@defproc[(serve/launch/wait @defproc[(serve/launch/wait

View File

@ -108,8 +108,7 @@ Suppose you would like to start a server for a stateless Web servlet @filepath{s
(serve/servlet start #:stateless? #t) (serve/servlet start #:stateless? #t)
] ]
@bold{Warning:} If you put the call to @racket[serve/servlet] in a @racketmodname[web-server] module directly it will not work correctly. You can also put the call to @racket[serve/servlet] in the @racketmodname[web-server] module directly:
Consider the following module:
@racketmod[ @racketmod[
web-server web-server
(require web-server/servlet-env) (require web-server/servlet-env)
@ -122,11 +121,7 @@ Consider the following module:
(serve/servlet start #:stateless? #t) (serve/servlet start #:stateless? #t)
] ]
First, if this module is not saved in a file (e.g., @filepath{servlet.rkt}), then the serialization layer cannot locate the definitions of the Like always, you don't even need to save the file.
serialized continuations. Second, due to an unfortunately subtle bug that we have not yet corrected,
every time the continuation link is clicked, @racket[serve/servlet] will
run and attempt to start a Web server instance and open a browser window. These problems do not occur if your servlet is saved in a file
and if @racket[serve/servlet] is run in another module.
@section{Full API} @section{Full API}
@ -194,13 +189,13 @@ and if @racket[serve/servlet] is run in another module.
as its continuation manager. (The default manager limits the amount of memory to 64 MB and as its continuation manager. (The default manager limits the amount of memory to 64 MB and
deals with memory pressure as discussed in the @racket[make-threshold-LRU-manager] documentation.) deals with memory pressure as discussed in the @racket[make-threshold-LRU-manager] documentation.)
The modules specified by @racket[servlet-namespace] are shared with other servlets.
The server files are rooted at @racket[server-root-path] (which is defaultly the distribution root.) The server files are rooted at @racket[server-root-path] (which is defaultly the distribution root.)
File paths, in addition to the @filepath["htdocs"] directory under @racket[server-root-path] may be File paths, in addition to the @filepath["htdocs"] directory under @racket[server-root-path] may be
provided with @racket[extra-files-paths]. These paths are checked first, in the order they appear in the list. provided with @racket[extra-files-paths]. These paths are checked first, in the order they appear in the list.
Other servlets are served from @racket[servlets-root]. Other servlets are served from @racket[servlets-root].
The modules specified by @racket[servlet-namespace] are shared between servlets found in @racket[servlets-root] and the current namespace (and therefore
the @racket[start] procedure.)
If a file cannot be found, @racket[file-not-found-responder] is used to generate an error response. If a file cannot be found, @racket[file-not-found-responder] is used to generate an error response.

View File

@ -28,7 +28,6 @@
[dispatch/servlet (((request? . -> . response/c)) [dispatch/servlet (((request? . -> . response/c))
(#:regexp regexp? (#:regexp regexp?
#:current-directory path-string? #:current-directory path-string?
#:namespace (listof module-path?)
#:stateless? boolean? #:stateless? boolean?
#:stuffer (stuffer/c serializable? bytes?) #:stuffer (stuffer/c serializable? bytes?)
#:manager manager?) #:manager manager?)
@ -50,9 +49,7 @@
#:regexp #:regexp
[servlet-regexp #rx""] [servlet-regexp #rx""]
#:current-directory #:current-directory
[servlet-current-directory (current-directory)] [servlet-current-directory (current-directory)]
#:namespace
[servlet-namespace empty]
#:stateless? #:stateless?
[stateless? #f] [stateless? #f]
#:stuffer #:stuffer
@ -65,8 +62,7 @@
(body (p "Sorry, this page has expired. Please go back.")))) (body (p "Sorry, this page has expired. Please go back."))))
(* 64 1024 1024))]) (* 64 1024 1024))])
(define servlet-box (box #f)) (define servlet-box (box #f))
(define make-servlet-namespace (define namespace-now (current-namespace))
(make-make-servlet-namespace #:to-be-copied-module-specs servlet-namespace))
(filter:make (filter:make
servlet-regexp servlet-regexp
(servlets:make (servlets:make
@ -74,10 +70,7 @@
(or (unbox servlet-box) (or (unbox servlet-box)
(let ([servlet (let ([servlet
(parameterize ([current-custodian (make-custodian)] (parameterize ([current-custodian (make-custodian)]
[current-namespace [current-namespace namespace-now])
(make-servlet-namespace
#:additional-specs
default-module-specs)])
(if stateless? (if stateless?
(make-stateless.servlet servlet-current-directory stuffer manager start) (make-stateless.servlet servlet-current-directory stuffer manager start)
(make-v2.servlet servlet-current-directory manager start)))]) (make-v2.servlet servlet-current-directory manager start)))])

View File

@ -148,7 +148,6 @@
(dispatch/servlet (dispatch/servlet
start start
#:regexp servlet-regexp #:regexp servlet-regexp
#:namespace servlet-namespace
#:stateless? stateless? #:stateless? stateless?
#:stuffer stuffer #:stuffer stuffer
#:current-directory servlet-current-directory #:current-directory servlet-current-directory