On Tue, Feb 9, 2010 at 10:19 AM, Ross Vandegrift <[email protected]> wrote:
> My objects aren't picklable or hashable - they have live TCP sessions.
> This means they can't be stored in beaker or memcached.  I have to
> have sockets hang around in some globally accessible memory.

``app_globals`` is a good place for database connections and
precalculated (cached) data, provided it's thread safe. If it's not,
you can put a threadlocal object under app_globals (see Python's
``threading`` module).  Or you can update the data in a local variable
and assign it all to a single ``app_global`` attribute in one step; I
think that's atomic.

The reason the SQLAlchemy Session was moved from app_globals to the
model was not because it's unsafe, but so that the model can be used
standalone without depending on the rest of the application or Pylons.

I put some lookup stuff into app_globals this week, some data that
doesn't change after startup. I thought about pylons.cache, but it
seemed like too much work for no particular benefit.

In a multiprocess server, you would duplicate data and not have them
updated simultaneously. But connections to external resources don't
use much memory and they wouldn't be updated simultaneously anyway.  I
use 'paster serve' with mod_proxy and don't worry about multi-CPU
efficiency, so it hasn't been an issue.

Earlier I had a Quixote application that cached 250 MB per process and
had three worker processes, so that was a lot of memory. I was glad to
avoid that duplication with Pylons' threaded server.

-- 
Mike Orr <[email protected]>

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.

Reply via email to