[Zope-Coders] Persistent Sessions question

Chris McDonough chrism@zope.com
Mon, 14 Oct 2002 18:09:46 -0400


This looks pretty good!  Shane's "external mount" product seems to work 
for this purpose as well: 
http://www.zope.org/Members/hathawsh/ExternalMount ..

Were I you, I'd be a little skittish about using a ZEO ClientStorage to 
serve up session data.  It should work fine in theory but I suspect 
you'll get a magnitude increase in conflict errors over a comparable 
local storage, which might lead to application errors, especially if 
it's hit hard.  You should pound it good before putting it into 
production under this setup if you expect a lot of traffic.  If you find 
anything, we'll get it fixed...

FWIW, also, please try to use Zope 2.6 instead of Zope 2.5 for 
sessioning stuff.  Zope 2.5's transience implementation had some bugs 
and exposed others in the 2.5 BTree implementation that made it unstable 
under heavy load.  If you must use 2.5, at least copy the Transience and 
BTrees packages out of 2.6 and recompile...

Shee ya,

-C


Evan Simpson wrote:
> This is primarily a question for Chris, but please chime in if you're 
> familiar with <ominous echo>Mounting Databases</ominous echo>.
> 
> I'm setting up an application where Sessions will save me a lot of work, 
> but I want to ensure that a user's session data doesn't just disappear 
> in the middle of their, well, session.  In particular, data kept in 
> temp_folder will go *poof* when I restart the server.
> 
> I don't want to keep sessions in the main ZODB, either, since they can 
> change frequently and there will be a lot of them.  Also, I'm using ZEO. 
>  Fun enough yet? ;-)
> 
> My solution seems to work, but I'm very nervous about it and want 
> reassurance.  I set up ZEO to serve a 'Sessions.fs' FileStorage in 
> addition to the normal 'Data.fs'.
> 
> I copied & hacked TemporaryFolder into a Product called MountedFolder. 
> Here are the important guts from the MountedFolderMount class:
> 
>     def __init__(self, id, label):
>         self.id = str(id)
>         self.label = str(label)
>         MountPoint.__init__(self, path='/',
>                             params='Mountable %s' % self.label)
> 
>     def _createDB(self, db=None):
>         """ Fetch the storage to mount from
>             the Mountables dictionary in custom_zodb. """
>         # We defer actually creating the Storage until it is needed.
>         klass, args, kwargs = 
> sys.modules['Zope.custom_zodb'].Mountables[self.label]
>         db = DB(klass(*args, **kwargs))
>         return db
> 
>     def _getMountRoot(self, root):
>         sdc = root.get('folder', None)
>         if sdc is None:
>             sdc = MountedFolder()
>             sdc.id = self.id
>             sdc.storage_label_ = self.label
>             root['folder'] = sdc
>         return sdc
> 
> Now, I created a MountedFolderMount with label 'Session'. In my 
> 'custom_zodb.py', I created a dictionary called 'Mountables' with a 
> single entry: the key is 'Session' and the value is a tuple consisting 
> of ZEO.ClientStorage.ClientStorage, a tuple, and a dictionary containing 
> the necessary arguments.  So, when the MountedFolderMount's _createDB is 
> called, it instantiates a new ClientStorage and wraps it in a DB.
> 
> Having done all this, I created a Transient Object Container in the 
> MountedFolder and set expiration to about a week.  I pointed my Session 
> Data Manager at the new container, and everything *seems* to work as 
> planned.
> 
> Thanks,
> 
> Evan
> 
> 
> _______________________________________________
> Zope-Coders mailing list
> Zope-Coders@zope.org
> http://lists.zope.org/mailman/listinfo/zope-coders

-- 
Chris McDonough                    Zope Corporation
http://www.zope.org             http://www.zope.com
"Killing hundreds of birds with thousands of stones"