Prism
A userspace network stack written in Rust, designed for low-latency applications. Implements TCP, UDP, and custom protocols with zero-copy I/O and lock-free data structures.
Design Goals
- Low Latency: Sub-microsecond packet processing
- High Throughput: Line-rate performance on 100Gbps links
- Deterministic: Bounded worst-case latency
- Safe: Memory-safe implementation in Rust
Architecture
Prism bypasses the kernel network stack using DPDK (Data Plane Development Kit) for direct hardware access:
┌─────────────┐
│ Application │
└──────┬──────┘
│
┌──────▼──────┐
│ Prism │ ← Userspace stack
│ (TCP/UDP) │
└──────┬──────┘
│
┌──────▼──────┐
│ DPDK │ ← Direct hardware access
└──────┬──────┘
│
Network Card
Key Components
- Packet Processing Pipeline: Lock-free ring buffers for packet I/O
- Connection Management: Efficient hash table for connection lookup
- Congestion Control: Custom algorithms optimized for datacenter networks
- Zero-Copy I/O: Direct memory access to avoid unnecessary copies
Performance
Benchmarks on a dual-port 100Gbps NIC:
| Metric | Linux Kernel | Prism | Improvement |
|---|---|---|---|
| Latency (P50) | 12μs | 0.8μs | 15x |
| Latency (P99) | 45μs | 2.1μs | 21x |
| Throughput | 85 Gbps | 98 Gbps | 15% |
| CPU Usage | 85% | 45% | 47% reduction |
Implementation Highlights
Lock-Free Connection Table
pub struct ConnectionTable {
buckets: Vec<AtomicPtr<Connection>>,
mask: usize,
}
impl ConnectionTable {
pub fn lookup(&self, key: ConnectionKey) -> Option<&Connection> {
let hash = self.hash(key);
let bucket = &self.buckets[hash & self.mask];
let mut current = bucket.load(Ordering::Acquire);
while !current.is_null() {
let conn = unsafe { &*current };
if conn.key == key {
return Some(conn);
}
current = conn.next.load(Ordering::Acquire);
}
None
}
}
Zero-Copy Packet Processing
Packets are processed in-place without copying:
pub fn process_packet(&mut self, mbuf: &mut Mbuf) {
let eth = mbuf.data_mut::<EthernetHeader>();
let ip = mbuf.data_mut::<Ipv4Header>();
let tcp = mbuf.data_mut::<TcpHeader>();
// Process headers in-place
self.handle_tcp_packet(ip, tcp, mbuf);
}
Use Cases
Prism is ideal for:
- High-frequency trading systems
- Real-time analytics pipelines
- Game servers requiring low latency
- Network function virtualization (NFV)
References
Protocol Support
Currently implemented:
- ✅ TCP (RFC 793)
- ✅ UDP (RFC 768)
- ✅ IPv4/IPv6
- ✅ ICMP
- 🔄 QUIC (in progress)
- 🔄 Custom protocol framework
Links to this page
On Type Safety
The Cost of Correctness
The Performance Illusion
Zero-Copy Dreams
Change Log