[plt-scheme] web-server and make-servlet-namespace

From: Jay McCarthy (jay.mccarthy at gmail.com)
Date: Mon Oct 29 12:54:36 EDT 2007

I'll do my best to answer your question.

On 10/29/07, Dave Gurnell <d.j.gurnell at gmail.com> wrote:
> I'm adding a fair chunk of code to the servlet namespace. It
> shouldn't make a difference in terms of the behaviour of my
> application as I only have one servlet. That said, I don't really
> know how modules and namespaces and servlet loading work behind the
> scenes.

Every time a servlet is loaded, the web-server makes a new servlet
namespace. This provides isolation between the servlets, as the
namespace is initially empty. Thus if two servlets use the same module
that has some state, they are separate from one another. Typically the
only modules that are copied into the new namespace are those
necessary to access the server's data-structures --- i.e. responses
and requests.

So, when you put something in the servlet namespace, you are actually
causing LESS memory to be used, as the module is only loaded once,
rather than multiple times. However, you are ensuring that it is
loaded before any servlet is loaded, and this requires that the server
be restarted to load any changes.

> Am I impacting the memory efficiency of my web-server
> installation by doing this? If so, am I impacting it positively or
> negatively? Should I refactor things so I only include a couple of
> very small modules in the namespace, or can I be blazé about it?

You are. Positively. You can be flagrant in your use of this feature,
as long as you recognize any state sharing that you are creating.

This feature was created to allow database connection pools,
databases, and structure sharing, by the way. So it seems it is
fulfilling the measure of its creation.


Jay McCarthy <jay.mccarthy at gmail.com>

Posted on the users mailing list.