当只有~50个实体存在时,GAE Python NDB查询获取响应时间> 55秒

时间:2014-03-10 15:29:54

标签: sql google-app-engine python-2.7 app-engine-ndb

我们有一个旅游搜索网站。为了搜索总线,我们对总线操作员实体执行查询。我们使用GAE Python NDB。当仅存在~50个实体时,查询获取响应时间> 55秒(在部署版本而不是开发服务器上)。

目前我的查询包含五个项目。如果我增加到五个以上,响应会进一步减慢。请建议将查询时间缩短到~1或2秒或尽可能少的方法 请在下面找到相关详细信息(抱歉,我试图在一定程度上尽量减少以下内容):

查询代码:

start_time = datetime.datetime.now() 
qry_1 = X.query(ndb.AND(X.active_status=="active", X.property_3==input_3, X.property_4==input_4, X.property_5==input_5, X.property_6.IN(input_6_list), X.property_20.IN(input_20_list))) 
record_list = qry_1.fetch() 
query_end_time = datetime.datetime.now() 
query_execution_time = query_end_time - start_time 
logging.info ("query_execution_time=["+str(query_execution_time)+"] ") 

# input_6_list contains ~5 string items 
# input_20_list contains ~5 string items 

日志输出:

query_execution_time=[0:00:55.925250]  

实体模型:

class X(ndb.Model): 
    active_status = ndb.StringProperty() 
    name = ndb.StringProperty() 
    property_1 = ndb.StringProperty() 
    property_2 = ndb.TextProperty() 
    property_3 = ndb.StringProperty() 
    property_4 = ndb.StringProperty() 
    property_5 = ndb.StringProperty() 
    property_6 = ndb.StringProperty() 
    property_7 = ndb.StringProperty() 
    property_8 = ndb.StringProperty() 
    property_9 = ndb.StringProperty(repeated=True) 
    property_10 = ndb.StringProperty(repeated=True) 
    property_11 = ndb.StringProperty() 
    property_12 = ndb.StructuredProperty(P) 
    property_13 = ndb.StructuredProperty(Q) 
    property_14 = ndb.StringProperty() 
    property_15 = ndb.StructuredProperty(R, repeated=True) 
    property_16 = ndb.StructuredProperty(S, repeated=True) 
    property_17 = ndb.StringProperty() 
    property_18 = ndb.StringProperty(repeated=True) 
    property_19 = ndb.StringProperty() 
    property_20 = ndb.StringProperty(repeated=True) 
    property_21 = ndb.StringProperty(repeated=True) 
    property_22 = ndb.StructuredProperty(T, repeated=True) 
    property_23 = ndb.IntegerProperty(default=6) 
    property_24 = ndb.IntegerProperty(default=6) 
    property_25 = ndb.IntegerProperty(default=6) 
    property_26 = ndb.IntegerProperty(default=6) 
    property_27 = ndb.IntegerProperty(default=6) 
    property_28 = ndb.IntegerProperty(default=0) 
    property_29 = ndb.IntegerProperty() 
    date_added = ndb.DateTimeProperty(auto_now_add=True) #creation date 
    date_modified = ndb.DateTimeProperty(auto_now=True) #update date 
    property_30 = ndb.TextProperty() 
    property_31 = ndb.BlobKeyProperty() 
    property_32 = ndb.BlobKeyProperty() 
    property_33 = ndb.BlobKeyProperty() 
    property_34 = ndb.BlobKeyProperty() 
    property_35 = ndb.BlobKeyProperty() 
    property_36 = ndb.BlobKeyProperty() 
    property_37 = ndb.BlobKeyProperty() 
    property_38 = ndb.StringProperty() 
    property_39 = ndb.BlobKeyProperty() 
    property_40 = ndb.StringProperty(default="not_allowed")  

在调试此问题时,我运行了Appstats,并且我在SO

上询问了another question

1 个答案:

答案 0 :(得分:2)

过滤其他属性通常并不昂贵。但是使用' IN'是。 2 IN过滤器包含5个项目的列表,每个过滤器需要25x并发搜索。

您可以从代码目录中发布index.yaml文件吗?如果此文件不存在,则查询将需要多个JOIN,这将解释缓慢。对dev_appserver运行相同的查询,它将自动生成文件。

更多信息:https://developers.google.com/appengine/docs/python/config/indexconfig

顺便说一句,使用' indexed = False'对于您不打算搜索的属性,将大大降低成本。