Skip to content

garysng/comfyless

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

ComfyLess - ComfyUI Serverless Platform

ComfyLess is a ComfyUI serverless platform developed in Go, providing task queue management and automatic worker scaling capabilities.

Features

  • πŸš€ Component-based Design: Queue management and worker management use interface design for pluggable replacement
  • ☁️ Multi-cloud Support: Supports Docker local deployment and Novita AI cloud GPU instances
  • πŸ“¦ Docker Containerization: Uses Docker to manage ComfyUI worker instances
  • πŸ”„ Auto-scaling: Automatically scales worker count based on task load
  • πŸ’Ύ Task Queue: Redis-based task queue
  • 🎯 Standard API: Compatible with ComfyUI standard API interface
  • πŸ“Š Monitoring Metrics: Provides detailed queue and worker metrics monitoring
  • πŸ”§ Health Checks: Automatic worker health status monitoring

Worker Providers

ComfyLess supports multiple worker providers:

🐳 Docker Provider (Default)

  • Uses local Docker to manage worker instances
  • Suitable for development environments and small-scale deployments
  • Requires Docker environment

☁️ Novita AI Provider

Quick Start

Prerequisites

  • Go 1.21+
  • Redis
  • Docker (if using Docker Provider)
  • Novita AI account (if using Novita Provider)

Install Dependencies

go mod download

Using Docker Provider

# Option 1: Use quick start configuration
cp deploy/quickstart.env .env
source .env

# Build and run
go build -o comfyless ./cmd/main.go
./comfyless

# Option 2: Manual configuration
export REDIS_HOST=localhost
export REDIS_PORT=6379
export WORKER_IMAGE=novitalabs/comfyui:flux1-dev-fp8v5
export MAX_WORKERS=10
export MIN_WORKERS=1

go run ./cmd/main.go

Using Novita AI Provider

# Use environment configuration
cp deploy/env.example .env
# Edit .env file with your Novita credentials
vim .env

# Or set environment variables directly
export NOVITA_API_KEY="your-api-key"
export NOVITA_PRODUCT_ID="your-product-id"
export REDIS_HOST=localhost
export REDIS_PORT=6379

# Build and run
go build -o comfyless ./cmd/main.go
./comfyless

Using Docker Compose

# Quick start with Docker Compose
cd deploy/
cp env.example .env
# Edit .env with your configuration
docker-compose up -d

For detailed configuration, please refer to the Novita Provider Documentation and Deployment Documentation.

API Interface

Submit Task

curl -X POST http://localhost:8080/api/v1/tasks \
  -H "Content-Type: application/json" \
  -d '{
  "workflow_id": "text_to_image_v1",
  "priority": 5,
  "payload": {
    "3": {
      "class_type": "KSampler",
      "inputs": {
        "cfg": 8,
        "denoise": 1,
        "latent_image": [
          "5",
          0
        ],
        "model": [
          "4",
          0
        ],
        "negative": [
          "7",
          0
        ],
        "positive": [
          "6",
          0
        ],
        "sampler_name": "euler",
        "scheduler": "normal",
        "seed": 46588125086418,
        "steps": 20
      }
    },
    "4": {
      "class_type": "CheckpointLoaderSimple",
      "inputs": {
        "ckpt_name": "flux1-dev-fp8.safetensors"
      }
    },
    "5": {
      "class_type": "EmptyLatentImage",
      "inputs": {
        "batch_size": 1,
        "height": 512,
        "width": 512
      }
    },
    "6": {
      "class_type": "CLIPTextEncode",
      "inputs": {
        "clip": [
          "4",
          1
        ],
        "text": "beautiful scenery nature glass bottle landscape, , purple galaxy bottle,"
      }
    },
    "7": {
      "class_type": "CLIPTextEncode",
      "inputs": {
        "clip": [
          "4",
          1
        ],
        "text": "text, watermark"
      }
    },
    "8": {
      "class_type": "VAEDecode",
      "inputs": {
        "samples": [
          "3",
          0
        ],
        "vae": [
          "4",
          2
        ]
      }
    },
    "9": {
      "class_type": "SaveImage",
      "inputs": {
        "filename_prefix": "ComfyUI",
        "images": [
          "8",
          0
        ]
      }
    }
  }
}'

Query Task Status

curl http://localhost:8080/api/v1/tasks/{task_id}

View Worker Status

# Get worker metrics
curl http://localhost:8080/api/v1/workers/metrics

# List all workers
curl http://localhost:8080/api/v1/workers

# Novita Provider specific status interface
curl http://localhost:8080/novita/status

Component Architecture

Both queue manager and worker manager are designed as interfaces that can be replaced as needed.

Queue Manager Interface

type QueueManager interface {
    Start(ctx context.Context) error
    AddTask(task *queue.Task) error
    GetNextTask() (*queue.Task, error)
    UpdateTask(task *queue.Task) error
}

Worker Manager Interface

type WorkerManager interface {
    Start(ctx context.Context) error
    GetAvailableWorker() (*interfaces.Worker, error)
    CreateWorker() (*interfaces.Worker, error)
    TerminateWorker(workerID string) error
    GetWorkerMetrics() *interfaces.WorkerMetrics
}

Architecture Overview

ComfyLess follows a modular architecture with clear separation of concerns:

  • API Layer (internal/api/): Handles HTTP requests and responses
  • Queue Management (internal/queue/): Redis-based task queue with priority support
  • Worker Management (internal/worker/): Pluggable worker providers (Docker, Novita AI)
  • Task Dispatcher (internal/dispatcher/): Orchestrates task assignment and monitoring
  • ComfyUI Client (internal/comfyui/): Communicates with ComfyUI instances
  • Configuration (internal/config/): Environment-based configuration management

Project Structure

comfyless/
β”œβ”€β”€ cmd/
β”‚   └── main.go                    # Main program entry point
β”œβ”€β”€ internal/                      # Internal application code
β”‚   β”œβ”€β”€ api/                       # HTTP API layer
β”‚   β”‚   β”œβ”€β”€ handler.go             # API request handlers
β”‚   β”‚   └── types.go               # API request/response types
β”‚   β”œβ”€β”€ queue/                     # Task queue management
β”‚   β”‚   β”œβ”€β”€ manager.go             # Queue manager implementation
β”‚   β”‚   └── types.go               # Queue data types
β”‚   β”œβ”€β”€ worker/                    # Worker management
β”‚   β”‚   β”œβ”€β”€ docker_manager.go      # Docker provider implementation
β”‚   β”‚   β”œβ”€β”€ novita_manager.go      # Novita AI provider implementation
β”‚   β”‚   β”œβ”€β”€ factory.go             # Worker factory
β”‚   β”‚   └── persistence.go         # Worker state persistence
β”‚   β”œβ”€β”€ dispatcher/                # Task dispatcher
β”‚   β”‚   └── dispatcher.go          # Task dispatch logic
β”‚   β”œβ”€β”€ interfaces/                # Interface definitions
β”‚   β”‚   β”œβ”€β”€ queue.go               # Queue interface
β”‚   β”‚   β”œβ”€β”€ worker.go              # Worker interface
β”‚   β”‚   └── types.go               # Common types
β”‚   β”œβ”€β”€ comfyui/                   # ComfyUI client
β”‚   β”‚   └── client.go              # ComfyUI API client
β”‚   └── config/                    # Configuration management
β”‚       └── config.go              # Configuration loading
β”œβ”€β”€ deploy/                        # Deployment configurations
β”‚   β”œβ”€β”€ Dockerfile                 # Docker image build file
β”‚   β”œβ”€β”€ docker-compose.yml         # Docker Compose configuration
β”‚   β”œβ”€β”€ config.json                # JSON configuration example
β”‚   β”œβ”€β”€ env.example                # Environment variables template
β”‚   β”œβ”€β”€ quickstart.env             # Quick start configuration
β”‚   β”œβ”€β”€ development.env            # Development environment config
β”‚   β”œβ”€β”€ production.env             # Production environment config
β”‚   └── README.md                  # Deployment documentation
β”œβ”€β”€ docs/                          # Documentation
β”‚   β”œβ”€β”€ openapi.yaml               # OpenAPI specification (YAML)
β”‚   β”œβ”€β”€ openapi.json               # OpenAPI specification (JSON)
β”‚   β”œβ”€β”€ API.md                     # API documentation
β”‚   β”œβ”€β”€ TASK_DISPATCH_FLOW.md      # Task dispatch flow documentation
β”‚   β”œβ”€β”€ COMPLETE_WORKFLOW.md       # Complete workflow documentation
β”‚   └── NOVITA_PROVIDER.md         # Novita AI provider documentation
β”œβ”€β”€ examples/                      # Example files
β”‚   └── create_task.json           # Task creation example
β”œβ”€β”€ go.mod                         # Go module definition
β”œβ”€β”€ go.sum                         # Go module checksums
β”œβ”€β”€ LICENSE                        # License
β”œβ”€β”€ .gitignore                     # Git ignore rules
└── README.md                      # Project documentation

Documentation

Comprehensive documentation is available in the docs/ directory:

For deployment and configuration:

License

This project is licensed under the Apache 2.0 License.

About

Support AutoScaling comfyui serverless

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published