WebIO 🦅
A minimalist, high-performance Rust web framework built with a zero-dependency philosophy for maximum speed and low memory footprint.
Why WebIO?
WebIO is a zero-dependency Rust web framework engineered to prevent "event loop freeze" during heavy calculations. By relying strictly on the Rust Standard Library, it prioritizes memory predictability and raw performance for data science and computational tasks. This minimalist engine utilizes dedicated OS threads for each connection to ensure non-blocking, pre-emptive multitasking. Featuring a "Safe-Turbo" executor with a custom spin-loop for ultra-low latency and O(1) memory complexity for big data ingestion, WebIO provides a high-integrity implementation for high-stakes environments.
🔬 The Rationale: WebIO vs. External Runtimes (Tokio/Hyper)
Most modern Rust web frameworks (like Axum or Actix) are built on top of Tokio, a high-performance asynchronous event-loop. While excellent for handling millions of idle connections (like a chat app), Tokio faces a "Cooperative Scheduling" challenge in Data Science and Computational environments.
🧠 The "Event Loop Freeze" Problem
In a traditional async runtime, tasks must "yield" voluntarily to the executor. If a single request performs a heavy 10-second mathematical calculation—such as a regression model, matrix inversion, or a large CSV parse—the entire event loop thread is blocked. This creates a "Stop-the-World" scenario where one heavy CPU task freezes the responses for all other users on that executor.
🚀 The WebIO Solution: Go-Inspired OS Pre-emption
WebIO is engineered as a specialized core engine for projects like Fluxor, where mathematical precision and memory predictability are the highest priority.
WebIO provides a Go-like concurrency experience but utilizes raw OS Threads for true kernel-level isolation. This ensures high efficiency for both small JSON responses and large "Big Data" streaming.
-
The Safety Distinction: While WebIO adopts the "goroutine-per-request model" strategy found in Go, it enforces Rust’s Ownership Model. This provides the concurrency simplicity of Go without the unpredictable latency of a Garbage Collector (GC). Deterministic memory management ensures no "GC pauses" occur during heavy mathematical calculations, providing consistent performance for high-stakes computational tasks.
-
OS-Level Isolation: Utilizing OS Threads managed by the Kernel achieves pre-emptive multitasking. If one handler is 100% occupied by heavy math on Core 1, the OS automatically ensures other threads remain responsive on other cores. This architecture eliminates the risk of "blocking the loop."
-
Safe-Turbo Bridge: While WebIO uses OS threads for isolation, a specialized
block_onexecutor allows the use ofasynclogic (like calling an external API or database) inside threads without the bloat of a massive dependency tree. -
Zero-RAM Big Data: Raw
TcpStreamaccess enables moving 100GB+ datasets directly from the socket to disk in 64KB chunks. This bypasses the 10MB RAM safety guard, ensuring the engine remains stable under massive data ingestion.
🛠️ Performance Architecture
- Hybrid Spin-Wait Strategy: The
block_onexecutor uses a 150k-cycle spin-loop to catch I/O ready states in nanoseconds, maintaining sub-millisecond tail latency by bypassing OS scheduler jitter for "hot" tasks. - Smart RAM Cache: Transparently caches hot assets (<500KB) using an
RwLockto provide ~50µs RAM-speed delivery for CSS/JS/JSON, while large files stream safely from the Disk. - Zero-Dependency Integrity: By strictly avoiding external crates, WebIO is immune to "supply chain attacks" and remains a pure, high-performance core for Computing Science and Mathematical applications.
- Nagle Control: Granular builder-pattern control over TCP throughput vs. latency (set_nagle) optimizes for either real-time APIs or massive data syncs.
✅ Production Ready: v1.0.0 Stable
WebIO is now a Stable Production Engine, moving beyond its initial research and development phase.
- API Stability: Starting with v1.0.0, WebIO follows strict semantic versioning. The core architecture and concurrency patterns are now locked for long-term stability.
- Legacy Research: Versions below 1.0.0 (0.9.x and earlier) represent the research phase and may contain breaking changes or unstable patterns.
- The Goal: To provide a high-integrity, zero-dependency core for high-performance web projects.
- Framework Foundation: Much like Tokio or Axum, WebIO is a powerful base for building specialized tools. It is designed to be the core foundation for the Fluxor Data Science framework and any other project requiring WebIO’s unique multi-threaded performance.
🎯 Core Philosophy
WebIO provides a fully functional web engine with zero external dependencies. By strictly utilizing the Rust std library, it ensures an ultra-light footprint, rapid compilation, and total memory predictability. zero external dependencies.
- No
tokio,async-stdorhyper. - No
serdeor heavy middleware bloat. - No
unsafecode in the executor. - Just pure, high-performance Rust.
🛠️ Installation
To include webio in your Rust project, run:
cargo add webio
Or add webio to your Cargo.toml:
[]
= "MAJOR.MINOR.PATCH" # replace with the actual version
💎 What Makes WebIO Unique?
WebIO is a High-Performance, Zero-Dependency, Multi-threaded Hybrid Engine inspired by the Go concurrency model. Unlike traditional runtimes, it provides deterministic performance by moving away from complex task-stealing to a direct OS-thread strategy. This ensures that heavy CPU tasks never block the event loop, maintaining ultra-low tail latency (~200µs) with zero external dependencies.
🧵 Go-Inspired Multi-threading
WebIO now mimics the Go strategy by spawning a unique OS Thread for every incoming connection. This ensures Pre-emptive Multitasking: a heavy mathematical calculation on one thread will never "freeze" the server for other users—a common pitfall in traditional async runtimes like Tokio.
⚡ Safe-Turbo block_on Executor
We have replaced the legacy runtime with a specialized Safe-Turbo Bridge. It utilizes a 150,000-cycle spin-loop to catch I/O ready states in nanoseconds. This bypasses OS scheduler jitter, maintaining sub-millisecond tail latency (~200µs) while remaining 100% safe.
🛡️ RAM Safety & Big Data Streaming
- 10MB Safety Valve: A pre-emptive RAM guard protects the heap by rejecting massive payloads before they are ingested.
- Zero-RAM Ingestion: Handlers now have direct access to the
TcpStream, allowing multi-gigabyte files (CSVs, Videos, Datasets) to be moved directly to disk in 64KB chunks with O(1) memory complexity.
🛰️ Real-Time WebSockets & Global Broadcast
Full RFC 6455 compliance is now built-in. WebIO handles the cryptographic handshake (SHA-1/Base64) and binary framing manually. The new Global Client Registry allows any thread to broadcast messages to all connected users simultaneously.
🧠 Smart Asset Caching
Introduced an RwLock RAM Cache for static assets. Small files (<500KB) are served at RAM speeds (~50µs), while larger files are intelligently served via the OS Page Cache to prevent memory exhaustion.
📈 Dynamic Nagle Control
New builder-pattern support for set_nagle(bool). Toggle between Low Latency (TCP_NODELAY) for real-time APIs or High Throughput for massive data synchronization.
🧬 Concurrency Comparison
| Feature | Traditional Async (Tokio) | WebIO v0.5.0 (OS Threads) |
|---|---|---|
| Heavy Math | ❌ Blocks the Event Loop | ✅ Isolated per CPU Core |
| Tail Latency | ⚠️ Variable (Task Stealing) | ✅ Ultra-Low (Spin-Wait) |
| Memory | ⚠️ Managed by Runtime | ✅ Deterministic (Ownership) |
| Dependencies | ❌ Hundreds | ✅ Zero (std only) |
🚀 Big Data Streaming
WebIO limits standard request bodies to 10MB for RAM safety, requiring the use of req.stream() for zero-RAM ingestion of large datasets exceeding this limit. This approach ensures O(1) memory complexity, allowing files of any size (e.g., 10GB+ CSVs or videos) to be streamed directly to storage, while maintaining flat RAM usage. For more information, visit WebIO documentation.
📋 Examples
use *;
use ;
use File;
const INDEX_HTML: &str = r##"<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>WebIO | High-Performance Rust</title>
<link rel="icon" href="/images/favicon.ico" type="image/x-icon" />
<link rel="stylesheet" href="/css/styles.css" />
</head>
<body>
<main>
<h1>👋 Welcome to WebIO</h1>
<p>A zero-dependency, ultra-low-latency web framework.</p>
<section class="gallery">
<img src="/images/logo.svg" alt="WebIO Logo" width="150" />
</section>
</main>
<script src="/js/script.js"></script>
</body>
</html>"##;
// --- Implementation Examples ---
/// Demonstrates basic GET routing.
async
/// Demonstrates dynamic path parameters using `<name>`.
/// Extracted via the `Params` collection.
async
/// A specialized handler for numeric IDs or other dynamic segments.
async
/// Demonstrates handling POST data directly from the `Req` struct.
async
/// A typical API endpoint returning JSON content.
async
/// A protected resource example. Access is controlled by the middleware defined in `main`.
async
/// A custom 404 handler that serves a styled HTML page.
/// Automatically selected by WebIO when a browser (Accept: text/html) hits a missing route.
async
/// A custom 404 handler that serves a JSON error.
/// Automatically selected for API clients or tools like `curl`.
async
async
/// Video upload handler
async
/// Chat handler
async
⚖️ License
WebIO is released under the MIT License.