[ZODB-Dev] About ZEO client cache

Hector Sanchez SanMartin Hector.Sanchez at cern.ch
Fri Jul 2 06:47:31 EDT 2004


    Hello everyone,

    I'm trying to figure out how the ZEO client cache works becuase some 
of the pages of the web application we are building are becoming very 
slow apparently due to the latency of fetching objects from ZODB. My 
problems appear in pages that make a kind of "summaries" or "listings", 
for example: you want to build a page containing a listing of  all the 
books you have in the DB alogn with their topics; this takes quite a lot 
of time (if I use FileStorage is really fast, problems come when using 
ZEO) and I was wondering if we could improve them by enabling the ZEO 
client cache.
    So while doing some tests using ZEO persistent client cache , I 
realised that cache works perfectly if it is the client who writes the 
objects into the DB; but if it only reads them from the DB the cache has 
no effect at all (0% of cache hits). Please see below the sample program 
I'm using for testing. If I run this program twice, the ZEO cache 
analyser gives me a hit rate of 0%, which is normal as it is the first 
time it fetches every object for this client; the second time I run it, 
it still gives me a 0% hit rate which I find a bit strange as he should 
have kept all those objects in the cache and there is no other client 
which is writing to the DB and therefore could invalidate the cache. Am 
I missing something? Any clue? Can someone think in a way I could find 
out why is not working as I expect?


Thanks a lot in advance

Here's the simple test program:

import ZODB
import Persistence
from ZODB.PersistentList import PersistentList
from BTrees.OOBTree import OOBTree
from ZEO.ClientStorage import ClientStorage
from ZODB.DB import DB



class Topic(Persistence.Persistent):
   
    def __init__(self,id):
        self._id=id
        self._name="no name"

    def getId(self):
        return self._id

    def setName(self,newName):
        self._name=newName.strip()

    def getName(self):
        return self._name


class Book(Persistence.Persistent):
   
    def __init__(self,id):
        self._id=str(id)
        self._title="no title"
        self._topics=PersistentList()

    def setTitle(self,newTitle):
        self._title=newTitle.strip()

    def getTitle(self):
        return self._title

    def addTopics(self,l):
        for topic in l:
            if topic not in self._topics:
                self._topics.append(topic)

    def getTopicList(self):
        return self._topics

   

storage=ClientStorage(("cdsdev.cern.ch",9676),client="cache")
db=DB(storage)
conn=db.open()
root=conn.root()
books=root["books"]
res=[]
for book in books.values():
    t=[]
    for topic in book.getTopicList():
        t.append(topic.getName())
    res.append("Book: %s (%s)"%(book.getTitle(),",".join(t)))
print "%s books"%len(res)
   
get_transaction().commit()
db.close()


-- 
Hector Sanchez

CERN Document Server ** <http://cds.cern.ch/> ** <cds.support at cern.ch>
InDiCo Project       ** <http://cern.ch/indico>
Room: Bldg 513-R-027 ** Voice: +41-22-7677918




More information about the ZODB-Dev mailing list