Skip to main content

Overview

Daemon mode allows you to preload AI models into memory and reuse them across multiple images. This eliminates the model loading overhead for each image, providing dramatic performance improvements for batch processing.
Daemon mode is only available for models that use the upscayl binary. Models using realcugan or waifu2x binaries do not support daemon mode.

Performance benefits

The performance improvement from daemon mode is substantial. Here are real benchmarks from processing 10 images (512x512px):

OpenComic AI Upscale Lite

  • Without daemon: 52.087s total (5.2s per image)
  • With daemon: 7.646s total (0.76s per image)
  • Speedup: 6.81x faster

RealESRGAN x4 Plus

  • Without daemon: 73.273s total (7.3s per image)
  • With daemon: 23.199s total (2.3s per image)
  • Speedup: 3.16x faster

Why daemon mode is faster

Without daemon mode, each image requires:
  1. Loading the model weights from disk (~2-5 seconds)
  2. Processing the image (~0.7-2.2 seconds)
  3. Unloading the model
With daemon mode:
  1. Model is loaded once at startup (~0.5-1.2 seconds)
  2. Each image processes immediately (~0.7-2.2 seconds)
  3. Model stays in memory for reuse

Configuration

Daemon mode is enabled by default with sensible defaults:

setConcurrentDaemons

Control how many daemon processes can run simultaneously:
Each daemon consumes GPU memory for the loaded model. The optimal number depends on:
  • GPU VRAM: More VRAM allows more concurrent daemons
  • CPU cores: More cores can handle more concurrent processes
  • Workload: Different models processing simultaneously
For most systems, 3-5 concurrent daemons provides the best balance between performance and resource usage.

setDaemonIdleTimeout

Daemons automatically close after being idle for a specified timeout:
Longer timeouts keep models in memory for future use but consume resources. Shorter timeouts free resources faster but require reloading for new batches.

Preloading models

For maximum performance, preload models before processing your batch:

What preload does

The preload method:
  1. Downloads any missing model files (if needed)
  2. Starts daemon processes for each model
  3. Loads model weights into memory
  4. Returns once all models are ready
Subsequent pipeline calls will immediately use the preloaded daemons.

Closing daemons

Manually close all running daemons to free resources:
Daemons automatically close after the idle timeout, so manual cleanup is optional. However, explicitly closing daemons is useful for long-running applications to free GPU memory immediately.

Batch processing example

Here’s a complete example demonstrating daemon mode for batch processing:

Performance timing example

Compare performance with and without daemon mode:

Daemon lifecycle

Understanding how daemons are managed:
  1. Creation: A daemon is created the first time a model is used (or via preload)
  2. Reuse: Subsequent uses of the same model reuse the existing daemon
  3. Queue: If a daemon is busy, new requests are queued
  4. Concurrency limit: If the number of daemons exceeds concurrentDaemons, the least recently used idle daemon is closed
  5. Idle timeout: Daemons automatically close after being idle for daemonIdleTimeout milliseconds
  6. Manual close: closeAllDaemons() immediately closes all daemons

Best practices

Preload before batch processing

Set appropriate concurrent daemons

Clean up after batch jobs

Next steps