Mill-IO
A lightweight, production-ready event loop library for Rust that provides efficient non-blocking I/O management without relying on heavyweight async runtimes. Mill-IO is a reactor-based event loop implementation built on top of mio that offers:
- Runtime-agnostic: No dependency on Tokio or other async runtimes
- Cross-platform: Leverages mio's polling abstraction (epoll, kqueue, IOCP)
- Thread pool integration: Configurable worker threads for handling I/O events
- Compute pool: Dedicated priority-based thread pool for CPU-intensive tasks
- High-level networking: TCP server/client with connection management
- Object pooling: Reduces allocation overhead for frequent operations
- Clean API: Simple registration and handler interface
Installation
Add Mill-IO to your Cargo.toml:
[]
= "2.0.0"
With networking support:
[]
= { = "2.0.0", = ["net"] }
For unstable features:
[]
= { = "2.0.0", = ["unstable"] }
Quick Start
use ;
use ;
;
See examples/scratch_echo_server.rs for a complete implementation.
High-Level TCP Networking
Mill-IO provides a high-level TCP API that handles connection management automatically. Enable with the net feature.
TCP Server
use ;
use ;
use Arc;
;
Server Context Operations
The ServerContext provides methods for interacting with connections:
// Send data to a specific connection
ctx.send_to?;
// Broadcast to all connections
ctx.broadcast?;
// Close a connection
ctx.close_connection?;
Compute Thread Pool
Mill-IO includes a dedicated thread pool for CPU-intensive operations, keeping the I/O event loop responsive. Tasks support priority scheduling.
Basic Usage
use ;
let event_loop = default;
// Spawn with default (Normal) priority
event_loop.spawn_compute;
// Spawn with specific priority
event_loop.spawn_compute_with_priority;
Task Priorities
Tasks are executed based on priority (highest first):
TaskPriority::Critical- Urgent tasks, processed firstTaskPriority::High- Important tasksTaskPriority::Normal- Default priorityTaskPriority::Low- Background tasks
Monitoring Metrics
let metrics = event_loop.get_compute_metrics;
println!;
println!;
println!;
println!;
println!;
println!;
Use Cases
- Cryptographic operations (hashing, encryption)
- Image/video processing
- Data compression
- Complex calculations
- File parsing
Examples
Mill-IO includes several practical examples demonstrating different use cases (See examples).
Configuration
Mill-IO provides flexible configuration options:
Default Configuration
use EventLoop;
// Uses CPU cores for workers, 1024 event capacity, 150ms timeout
let event_loop = default;
Custom Configuration
use EventLoop;
let event_loop = new?;
TCP Server Configuration
use TcpServerConfig;
let config = builder
.address
.buffer_size // Read buffer size
.max_connections // Connection limit
.no_delay // Disable Nagle's algorithm
.keep_alive
.build;
Thread Pool Sizing Guidelines
- CPU-bound tasks: Number of CPU cores
- I/O-bound tasks: 2-4x number of CPU cores
- Mixed workloads: Start with CPU cores + 2
Architecture
For detailed architectural documentation, see Architecture Guide
Platform Support
Mill-IO supports all major platforms through mio:
- Linux: epoll-based polling
- macOS: kqueue-based polling
- Windows: IOCP-based polling
- FreeBSD/OpenBSD: kqueue-based polling
Minimum supported Rust version: 1.70
License
Licensed under the Apache License, Version 2.0. See LICENSE for details.
Contributing
Contributions are welcome! Please read our Contributing Guide for details on our development process, coding standards, and how to submit pull requests.
For questions or discussions, feel free to open an issue or reach out to the maintainers.