[ZODB-Dev] shared cache when no write?

Leonardo Rochael Almeida leorochael at gmail.com
Tue Dec 18 03:15:25 UTC 2012


Hi,

On Mon, Dec 17, 2012 at 10:03 PM, Dylan Jay <djay at pretaweb.com> wrote:
>
> On 14/12/2012, at 8:32 AM, Jim Fulton <jim at zope.com> wrote:
>
>> On Thu, Dec 13, 2012 at 4:18 PM, Dylan Jay <djay at pretaweb.com> wrote:
>> ...
>>> I'd never considered that the cache was attached to the db connection rather
>>> than the thread. I just reread
>>> http://docs.zope.org/zope2/zope2book/MaintainingZope.html and it says
>>> exactly that.
>>> So what your saying is I'd tune db connections down to memory size on an
>>> instance dedicated to io bound and then increase the threads. Whenever a
>>> thread requests a db connection and there isn't one available it will block.
>>> So I just optimize my app the release the db connection when not needed.
>>> In fact I could tune all my copes this way since a zone with 10 threads and
>>> 2 connections is going to end up queuing requests the same as 2 threads and
>>> 10 connections?
>>
>> Something like that. It's a little more complicated than that because
>> Zope 2 is managing connections for you, it would be easy to run afoul
>> of that.  This is a case where something that usually makes your life
>> easier, makes it harder. :)
>
> true. With Plone as you have many modules sharing the connection all expecting it to be the same connection closing the connection half way through isn't possible. If it was closed and another connection opened then the other modules that are outside of your control might have references to stale data.
>
>>
>> What I'd do is use a separate database other than the one Zope 2 is
>> using.  Then you can manage connections yourself without conflicting
>> with the publisher is doing.  Then, when you want to use the database,
>> you just open the database, being careful to close it when you're
>> going to block.  The downside being that you'll have separate
>> transactions.
>>
>>> This should be easier to achieve and changes the application less than the
>>> erp5 background task solution mentioned.
>>
>> It would probably be a good idea to lean more bout how erp does this.
>> The erp approach sounds like a variation on what I suggested.

Indeed, it's clear from all the proposed solutions (including DJ's
reconnect after transaction end but before returning to the user) that
you can't have, at the same time, a single ZODB transaction AND
immediate user feedback, when depending on an external system.

There's not much more to the ERP5 technique than what I already
explained earlier. It boils down to:

 * take user input
 * store it as received with as little processing as possible
 * trigger background activities (as few as possible) for anything
that requires looking beyond the object the user is currently
manipulating and it's immediate vicinity (specially object
reindexing).
 * return info to the user as fast as possible, including any info
telling him to check back later if necessary.

> It's not always possible as sometimes you need to feedback the result to the user immediately.
> Let's take another example. A Plone site with a page that lets you upload a mp3 file and it guesses the song, then combines that with your preference data to return other songs you might like. The guessing the song bit is an external service and the preference data is stored in the same zodb as Plone.
> To do it the ERP background task way you;d deliver back a page with some javascript on it that polls the server to see if the song had been processed yet. This isn't always desirable, esp if you have to avoid javascript.

Avoiding JavaScript is possible with the same approach GitHub does
when forking a repo: a meta-http-equiv-refresh message "we're
processing your request. This page will update itself when we're done.
You may refresh if it on your own if it makes you feel like you're in
control".

Providing user feedback is usually less tricky than coping with system
restrictions. As long as the user is seeing something happening, and
the system feels like it's evolving towards a solution, instead of
seeming stuck, users tend to be satisfied.

In your example, the user already waits quite a bit for his file
upload to finish. Having him wait on the external system to handle the
date could be a bit too much, better return some info to him and show
the rest later.

> [...]

Cheers,

Leo


More information about the ZODB-Dev mailing list