def worker(listen):
with Connection(redis_conn):
worker = Worker(map(Queue, listen))
worker.work()
def run ():
listen = ['high', 'scheduler']
try:
cpu_num = 2
p = Pool(cpu_num)
for i in range(cpu_num):
p.apply_async(worker, args=(listen,)) # 开启 worker
p.close()
p.join()
except Exception as e:
print(e)
主机为 1CPU,4 核
运行程序后,加入队列的任务有点多(500 多个),在前台看了下处于正在处理的任务有 16 个,这是怎么计算出来的啊?生产环境中用 gunicorn 部署的,fastapi 框架,gunicorn workers 为 4,threads 为 5
1
deplivesb 2021-12-07 16:32:45 +08:00
gunicorn workers * cpu_core
|