Features
Core Capabilities
- Zero-Copy Architecture: Minimal allocations with memory pooling for maximum performance
- Runtime Agnostic: First-class support for both Tokio and async-std via feature flags
- Cross-Platform: Native support for Linux, macOS, and Windows with platform-specific optimizations
- Graceful Shutdown: Coordinated shutdown with configurable timeouts and subsystem awareness
- Signal Handling: Robust cross-platform signal management (SIGTERM, SIGINT, SIGQUIT, SIGHUP, Windows console events)
Advanced Features
- Subsystem Management: Concurrent subsystem lifecycle management with health checks and auto-restart
- Configuration Hot-Reload: Dynamic configuration updates without service interruption
- Structured Logging: High-performance tracing with JSON support and log rotation
- Metrics Collection: Built-in performance monitoring and resource tracking
- Memory Safety: 100% safe Rust with
#![deny(unsafe_code)]
Enterprise Ready
- High Concurrency: Built for 100,000+ concurrent operations
- Resource Management: Intelligent memory pooling and NUMA awareness
- Health Monitoring: Comprehensive subsystem health checks and diagnostics
- Production Tested: Battle-tested patterns from high-scale deployments
Installation
Add this to your Cargo.toml
:
[]
= "0.6.0"
# Optional features
= { = "0.6.0", = ["full"] }
Feature Flags
Feature | Description | Default |
---|---|---|
tokio |
Tokio runtime support | ✅ |
async-std |
async-std runtime support | ❌ |
metrics |
Performance metrics collection | ❌ |
console |
Enhanced console output | ❌ |
json-logs |
JSON structured logging | ❌ |
config-watch |
Configuration hot-reloading | ❌ |
full |
All features enabled | ❌ |
Quick Start
Simple Daemon
use ;
use Duration;
async
async
Multi-Subsystem Daemon
use ;
use Pin;
use Future;
use Duration;
// Define a custom subsystem
async
async
Configuration
Programmatic Configuration
use ;
use Duration;
let config = builder
.name
.log_level
.json_logging
.shutdown_timeout
.worker_threads
.enable_metrics
.hot_reload
.build?;
File Configuration (TOML)
Create a daemon.toml
file:
= "my-production-daemon"
[]
= "info"
= false
= true
= "/var/log/my-daemon.log"
[]
= 30000
= 45000
= 60000
[]
= 0 # auto-detect
= false
= 1048576
= false
= true
[]
= true
= 1000
= true
Load the configuration:
let config = load_from_file?;
Environment Variables
All configuration options can be overridden with environment variables using the DAEMON_
prefix:
Advanced Usage
Custom Subsystems with Health Checks
Metrics Collection
use MetricsCollector;
let collector = new;
// Increment counters
collector.increment_counter;
// Set gauge values
collector.set_gauge;
// Record timing histograms
collector.record_histogram;
// Get metrics snapshot
let snapshot = collector.get_metrics;
println!;
Signal Handling Configuration
use SignalConfig;
let signal_config = new
.with_sighup // Enable SIGHUP handling
.without_sigint // Disable SIGINT
.with_custom_handler;
builder
.with_signal_config
.run
.await
Architecture
Zero-Copy Design
proc-daemon is built around zero-copy principles:
- Arc-based sharing: Configuration and state shared via
Arc
to avoid cloning - Lock-free coordination: Uses atomic operations and lock-free data structures
- Memory pooling: Pre-allocated memory pools for high-frequency operations
- Efficient serialization: Direct memory mapping for configuration loading
Subsystem Lifecycle
graph TD
A[Register] --> B[Starting]
B --> C[Running]
C --> D[Health Check]
D --> C
C --> E[Stopping]
E --> F[Stopped]
F --> G[Restart?]
G -->|Yes| B
G -->|No| H[Removed]
C --> I[Failed]
I --> G
Shutdown Coordination
proc-daemon implements a sophisticated shutdown coordination system:
- Signal Reception: Cross-platform signal handling
- Graceful Notification: All subsystems notified simultaneously
- Coordinated Shutdown: Subsystems shut down in dependency order
- Timeout Management: Configurable graceful and force timeouts
- Resource Cleanup: Automatic cleanup of resources and handles
Testing
Run the test suite:
# Run all tests
# Run tests with all features
# Run integration tests
# Run benchmarks
PERFORMANCE
proc-daemon is designed for extreme performance:
Running Benchmarks
Typical performance:
- Daemon Creation: ~1-5μs
- Subsystem Registration: ~500ns per subsystem
- Shutdown Coordination: ~10-50μs for 100 subsystems
- Signal Handling: ~100ns latency
- Metrics Collection: ~10ns per operation
Memory Usage
- Base daemon: ~1-2MB
- Per subsystem: ~4-8KB
- Configuration: ~1-4KB
- Signal handling: ~512B
🔗 See PERFORMANCE.md
for up-to-date benchmarks, metrics, and version-over-version improvements.
Security
- Memory Safety: 100% safe Rust with no unsafe code
- Signal Safety: Async signal handling prevents race conditions
- Resource Limits: Configurable limits prevent resource exhaustion
- Graceful Degradation: Continues operating even when subsystems fail
Development Setup
Acknowledgments
- Inspired by production daemon patterns from high-scale deployments
- Built on the excellent Rust async ecosystem (Tokio, async-std)
- Configuration management powered by Figment
- Logging via the tracing ecosystem
We welcome contributions! Please see CONTRIBUTING.md for guidelines.