Commit 0a9947c2 authored by 张彦钊's avatar 张彦钊

add multi process predict

parent df7a805c
......@@ -89,6 +89,18 @@ def router(device_id):
predict(user_profile)
# 多进程预测
def multi_predict(predict_list,processes=8):
pool = Pool(processes)
for device_id in predict_list:
start = time.time()
pool.apply_async(router, (device_id,))
end = time.time()
print("该用户{}预测耗时{}秒".format(device_id, (end - start)))
pool.close()
pool.join()
if __name__ == "__main__":
# TODO 如果耗时小于一分钟,下一次取到的device_id和上一次相同
while True:
......@@ -100,14 +112,29 @@ if __name__ == "__main__":
time.sleep(58)
else:
old_device_id_list = pd.read_csv(DIRECTORY_PATH + "data_set_device_id.csv")["device_id"].values.tolist()
for device_id in device_id_list:
if device_id in old_device_id_list:
start = time.time()
router(device_id)
end = time.time()
print("该用户预测耗时{}秒".format(end - start))
else:
print("该用户不是老用户,不能预测")
predict_list = list(set(device_id_list) & set(old_device_id_list))
multi_predict(predict_list)
# while True:
# empty,device_id_list = get_active_users()
# if empty:
# for eachFile in os.listdir("/tmp"):
# if "xlearn" in eachFile:
# os.remove("/tmp" + "/" + eachFile)
# time.sleep(58)
# else:
# old_device_id_list = pd.read_csv(DIRECTORY_PATH + "data_set_device_id.csv")["device_id"].values.tolist()
# for device_id in device_id_list:
# if device_id in old_device_id_list:
# start = time.time()
# router(device_id)
# end = time.time()
# print("该用户预测耗时{}秒".format(end - start))
# else:
# print("该用户不是老用户,不能预测")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment