操作系统:MacOSBigSur11.1 python:3.8.5
这是我提交线程的地方。请注意,线程过程是一个回调函数
def esGetAlertByKQLAndCallBack(self, kql, size, callback):
res = self.es.search(index=ES_INDEX, q=kql, size=size, filter_path=['hits.hits._index', 'hits.hits._source.alert.signature_id', 'hits.hits._source.payload'], request_timeout=60)
task = THREAD_POOL.submit(callback, res['hits']['hits'])
return task
然后我将returntask对象放入一个列表中
task_list = []
for perSid in all_sigid:
task_list.append(alertSearcher.getAlertBySigAndCallBack(perSid, MAX_SIZE, underreport_callback)
然后我等待任务完成并得到它的返回
for perTask in futures.as_completed(task_list):
total_time += 1
task_res = perTask.result()
if task_res:
lock.acquire()
aType = task_res.split('-')[0]
sid = task_res.split('-')[1]
if aType == 'have':
have_list.append(sid)
elif aType == 'lack':
lack_list.append(sid)
elif aType == 'common':
common_list.append(sid)
lock.release()
这是我的回调函数:
def underreport_callback(res_list):
sid = res_list[0]['_source']['alert']['signature_id']
size = len(res_list)
fromwhere = res_list[0]['_index']
tres_list = tqdm(res_list)
for perAlert in tres_list:
if 'payload' not in perAlert['_source']:
continue
payload = perAlert['_source']['payload']
count = esOperator.esGetNumByKQL(f'payload : "{payload}" AND -_index : "{fromwhere}"')
if count > 0:
logger.error(sid)
return 'common-' + str(sid)
if size <= 10000 and 'dx' in fromwhere:
logger.cyan(sid)
return 'lack-' + str(sid)
elif size <= 10000 and 'aisa' in fromwhere:
logger.info(sid)
return 'have-' + str(sid)
一开始,程序运行良好。但是当它执行最后10个线程时,它会变得非常慢。我不知道怎么了
目前没有回答
相关问题 更多 >
编程相关推荐