[plt-scheme] concurrent database connections
On Wed, Mar 25, 2009 at 3:30 PM, YC <yinso.chen at gmail.com> wrote:
>> For different sessions to use the same connections, they must servlet
>> module-level definitions.
>
> So when web-server creates two separate threads for the same servlet module,
> does the connection get duplicated or shared? What if the connection is
> instantiated in a module that's included by the servlet module?
All the module definitions and module imports are shared for a single
servlet module.
So, DBs created in db.ss and `db' are shared for all instances of servlet1.ss.
servlet1.ss:
#lang scheme
(require "db.ss")
(define db (make-db ...))
...
(define (start req)
... uses database ...)
Suppose you also have
servlet2.ss:
#lang scheme
(require "db.ss")
(define db (make-db ...))
...
(define (start req)
... uses database ...)
Anything created in "db.ss" here is NOT shared with servlet1.ss,
unless you explicitly share "db.ss" in the namespaces.
>> For different servlets to use the same connections, there must be a
>> single module that handles the connections that is shared via
>> make-servlet-namespace.
>>
> Related to the previous question if the answer is duplicated - can
> make-servlet-namespace be used with `serve/servlet`?
Yes. See the #:servlet-namespace kw arg.
Jay
--
Jay McCarthy <jay at cs.byu.edu>
Assistant Professor / Brigham Young University
http://teammccarthy.org/jay
"The glory of God is Intelligence" - D&C 93