On Fri, 2010-06-25 at 12:55 -0600, Shane Hathaway wrote:
> On 06/25/2010 12:03 PM, Wichert Akkerman wrote:
> > I am using repoze.zodbconn in a BFG application but I suspect it is not
> > working as it should be: as soon as multiple requests come in at the
> > same time I get a lot of locking errors and broken results:
> >
> > LockError: Couldn't lock
> > '/Users/wichert/Work/code/buildout/blackbox/var/Data.fs.lock'
> >
> > The way I've setup repoze.zodbconn is
> >
> >       from repoze.zodbconn.finder import PersistentApplicationFinder
> >       from myproject import appmaker
> >       finder = PersistentApplicationFinder(settings["zodb.url"], appmaker)
> >       def get_root(request):
> >           return finder(request.environ)
> >       return get_root
> 
> According to the docs[1], your code should look more like this:
> 
>        from repoze.zodbconn.finder import PersistentApplicationFinder
>        from myproject import appmaker
>        finder = PersistentApplicationFinder(settings["zodb.url"],
>            appmaker)
>        app = finder(request.environ)
>        return app
> 
> OTOH, personally, I don't think this is a good pattern.  I think the 
> right idea is to open the connection in the WSGI stack [2].  That way, 
> other WSGI components can use the connection, and you can guarantee that 
> the connection gets closed.  repoze.zodbconn supports both patterns.

The problem Wiggy saw seems to have been related to a race condition,
which I've fixed in release 0.12
(http://pypi.python.org/pypi/repoze.zodbconn/0.12).

While it's probably trivial overhead, the issue with using the
"connector" middleware that adds a ZODB connection to the environment at
ingress is that not all requests actually need the connection.  For
example, image requests never need a ZODB connection.  In Wiggy's
application, there are a lot requests to the application which use a
relational database, but which never access ZODB.

This is a problem shared with other middleware like repoze.who, which
adds identification information to the request.  In the case of
repoze.who, it can add nontrivial processing time to inject
identification info into the environ, which can add inappropriate
performance penalty for requests for images, and other views which dont
require authentication information.

We've addressed this in repoze.who by giving r.who's middleware a mode
which injects only a factory into the environ instead of more eagerly
constructing identity information.  We can't really do that for
repoze.zodbconn#connector, or at least it doesn't make much sense to do
so, given that the entire purpose of opening it early is to be able to
close it easily.

- C


_______________________________________________
Repoze-dev mailing list
Repoze-dev@lists.repoze.org
http://lists.repoze.org/listinfo/repoze-dev

Reply via email to