* feat(collector): compressed worker -> master result transfer Workers sent every frame as an uncompressed PNG (compress_level=0), base64-encoded inside a JSON request, one request per frame. For cloud workers this makes result download (egress) the dominant transfer cost: a 121-frame 720p batch is ~446 MB per worker. Add `transfer_format` / `transfer_quality` optional widgets to Distributed Collector: - legacy_png (default): unchanged behaviour - png, ffv1: lossless, bit-identical master tensors to legacy_png - jpeg, webp: lossy stills - h264, h265, av1: lossy video of the whole batch Compressed results are posted as multipart/form-data chunks (binary, no base64, ~32 MB soft cap per request, configurable with COMFYUI_DISTRIBUTED_TRANSFER_CHUNK_BYTES). The master decodes each chunk off the event loop and enqueues one item per frame, so collection, ordering and audio handling are unchanged. Encoding also runs in an executor on the worker. Compatibility: - /distributed/job_complete still accepts the legacy JSON envelope. - A worker talking to an older master gets a 400 on the first chunk and resends everything as legacy_png. - Missing video encoders fall back to h264 (lossy) or png (ffv1). Measured on 121 frames at 1280x720: png 163 MB (2.7x), ffv1 128 MB (3.5x), h264 q90 2.4 MB (186x, 40.2 dB), av1 q90 0.4 MB. Also clips IMAGE values before 8-bit quantization on the new path so out-of-range values no longer wrap around. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0166t8T3CVaxZkJbP2RtSpo6 * fix(collector): wire transfer options through V3 node; bound finalized payload size Addresses review on #97. V3 integration - Add optional `transfer_format` / `transfer_quality` inputs to the registered nodes/v3.py DistributedCollector schema (legacy defaults) and accept/forward them in execute() to the runtime helper. - tests/test_v3_collector_transfer.py checks the registered node's public schema and argument forwarding without a ComfyUI checkout; the opt-in real-runtime acceptance (tests/helpers/v3_runtime_check.py) now allows exactly these appended optional inputs, verifies their contract, and checks forwarding through the real executor. Payload size bound - encode_chunks() enforces limits on finalized bytes (after encoder flush and muxer finalization). Encoder lookahead kept the pre-flush buffer near zero, so a chunk could hold the whole batch and finalize far above the limit. Oversized video chunks are re-encoded with proportionally fewer frames; the next chunk is sized from observed bytes/frame. - Multi-frame chunks stay within TRANSFER_MAX_CHUNK_BYTES (32 MiB); a single frame may use up to TRANSFER_MAX_REQUEST_BYTES (96 MiB, new, COMFYUI_DISTRIBUTED_TRANSFER_MAX_REQUEST_BYTES) minus envelope reserve. A frame that cannot fit raises FrameTooLargeError. - The worker encodes all chunks before sending, so an unfittable frame fails before anything is delivered (no partial batch on the master). - Audio rides on the last chunk only when the request stays in bounds; otherwise it is sent as a final audio-only completion. - Legacy fallback triggers only on an older master's rejection ("Invalid JSON payload"); other errors, e.g. size limits, raise with a pointer to the limit settings instead of resending as legacy_png. - The master returns 413 when a request exceeds --max-upload-size. Tests: codec flush-overshoot and single-frame cases, worker fallback / nothing-sent / audio placement, and real aiohttp server tests with client_max_size covering bounded high-entropy video, 413 reporting, and unfittable frames. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0166t8T3CVaxZkJbP2RtSpo6 --------- Co-authored-by: ymiyad <ymiyad@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
80 lines
2.5 KiB
Python
80 lines
2.5 KiB
Python
"""
|
|
Shared constants for ComfyUI-Distributed.
|
|
"""
|
|
import os
|
|
|
|
# Timeouts (in seconds)
|
|
WORKER_JOB_TIMEOUT = 30.0
|
|
TILE_COLLECTION_TIMEOUT = 30.0
|
|
TILE_WAIT_TIMEOUT = 30.0
|
|
PROCESS_TERMINATION_TIMEOUT = 5.0
|
|
|
|
# Process monitoring
|
|
WORKER_CHECK_INTERVAL = 2.0
|
|
STATUS_CHECK_INTERVAL = 5.0
|
|
|
|
# Cloudflare tunnel
|
|
TUNNEL_START_TIMEOUT = float(os.environ.get("TUNNEL_START_TIMEOUT", "25"))
|
|
CLOUDFLARE_LOG_BUFFER_SIZE = 200
|
|
|
|
# Network
|
|
CHUNK_SIZE = 8192
|
|
LOG_TAIL_BYTES = 65536 # 64KB
|
|
|
|
# File paths
|
|
WORKER_LOG_PATTERN = "distributed_worker_*.log"
|
|
|
|
# Worker management
|
|
WORKER_STARTUP_DELAY = 2.0
|
|
|
|
# Tile transfer
|
|
TILE_TRANSFER_TIMEOUT = 30.0
|
|
|
|
# Process cleanup
|
|
PROCESS_WAIT_TIMEOUT = 3.0
|
|
QUEUE_INIT_TIMEOUT = 5.0
|
|
TILE_SEND_TIMEOUT = 60.0
|
|
JOB_INIT_GRACE_PERIOD = 10.0
|
|
|
|
# Memory operations
|
|
MEMORY_CLEAR_DELAY = 0.5
|
|
|
|
# Batch processing
|
|
MAX_BATCH = int(os.environ.get('COMFYUI_MAX_BATCH', '20')) # Maximum items per batch to prevent timeouts/OOM (~100MB chunks for 512x512 PNGs)
|
|
|
|
# Compressed worker -> master result transfer (DistributedCollector)
|
|
# Hard cap on one multipart request body. Must not exceed the master's
|
|
# --max-upload-size (ComfyUI default: 100 MiB), which rejects larger requests.
|
|
TRANSFER_MAX_REQUEST_BYTES = int(os.environ.get('COMFYUI_DISTRIBUTED_TRANSFER_MAX_REQUEST_BYTES', str(96 * 1024 * 1024)))
|
|
# Target media bytes per request when batching several frames into one
|
|
# request; a single frame may exceed this up to the hard cap above.
|
|
TRANSFER_MAX_CHUNK_BYTES = min(
|
|
int(os.environ.get('COMFYUI_DISTRIBUTED_TRANSFER_CHUNK_BYTES', str(32 * 1024 * 1024))),
|
|
TRANSFER_MAX_REQUEST_BYTES,
|
|
)
|
|
|
|
# Heartbeat monitoring
|
|
HEARTBEAT_INTERVAL = float(os.environ.get('COMFYUI_HEARTBEAT_INTERVAL', '10')) # Heartbeat/check interval in seconds
|
|
HEARTBEAT_TIMEOUT = int(os.environ.get('COMFYUI_HEARTBEAT_TIMEOUT', '60')) # Worker heartbeat timeout in seconds (default 60s)
|
|
|
|
# USDU result collection
|
|
DYNAMIC_MODE_MAX_POLL_TIMEOUT = 10.0
|
|
|
|
# Static mode job poll loop
|
|
JOB_POLL_INTERVAL = 1.0
|
|
JOB_POLL_MAX_ATTEMPTS = 20
|
|
|
|
# Orchestration pipeline
|
|
ORCHESTRATION_WORKER_PROBE_CONCURRENCY = int(
|
|
os.environ.get('COMFYUI_ORCHESTRATION_WORKER_PROBE_CONCURRENCY', '8')
|
|
)
|
|
ORCHESTRATION_WORKER_PREP_CONCURRENCY = int(
|
|
os.environ.get('COMFYUI_ORCHESTRATION_WORKER_PREP_CONCURRENCY', '4')
|
|
)
|
|
ORCHESTRATION_MEDIA_SYNC_CONCURRENCY = int(
|
|
os.environ.get('COMFYUI_ORCHESTRATION_MEDIA_SYNC_CONCURRENCY', '2')
|
|
)
|
|
ORCHESTRATION_MEDIA_SYNC_TIMEOUT = float(
|
|
os.environ.get('COMFYUI_ORCHESTRATION_MEDIA_SYNC_TIMEOUT', '120')
|
|
)
|