【发布时间】:2017-04-17 18:27:55
【问题描述】:
我目前有一个在 appengine 上运行的应用程序,我正在使用延迟库执行一些作业,其中一些任务每天运行,而其中一些任务每月执行一次。这些任务中的大多数查询 Datastore 以检索文档,然后将实体存储在索引中(搜索 API)。其中一些表每月更换一次,我必须在所有实体(4~5M)上运行这些任务。
此类任务的一个示例是:
def addCompaniesToIndex(cursor=None, n_entities=0, mindate=None):
#get index
BATCH_SIZE = 200
cps, next_cursor, more = Company.query().\
fetch_page(BATCH_SIZE,
start_cursor=cursor)
doc_list = []
for i in range(0, len(cps)):
cp = cps[i]
#create a Index Document using the Datastore entity
#this document has only about 5 text fields and one date field
cp_doc = getCompanyDocument(cp)
doc_list.append(cp_doc)
index = search.Index(name='Company')
index.put(doc_list)
n_entities += len(doc_list)
if more:
logging.debug('Company: %d added to index', n_entities)
#to_put[:] = []
doc_list[:] = []
deferred.defer(addCompaniesToIndex,
cursor=next_cursor,
n_entities=n_entities,
mindate=mindate)
else:
logging.debug('Finished Company index creation (%d processed)', n_entities)
当我只运行一项任务时,每个延迟任务的执行大约需要 4-5 秒,因此索引我的 500 万个实体大约需要 35 小时。
另一件事是,当我使用同一队列上的不同延迟任务对另一个索引(例如,每日更新之一)运行更新时,两者的执行速度都会慢很多。并且每次延迟通话开始花费大约 10-15 秒,这简直难以忍受。
我的问题是:有没有办法更快地做到这一点并将推送队列扩展到每次运行的多个作业?或者我应该使用不同的方法来解决这个问题?
提前致谢,
【问题讨论】:
标签: python google-app-engine app-engine-ndb task-queue