开发者

Workaround to saving a model with many properties without using too much CPU time?

I have a model with a lot of properties and when I try to write it I get a warning on the logs that the request is taking too much CPU times (over 1000cpu_ms and over 8000api_cpu_ms).

The following test program demonstrates the issue:

class TestModel(db.Model): 
    user = db.UserProperty() 
    p1 = db.StringProperty() 
    p2 = db.StringProperty() 
    p3 开发者_JS百科= db.StringProperty()
    p4 = db.StringProperty()
    p5 = db.StringProperty() # 475cpu_ms with 1..5 only
    p6 = db.StringProperty()
    p7 = db.StringProperty()
    p8 = db.StringProperty()
    p9 = db.StringProperty()
    p10 = db.StringProperty() # 760cpu_ms with 1..10 only
    p11 = db.StringProperty()
    p12 = db.StringProperty()
    p13 = db.ListProperty(unicode)
    p14 = db.ListProperty(int) 
    p15 = db.ListProperty(int)
    p16 = db.BooleanProperty()
    p17 = db.DateTimeProperty() #over 1000cpu_ms with all these


class DebugitHandler(webapp.RequestHandler):
    def get(self):
        instance = TestModel()
        instance = instance.put() 
        self.response.out.write("Done.")

All the CPU time is spent on that one .put() call.

Other than splitting the model into more than one (which, probably won't help as I would still have the same number of properties) is there a way to get around this problem? a way to put 1 instance with 20 properties in the datastore without taking over 1 second of CPU time?


As stated in the quota documentation:

As the number of properties associated with a given entity increases, so does the CPU time required to read and write that entity

If you don't need to sort or filter on each of these properties, you could add the indexed = False declaration to some of them; this should save some CPU time..

class TestModel(db.Model): 
    user = db.UserProperty(indexed = False) 
    p1 = db.StringProperty(indexed = False) 
    p2 = db.StringProperty(indexed = False) 
    p3 = db.StringProperty(indexed = False)
    ....
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜