On Jun 8, 2010, at 3:58 PM, Fredrik Bonander wrote:
> 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
Doing this would perform a fetch for item for every label, which is expensive.
> if labelItem not in outputData['items']:
> outputData['items'][labelItem] = { 'item' : labelItem, 'labels'
> : [] }
> outputData['items'][labelItem]['labels'].append(label.text)
Why not perform a GQL query here instead?
[snip]
>
> My test data is just 10 rows in Item and 40 in Label.
That would mean that at least 40 * 10 queries are run, which means about 400
queries.
>
> 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?
More of the latter. You're doing a fetch for every model in the list. See above.
To see what's going on under the covers, why not use appstats?
https://sites.google.com/site/appengineappstats/
Jan Michael Ibanez
[email protected]
--
You received this message because you are subscribed to the Google Groups
"Google App Engine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine?hl=en.