diff --git a/comfy/cli_args.py b/comfy/cli_args.py index 2f30b72d2..ffb15becf 100644 --- a/comfy/cli_args.py +++ b/comfy/cli_args.py @@ -205,6 +205,8 @@ parser.add_argument("--user-directory", type=is_valid_directory, default=None, h parser.add_argument("--enable-compress-response-body", action="store_true", help="Enable compressing response body.") +parser.add_argument("--num-workers", type=int, default=1, help="Set the number of worker threads to process the queue (default: 1). Increase this for better concurrency but be aware of GPU memory limitations.") + parser.add_argument( "--comfy-api-base", type=str, diff --git a/main.py b/main.py index e1b0f1620..a02e8c5a4 100644 --- a/main.py +++ b/main.py @@ -336,7 +336,10 @@ def start_comfyui(asyncio_loop=None): prompt_server.add_routes() hijack_progress(prompt_server) - threading.Thread(target=prompt_worker, daemon=True, args=(prompt_server.prompt_queue, prompt_server,)).start() + num_workers = max(1, args.num_workers) + logging.info(f"Starting {num_workers} worker thread(s) for queue processing") + for i in range(num_workers): + threading.Thread(target=prompt_worker, daemon=True, args=(prompt_server.prompt_queue, prompt_server,), name=f"PromptWorker-{i+1}").start() if args.quick_test_for_ci: exit(0)