Ok. Thanks Ben. I have a follow up question about the thread safety
setup.
def __call__(self, environ, start_response):
""" base.py controller. Get mongodb site context aware object
based on subdomain """
conn = environ['pylons.pylons'].app_globals.mongo_conn
site = get_site_context(environ)
self.db = Mongo(mongo_conn, 'myproject', site) # subclass of
pymongo.database, with site context awareness
return WSGIController.__call__(self, environ, start_response)
Here the Mongo(mongo_conn, 'myproject', site) is just a simple
subclass of the pymongo.database, but is aware of the requesting site/
subdomain. This way, if I say self.db.events.save({name:'Concert'}),
self.db knows how to save that document to the requesting site's
collection. (my mongo collections are segregated by site/subdomain).
>From my questionable testing, it seems to be thread safe, that is,
docs are getting saved to proper collections. From googling around
though, it seems I may need to use something like threading.local()?
Can anybody point me on the right direction on this? Sorry.. not very
well versed in threading.
Also, also if anybody has a better approach or tips on this, I'm all
ears :)
Thanks,
Chris
On Sep 12, 1:37 am, Ben Bangert <[email protected]> wrote:
> On Sep 11, 2009, at 6:47 PM, Chris wrote:
>
> > I saw Ben's blog app 'minger' has been built with MongoDB. Thanks for
> > sharing that. A few questions about mongodb usage with pylons:
> > - is setting up the mongo connection in lib/app_globals.py the
> > recommended way to go? (like minger)
>
> For connection pools and such, I'd consider app_globals the best place
> to hang it. Since app_globals is global to the application, the object
> there should be thread-safe of course.
>
> > - it looks like pymongo has a built-in connection pool (defaults to
> > 1), should that be higher for production sites? Should it match the
> > number of threads that Paste (or others) will spawn?
>
> Ah yes, I suppose I could up it. I actually hadn't realized at the
> time that it was using its own connection pool. Ideally it should
> probably match however many connections your MongoDB server handling,
> and of course, less than or equal to the number of threads that are
> being used for the application.
>
> Cheers,
> Ben
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---