当只有〜50个实体存在时,GAE Python NDB查询获取响应时间> 55秒 [英] GAE Python NDB query fetch response time >55 seconds when only ~50 entities are present

查看:150
本文介绍了当只有〜50个实体存在时,GAE Python NDB查询获取响应时间> 55秒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个旅游搜索网站。为了搜索公交车,我们对公交运营商实体执行查询。我们使用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包含〜5个字符串项目
#input_20_list包含〜5个字符串项目

输出日志:

  query_execution_time = [0:00:55.925250] 

实体模型:

 类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(重复= True)
property_10 = ndb.StringProperty(重复= 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(重复= True)
property_21 = ndb.StringProperty(重复= True)
property_22 = ndb.StructuredProperty(T,repeated = True )
property_23 = ndb.IntegerProperty(default = 6)
property_24 = ndb.IntegerProperty(default = 6)
property_25 = ndb.InteProProperty(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 = n db.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并且有另一个问题, / p>

解决方案

过滤其他属性通常不昂贵。但使用'IN'是。 2个IN过滤器,每个过滤器列表中有5个项目,每个过滤器需要在后端进行25次并发访问。

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



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



<顺便说一下,在你不打算搜索的属性上使用'indexed = False'将大大降低成本投入。


We have a travel search website. To search for a bus, we execute a query on the bus operator entities. We use GAE Python NDB. The query fetch response time >55 seconds(on deployed version and not development server) when only ~50 entities are present.

Presently my query contains five items. If I increase to more than five, the response slows further considerably. Please suggest ways to bring down the query time to ~1 or 2 seconds or as less as possible.
Please find the relevant details below(sorry i tried to minimize the below content to some extent):

Query code:

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 

Output in Logs:

query_execution_time=[0:00:55.925250]  

Entity Model:

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")  

While debugging this issue, I ran Appstats and had another question which I asked on SO

解决方案

Filtering on additional properties is not usually expensive. But using 'IN' is. 2 IN filters with lists of 5 items each requires 25x concurrent seeks on the backend.

Could you post the index.yaml file from your code directory? If this file does not exist, the query would require multiple JOINs, which would explain the slowness. Run the same query against the dev_appserver and it will generate the file automatically.

More here: https://developers.google.com/appengine/docs/python/config/indexconfig

By the way, using 'indexed=False' on the properties you don't intend to search on will reduce the cost puts considerably.

这篇关于当只有〜50个实体存在时,GAE Python NDB查询获取响应时间> 55秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆