Datastore performance, my code or the datastore latency

Posted by fredrik on Stack Overflow See other posts from Stack Overflow or by fredrik
Published on 2010-06-08T09:03:43Z Indexed on 2010/06/08 12:32 UTC
Read the original article Hit count: 383

I had for the last month a bit of a problem with a quite basic datastore query. It involves 2 db.Models with one referring to the other with a db.ReferenceProperty.

The problem is that according to the admin logs the request takes about 2-4 seconds to complete. I strip it down to a bare form and a list to display the results. The put works fine, but the get accumulates (in my opinion) way to much cpu time.

#The get look like this: 
outputData['items'] = {} 
labelsData = Label.all() 
for label in labelsData: 
        labelItem = label.item.name 
        if labelItem not in outputData['items']: 
                outputData['items'][labelItem] = { 'item' : labelItem, 'labels' : [] } 
        outputData['items'][labelItem]['labels'].append(label.text) 
path = os.path.join(os.path.dirname(__file__), 'index.html') 
self.response.out.write(template.render(path, outputData)) 
#And the models: 
class Item(db.Model): 
        name = db.StringProperty() 
class Label(db.Model): 
        text = db.StringProperty() 
        lang = db.StringProperty() 
        item = db.ReferenceProperty(Item) 

I've tried to make it a number of different way ie. instead of ReferenceProperty storing all Label keys in the Item Model as a db.ListProperty.

My test data is just 10 rows in Item and 40 in Label.

So my questions: Is it a fools errand to try to optimize this since the high cpu usage is due to the problems with the datastore or have I just screwed up somewhere in the code? ..fredrik

© Stack Overflow or respective owner

Related posts about python

Related posts about google-app-engine