开发者

Improve fetch time and this function's performance

I am searching the Final model (defined below) with a query which filters on its name property. This query is taking about 2200ms to execute on the development server. How can I speed it up? Here is an AppStats screenshot.

I was filtering on the created field too, but this was taking in excess of 10000ms so I've removed that part of the query for now.

class Final(db.Model):
    name = db.StringProperty()     # 7 characters long
    author = db.StringProperty()
    rating = db.FloatProperty()
    creat开发者_如何学编程ed = db.DateTimeProperty()

# this is the important part of the request (AppStats shows that these two
# queries take about 2200ms each).

 query = Final.all()
 query2 = Final.all()
 query.filter('name = ', link1)
 query2.filter('name = ', link2)
 aa = query.fetch(10000)
 bb = query2.fetch(10000)


While David's suggestions are good ones, optimizing for speed on the development server is probably a bad idea. The development server's performance does not reflect that of the production server, and optimizations based on development server runtime may not fare well in production.

In general, you can assume that the performance of the development server will decrease as records are added, whilst this is definitely not the case in production, where your query runtime depends only on the size of the result set. If you can reduce the size of your sample dataset in production, that may be your best option for speeding development up.


A few ways you might be able to speed up this query:

  1. Use the SQLite backend for the development server (it might be faster).

  2. Can you store integer IDs instead of string IDs for name? This might make the entities smaller and thus take less time to transfer and deserialize them. It is also easier to check integer equality than string equality so the filter operation might be faster for the datastore to perform.

  3. If name is large, you could potentially save some time by moving the author name and rating into a separate child model. Then you could use an ancestor query to fetch the relevant child models - thus you will save transfer and deserialization time by only only fetching the fields you need.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜