Repository navigation
Stop ComfyUI while it is idle, so it holds no VRAM - #20
Merged
Merged
Conversation
On the 5090 rig ComfyUI kept ~776 MB of the card while idle, although every render already frees its models: what stays is the CUDA context, which no API gives back while the process lives. The card is shared with VoxMin and OmniVoice, so that memory was missing from every job they ran. With COMFYUI_IDLE_STOP_SECONDS set (compose: 120), the entrypoint execs docker/idle_gate.py in place of ComfyUI. The gate owns the port, starts ComfyUI on the first request that needs it (~5 s on the rig) and stops it once its queue has been empty and nothing has asked for that long. It answers the probes that run all day without starting it: the healthcheck's /system_stats and /queue as fixed answers, voxmin-backend's 10 s /api/wrapper/workflows probe from ComfyUI's last answer; /ws is a 503 until something real starts it. Stubs and the cache are only served to a request carrying WRAPPER_AUTH_TOKEN when one is set. Each request gets its own connection to ComfyUI, so the gate sees every one; X-Forwarded-For carries the real client. Unset (RunPod, vast, serverless) or with sequence parallelism, ComfyUI runs as before. The gate is stdlib-only; VoxMin ships the same file. Tested: 20 new tests (the gate against a stand-in server, the entrypoint wiring in test_docker.py); on the rig, the published image with this entrypoint answered probes without starting ComfyUI, freed its VRAM 20 s after the last request, and started again on the next one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem. On the 5090 rig an idle ComfyUI held ~776 MB of VRAM, although every render already frees its models. What stays is the CUDA context, which only goes away when the process exits. The card is shared with VoxMin (7.8 GB idle) and OmniVoice, so that memory was missing from every job they ran (januscaler/VoxMin has the matching change).
Change.
COMFYUI_IDLE_STOP_SECONDSset (compose default:120),docker/entrypoint.shexecsdocker/idle_gate.pyin place of ComfyUI. The gate owns port 8188 and runs ComfyUI onCOMFYUI_PORT+1. It starts ComfyUI on the first request that needs it (~5 s on the rig) and stops it once the queue has been empty and nothing has asked for that long./system_stats(healthcheck) and/queuewith fixed answers;/api/wrapper/workflows(voxmin-backend's 10 s probe) from ComfyUI's last answer;/wswith 503 until something real starts ComfyUI.WRAPPER_AUTH_TOKENis set, those answers go only to requests that carry it; anything else reaches ComfyUI itself.X-Forwarded-Forcarries the real client.Tests.
test_idle_gate.pyruns the real gate against a stand-in server;test_docker.pycovers the entrypoint wiring and validates its flags against the gate's parser.tests-unit/wrapper_api_test: 308 passed. The 3TestGraphValidationfailures also fail on master here (no model files locally).ruff check .is clean.:latestimage ran with this entrypoint and gate mounted./queueand/system_statswere answered with ComfyUI down. The first workflows probe started it (4.8 s) and was cached. ComfyUI exited 20 s later, taking its GPU process with it, and the cached probe did not wake it. A real request started it again (4.8 s), and the Docker healthcheck stayedhealthy.After merge: on the rig,
docker compose pull comfyui && docker compose up -d comfyui.🤖 Generated with Claude Code