There are considerations listed in the references for stateless servlets.<div><br></div><div>> First, this process drastically changes the structure of your program. It will create an im-<div>mense number of lambdas and structures your program did not normally contain. The per-</div>
<div>formance implication of this has not been studied with Racket.</div><div><br></div><div>So this is implicit? Right? No code changes on the user side.</div><div><br></div><div>> Second, the defunctionalization process is sensitive to the syntactic structure of your pro-</div>
<div>gram. Therefore, if you change your program in a trivial way, for example, changing a</div><div>constant, then all serialized continuations will be obsolete and will error when deserializa-</div><div>tion is attempted. This is a feature, not a bug! It is a small price to pay for protection from</div>
<div>the sorts of errors that would occur if your program were changed in a meaningful way.</div><div><br></div><div>Ok, I get that.</div><div><br></div><div>> Third, the values in the lexical scope of your continuations must be serializable for the con-</div>
<div>tinuations itself to be serializable. This means that you must use define-serializable-</div><div>struct rather than define-struct, and take care to use modules that do the same. Simi-</div><div>larly, you may not use parameterize, because parameterizations are not serializable.</div>
<div><br></div><div>Haven't tried with struct yet; doesn't look like a big issue.</div><div><br></div><div>> Fourth, and related, this process only runs on your code, not on the code you require. Thus,</div><div>
your continuations—to be serializable—must not be in the context of another module.</div><div><br></div><div>Again, serialization issue.</div><div><br></div><div><br></div><div><br></div><div class="gmail_quote">On Sun, May 8, 2011 at 7:12 AM, Rahul Kumar <span dir="ltr"><<a href="mailto:rahulsinner@gmail.com">rahulsinner@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Thanks Jay.<div><br></div><div>Worked like a charm. For anyone else fighting with the same issue, the only change needed is the `#lang web-server` in-place of `#lang racket` in the code sample - `#:stateless? #t` is already there.</div>
<div><br></div><div>Out of curiosity, since I didn't need to make any code changes to make stateless work, is there any reason to run stateful servlets? The only concern I see is the default stuffer which does disk writes - that too if the urls are large. Nothing a fast disk and short ulrs can't mitigate.</div>
<div><div></div><div class="h5">
<div><br></div><div><br><br><div class="gmail_quote">On Sun, May 8, 2011 at 6:57 AM, Jay McCarthy <span dir="ltr"><<a href="mailto:jay.mccarthy@gmail.com" target="_blank">jay.mccarthy@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Stateless servlets must be written in the #lang web-server language.<br>
<br>
Once you write them that way, if you want to start a server that<br>
launches them, you need to use #:stateless?<br>
<br>
Unless you have both pieces, it won't work.<br>
<br>
Jay<br>
<br>
2011/5/7 Rahul Kumar <<a href="mailto:rahulsinner@gmail.com" target="_blank">rahulsinner@gmail.com</a>>:<br>
<div><div></div><div>> Hi,<br>
> What do I need to do to run a stateless servlet?<br>
> Consider the following example taken from the web tutorial. I just added<br>
> `#:stateless? #t` while starting.<br>
> #lang racket<br>
> (require web-server/servlet<br>
> web-server/servlet-env)<br>
> ; start: request -> response<br>
> (define (start request)<br>
> (show-counter 0 request))<br>
> ; show-counter: number request -> doesn't<br>
> ; Displays a number that's hyperlinked: when the link is pressed,<br>
> ; returns a new page with the incremented number.<br>
> (define (show-counter n request)<br>
> (send/suspend/dispatch<br>
> (lambda (url)<br>
> (response/xexpr<br>
> `(html (head (title "Counting example"))<br>
> (body<br>
> (a<br>
> ([href ,(url<br>
> (lambda (req)<br>
> (show-counter (add1 n) req)))])<br>
> ,(number->string n))))))))<br>
> (serve/servlet start<br>
> #:port 7070<br>
> #:servlet-path "/"<br>
> #:listen-ip #f<br>
> #:stateless? #t)<br>
><br>
> This doesn't work. I am looking at the web server reference but I can't find<br>
> a proper example.<br>
><br>
><br>
</div></div>> _________________________________________________<br>
> For list-related administrative tasks:<br>
> <a href="http://lists.racket-lang.org/listinfo/users" target="_blank">http://lists.racket-lang.org/listinfo/users</a><br>
><br>
<font color="#888888"><br>
<br>
<br>
--<br>
Jay McCarthy <<a href="mailto:jay@cs.byu.edu" target="_blank">jay@cs.byu.edu</a>><br>
Assistant Professor / Brigham Young University<br>
<a href="http://faculty.cs.byu.edu/~jay" target="_blank">http://faculty.cs.byu.edu/~jay</a><br>
<br>
"The glory of God is Intelligence" - D&C 93<br>
</font></blockquote></div><br></div>
</div></div></blockquote></div><br></div>