[Zope] Counter and concurrent access

Luciano Ramalho luciano@hiper.com.br
Mon, 24 Sep 2001 12:32:48 -0300


Beware of implementing counters within ZODB! Anytime you change a
property of a persistent object like a Folder or DTML Document, Zope
stores a new version of that object in ZODB. This leads to Data.fs
severe bloat!!! Use a relational database or some other Python-only
persistence mechanism to store your counter.

Best regards,

Luciano


Yann Lugrin wrote:
> 
> Hello,
> 
> I try to create a counter of which I am certain that it sends back in every
> Call a different result. I should so manage concurent acces on this one.
> 
> The following method is not valid I have to look for a product which could make
> works:
> ----
> ID = context.nextID
> context.manage_changeProperties( { 'nextID' : ID+1 } )
> ----
> 
> But products found (FSCounter and to threadSafeCounter) uses the
> File System to manage the concurrent access on the counter value.
> 
> I want to use the method described in the article " Advanced ZODB for python
> Programmers " ( Http://www.zope.org/Documentation/Articles/ZODB2) by creating a
> product based on the following code:
> 
> ------------
> class Counter(Persistent):
>     self.count = 0
> 
>     def hit(self):
>         self.count = self.count + 1
>         return self.count
> 
>     def _p_resolveConflict(self, oldState, savedState, newState):
>         # Figure out how each state is different:
>         savedDiff= savedState['count'] - oldState['count']
>         newDiff= newState['count']- oldState['count']
> 
>         # Apply both sets of changes to old state:
>         return oldState['count'] + savedDiff + newDiff
> ----------
> 
> Is the class "Persistent" assure the value " self.count " to be not identical in
> two simultaneous calls of the "hit" method (not identical return value)?
> 
> --
> Yann Lugrin
> yann.lugrin@gmproject.net
> 
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists -
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope-dev )