WebIO π¦
A minimalist, high-performance web framework for Rust built with a zero-dependency philosophy.
π§ͺ Research Status: Experimental
WebIO is currently in an active research and development phase.
- API Stability: Expect breaking changes as we refine the core engine.
- Goal: To provide a high-integrity core engine for Data Science, Computing Science, and frameworks like Fluxor.
- Production Warning: Use with caution until the stable
1.0.0released.
π― 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
Add this to your Cargo.toml:
[]
= "0.5.0-alpha"
π What's New in v0.5.0-alpha
The v0.5.0-alpha release represents a major architectural shift from a single-threaded async model to a High-Performance Multi-threaded Hybrid Engine inspired by the Go concurrency model.
π§΅ 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 POST Examples
In WebIO, standard POST data is limited to 10MB for RAM safety. For datasets exceeding this (e.g., 10GB CSVs or Videos), handlers must use the raw stream for Zero-RAM Ingestion.
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
async
async