[racket] web server: module servlets

From: Jay McCarthy (jay.mccarthy at gmail.com)
Date: Fri Sep 26 20:08:30 EDT 2014

Hi George,

I suggest that all Racket web-server apps not use the dynamic features
of serve/servlet either, but instead write the servlet as the single
"request -> response" function that serve/servlet provides. This would
ensure that all the libraries are loaded the one time and has the best
performance out of all the options of the Web server. Furthermore,
there are many features (such as total URL control) that are only
available in this model.

In case it is not completely clear, here's a little example (<500
lines) of a Web application that works this way:

https://github.com/plt/racket/blob/master/pkgs/plt-services/meta/pkg-index/official/dynamic.rkt#L423

Here's another that uses 'serve' directly for non-servlet needs:

https://github.com/jeapostrophe/exp/blob/master/dir-serve.rkt

And here's a considerably longer one:

https://github.com/jeapostrophe/grade-samurai/blob/master/app.rkt#L2020

I highly recommend using serve/servlet like this over any other
options. In particular, many of the problems you're talking about were
the reason that I made serve/servlet in the first place.

Jay

On Fri, Sep 26, 2014 at 12:16 AM, George Neuner <gneuner2 at comcast.net> wrote:
> On 9/25/2014 6:26 PM, Jay McCarthy wrote:
>
> web-server/servlet is NOT shared, nor is any net library or common
> racket library like racket/list. They are all totally unique per
> servlet.
>
> This, by the way, is part of why I don't recommend using dynamic
> servlets at all and suggest using serve/servlet.
>
>
> But ... IIUC ... a listener started by  serve/servlet  will still
> dynamically load from <servlet-root>, <server-root>/htdocs/*, etc. if the
> request doesn't match a hard coded dispatch URL - the regex of the initial
> servlet or an entry in a dispatcher table.  At least that's the behavior I
> see with my own application: my initial servlet returns 404 when called -
> the call to  serve/servlet  just sets up the environment and and all the
> "real" servlets are demand loaded from disk when first touched.
>
> Are you advocating *static* linking and essentially just dispatching to
> internal functions by URL?  ISTM that that defeats the purpose.
>
> George



-- 
Jay McCarthy
http://jeapostrophe.github.io

           "Wherefore, be not weary in well-doing,
      for ye are laying the foundation of a great work.
And out of small things proceedeth that which is great."
                          - D&C 64:33

Posted on the users mailing list.