mytheclipse
Resource-aware execution primitives and reliability abstractions for Rust: async I/O, heavy compute, background queue management, resiliency, traffic control, lifecycle management, and observability. Sized automatically from the host's logical core count and exposed through a single, lazily-initialized engine context alongside self-contained, constructible utilities.
Resource Sizing
Given $N$ logical cores (via num_cpus::get()):
| Subsystem | Sizing Formula | Default on 8 cores | Backing Primitive |
|---|---|---|---|
| Async I/O | $N$ | 8 | Ambient tokio::spawn + tracing span |
| Compute | $\max(1, N - 1)$ | 7 | Sized rayon::ThreadPool + catch_unwind |
| Background Queue | $\max(2, \lfloor N / 2 \rfloor)$ | 4 | tokio::sync::Semaphore + tokio::spawn |
The three execution primitives (io, compute, bg) are sized from the host's CPU core count through mytheclipse::context(). Resiliency, traffic control, lifecycle, and observability utilities are constructible per-instance without global state.
Features
io: enablesmytheclipse::spawn_io, instrumented async task spawning.compute: enablesmytheclipse::compute, panic-isolated execution on a sized Rayon pool.bg: enablesmytheclipse::spawn_bg, semaphore-bounded background tasks.resiliency: fault tolerance abstractions:retry— auto-retry with exponential backoff and full/equal jitter.CircuitBreaker— failure threshold and cooldown state machine (Closed/Open/HalfOpen).with_timeout/timeout/Timeout— hard execution deadlines.
traffic: traffic & load control:RateLimiter— lazy token-bucket rate limiter with burst capacity.BackpressureQueue— bounded queue withDropOldest,Reject, andBlockoverflow policies.ConcurrencyLimiter— synchronous RAII semaphore wrapper for capping concurrent operations.
lifecycle: system lifecycle coordination:ShutdownManager/ShutdownSignal— OS signal catching (SIGINT/SIGTERM/Ctrl-C) and graceful task draining.CronSchedule/schedule— self-contained 5-field cron parser and async timer scheduler.
observability: runtime visibility:MetricsCollector— thread-safe statistics collector with Prometheus text exposition format export.PanicTracker— non-fatal panic logging with tracing context and boundary isolation.
full: enables all subsystems:io,compute,bg,resiliency,traffic,lifecycle,observability.
Zero features enabled by default (default = []), so you only pull in the dependencies your application actually uses.
Quick Start
Add to your Cargo.toml:
[]
= { = "0.2", = ["full"] }
1. Execution Primitives
async
2. Resiliency & Fault Tolerance
use Duration;
// Auto-Retry with Exponential Backoff + Jitter
let result = retry.await?;
// Circuit Breaker
let breaker = new;
let value = breaker.call?;
// Timeout & Deadlines
let value = with_timeout.await?;
3. Traffic & Resource Control
// Rate Limiter (Token Bucket)
let limiter = new;
limiter.acquire.await?;
// Concurrency Limiter (Sync Semaphore)
let limiter = new;
let _permit = limiter.acquire; // released on drop
// Backpressure Queue (Graceful Degradation)
let queue = new;
queue.push.await?;
let next_job = queue.pop.await;
4. Lifecycle & State Management
// Graceful Shutdown Manager
let shutdown = new;
let sig = shutdown.handle;
spawn;
shutdown.drain.await;
// Cron Periodic Job Scheduler (Self-contained, no external crates)
let cron = parse?; // 1 AM daily
let job = schedule?;
5. Telemetry & Observability
// Centralized Metrics Collector (Prometheus text exposition format)
let metrics = new;
metrics.record_task;
metrics.inc_counter;
let prometheus_output = metrics.export_prometheus;
// Panic Isolation Tracker
let guard = install; // logs panics with tracing span
let result = catch;
Running the Example
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.