From f1d1fb78cf5be7822c71046be8a7d7d1776754ff Mon Sep 17 00:00:00 2001 From: Neo Date: Wed, 12 Nov 2025 21:38:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81Concurrent-8=20by=E7=B1=B3?= =?UTF-8?q?=E5=BC=BA=E6=BB=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- comfy/cli_args.py | 2 ++ main.py | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) 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)