Forum OpenACS Development: Threading and global scope: how to proceed?

As I am not an expert on OpenACS or AOLServer, I would like some input as to whether this will work or not before I proceed.

I need to write some code for a particular problem, but I am not sure how the threading model in OpenACS/AOLServer works. The way I envision it working is this: there is a "global global" and a "local global" of scope.

"Global global" is procs and variables defined in startups like the tcl directory -inits and -procs. These are global across ALL threads, meaning when a web page is loaded and the corresponding script is run (I presume this must be in its own thread), that script has access to stuff defined in -inits and -procs which were already sourced at boot, and it doesn't have to re-source anything.

Each thread also gets it's own global (a "local global") where it can declare global variables and procs available globally to that thread, but aren't available to other threads. This would correspond to a normal global scope in a single-threaded environment.

My basis for assuming it works this way is the fact that there are these -procs and -inits that make things available to all threads, so I assume that has to be the "global global." But while I haven't tested this, it seems there must be a "local global" as well, otherwise one user's script could interfere with another user's script if both pages were hit at the same time.

At any rate, I can proceed after knowing which way it works.

Thanks.

Collapse
Posted by Gustaf Neumann on
Here is a short, simplified summary, how the sharing and threading model of aolserver works.

Upon startup, the server collects from all configured packages the -proc.tcl files and builds from these files a so-called blueprint (consider this as a single large file containing all the definitions). Aolserver uses threads for various purposes. For the handling of incoming HTTP requests, the "connection threads" (sometimes called "request threads") are used.

When a connection thread starts up, its interpreter is initialized with the blueprint. Therefore, every request has all procs/objects/global variables of the configured packages available without any loading.

Aolserver handles a pool of connection threads, every
connection thread serves typically several http requests (the number is configurable in the config file). After a connection thread has processed the configured number of requests (or an idle timeout) it shuts down. New connection threads are created upon needs.

After every request, the connection thread performs a cleanup that deletes e.g. the global variables (the variables in the namespace "::" of the tcl interpreter of the connection thread).

Connection threads are an important part of the picture, but there is much more infrastructure available: In addition to the connection threads, there are driver and spooler threads (naviserver), there are threads for scheduled procs, it is possible to define job-queues, one can define persistent threads, etc., there are options for lazy-loading, etc.

From your terminology, "global global" refers to the blueprint, and "local global" refers to the interpreter of the connection threads.

Hope this helps to understand the basic model.

Collapse
Posted by sal berg on
That's sort of how I envisioned it, and I was hoping it worked that way.

Thanks very much - now I know how to proceed.