简体   繁体   English

Google App Engine NDB查询和超出的内存

[英]Google App Engine NDB Queries and exceeding memory

I have a Google App Engine datastore kind called "Obj" and it has close to 500K entities in production. 我有一个名为“ Obj”的Google App Engine数据存储,其生产中的实体接近50万。 I'm trying to query just 50 Obj entities, but even though I'm setting the limit argument to 50, the query eventually throws the error "Exceeded soft private memory limit". 我正在尝试仅查询50个Obj实体,但是即使将limit参数设置为50,查询最终仍会引发错误“超出软私有内存限制”。

Would this have something to do with the use of ndb.GenericProperty in the query? 这是否与查询中使用ndb.GenericProperty有关? The attribute "trashed_date", which is a datetime type, is not normally an attribute of Obj. 属性“ trashed_date”是日期时间类型,通常不是Obj的属性。 I've also manually created the correct index for status and trashed_date. 我还手动为status和rashed_date创建了正确的索引。 Should "trashed_date" always be a property of that model? 应该“ trashed_date”始终是该模型的属性吗?

Below is the code I'm using, what can I do so when querying just 50 entities it doesn't exceed the memory limit? 以下是我正在使用的代码,仅查询50个不超过内存限制的实体时该怎么办?

q = Obj.query(
    Obj.status == 1,
    ndb.GenericProperty('trashed_date') < expire_date
)
results = q.fetch(50)

Please try this using q.iter() and a counter to limit it to 50. I had a similar problem with fetch() and fixed it using iter(). 请尝试使用q.iter()和一个计数器将其限制为50。我对fetch()有类似的问题,并使用iter()进行了修复。 GAE is pretty strongly advising against fetch now. GAE强烈建议您不要立即获取。 YMMV. YMMV。 HTH. HTH。 -stevep -stevep

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM