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:- Loading the model weights from disk (~2-5 seconds)
- Processing the image (~0.7-2.2 seconds)
- Unloading the model
- Model is loaded once at startup (~0.5-1.2 seconds)
- Each image processes immediately (~0.7-2.2 seconds)
- 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:- GPU VRAM: More VRAM allows more concurrent daemons
- CPU cores: More cores can handle more concurrent processes
- Workload: Different models processing simultaneously
setDaemonIdleTimeout
Daemons automatically close after being idle for a specified timeout:Preloading models
For maximum performance, preload models before processing your batch:What preload does
Thepreload method:
- Downloads any missing model files (if needed)
- Starts daemon processes for each model
- Loads model weights into memory
- Returns once all models are ready
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:- Creation: A daemon is created the first time a model is used (or via
preload) - Reuse: Subsequent uses of the same model reuse the existing daemon
- Queue: If a daemon is busy, new requests are queued
- Concurrency limit: If the number of daemons exceeds
concurrentDaemons, the least recently used idle daemon is closed - Idle timeout: Daemons automatically close after being idle for
daemonIdleTimeoutmilliseconds - Manual close:
closeAllDaemons()immediately closes all daemons
Best practices
Preload before batch processing
Set appropriate concurrent daemons
Clean up after batch jobs
Next steps
- Review pipeline processing to combine multiple models efficiently
- Explore model selection to understand which models support daemon mode
- Check basic usage for fundamental concepts