app engine ndb fetch is very slow

436 views Asked by At

I need to store a lot of ModelA entities, and because app engine pricing is based on the number of entities written/read, I bundle together 100 entities and store them as one ModelB.

class ModelA(ndb.Expando):
  a1 ... a20 = ndb.IntegerProperty()

class ModelB(ndb.Model):
  data = ndb.StructuredProperty(ModelA, repeated=True)

I have only 80 such ModelB entities in my datastore, that should use around 1-2MB of memory, yet ModelB.query().fetch() takes 5 seconds. Is there any way to make this faster? Would using LocalStructuredProperty instead of StructuredProperty be better?

1

There are 1 answers

1
Brent Washburne On BEST ANSWER

If you don't need to index the values (for queries), you might want to store them as an opaque object:

class ModelB(ndb.Model):
    data = ndb.JsonProperty(indexed=False)

    def add_data(self, model_a)
        if not self.data:
            self.data = []
        self.data.append(model_a)

This will avoid the overhead of handling structured properties and validation.