提交 b2546e88 作者: 薛凌堃

使用多线程补采公告

上级 04deaad2
""" """
...@@ -258,6 +258,7 @@ def main(page,p,esMethod): ...@@ -258,6 +258,7 @@ def main(page,p,esMethod):
# print(msglist) # print(msglist)
num = 0 num = 0
for mms in msglist: for mms in msglist:
start_time = time.time()
id = mms['_id'] id = mms['_id']
title = mms['_source']['title'] title = mms['_source']['title']
sourceAddress = mms['_source']['sourceAddress'] sourceAddress = mms['_source']['sourceAddress']
...@@ -269,6 +270,9 @@ def main(page,p,esMethod): ...@@ -269,6 +270,9 @@ def main(page,p,esMethod):
att_id = upload(sourceAddress,num,title,social_code,year,publishDate,createDate) att_id = upload(sourceAddress,num,title,social_code,year,publishDate,createDate)
u_attid = att_id u_attid = att_id
esMethod.updateaunn(esMethod.index_name, str(id), u_attid) esMethod.updateaunn(esMethod.index_name, str(id), u_attid)
end_time = time.time()
elapsed_time = end_time - start_time
log.info(f'******更新一条数据耗时{elapsed_time}秒******')
def run_threads(num_threads,esMethod): def run_threads(num_threads,esMethod):
threads = [] threads = []
...@@ -283,16 +287,18 @@ def run_threads(num_threads,esMethod): ...@@ -283,16 +287,18 @@ def run_threads(num_threads,esMethod):
thread.join() thread.join()
if __name__ == '__main__': if __name__ == '__main__':
while True: # while True:
esMethod = EsMethod() esMethod = EsMethod()
p = 0 # p = 0
result = esMethod.queryatt(index_name=esMethod.index_name, pnum=p) # result = esMethod.queryatt(index_name=esMethod.index_name, pnum=p)
total = result['hits']['total']['value'] # total = result['hits']['total']['value']
if total == 0: # if total == 0:
log.info('++++已没有数据+++++') # log.info('++++已没有数据+++++')
break # break
start = time.time()
num_threads = 5 num_threads = 5
run_threads(num_threads,esMethod) run_threads(num_threads,esMethod)
log.info(f'5线程 每个处理200条数据 总耗时{time.time()-start}秒')
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论