wt-trackerMulti-Core WebTorrent Tracker in Rust
How we ported our WebTorrent tracker from Node.js to Rust with AI in two days, and built a server that served 216,000 simultaneous peers in production on a free 2-core Oracle Cloud instance — and why that matters for the cost of P2P video.
- 216,000 simultaneous WebSocket Secure peers in production; ~120,000 on average within the free traffic
- 2 vCPU, 12 GB Ampere A1, Oracle Cloud Free Tier
- 2 days from the first commit to production, with AI-assisted development
- Apache-2.0 open source
The challenge
Viewers in a P2P Media Loader network find each other through a WebTorrent tracker. Every viewer keeps a WebSocket connection open to the tracker, announces the streams it is watching, and exchanges WebRTC connection offers and answers (SDP) with other viewers of the same stream — a process called WebRTC signaling.
Public trackers are fine to start with, but a production audience needs its own. The load is unusual: tens of thousands of long-lived TLS connections and a constant flow of small JSON messages, where every announce can fan out into offers to many other peers.
Our goal was to serve 100,000 viewers from a free server, as one more step toward making video delivery affordable for anyone. Oracle Cloud's Always Free Tier offers a generous free server, but it has been halved: its Arm-based Ampere A1 instance now has 2 cores and 12 GB of memory.
Where we started
Our first tracker, wt-tracker for Node.js, keeps its logic in TypeScript and hands HTTP, WebSocket and TLS to µWebSockets.js, a native C++ networking stack. It is efficient per core, but Node.js runs it on one core, so on a 2-core server half of the CPU stays idle. Aquatic, a multi-threaded tracker in Rust, used 1.46 of the 2 cores at 42,000 peers on the same server. Neither could reach 100,000.
So we ported wt-tracker to Rust. The Node.js implementation remains available, and both use the same configuration file.
Ported with AI, verified against the original
AI coding agents wrote most of the code; our engineers set the goals, made the design decisions and reviewed every change. From the first commit to real viewers in production took two days. Speed did not come at the expense of correctness:
- A written specification is the source of truth for behavior, and it changes together with the code.
- Differential testing: random message sequences go through both implementations, and the Rust tracker's replies must be byte-identical to the Node.js tracker's.
- Twin benchmarks: every Rust benchmark has an identical JavaScript twin.
- Conformance and fuzzing: all 517 cases of the Autobahn WebSocket testsuite pass, and the WebSocket framing, compression, HTTP upgrade and tracker protocol are fuzzed.
- CI runs all of it on every change, with longer fuzzing every night.
How we made it fast
Multi-core without locks
Each CPU core runs a worker with its own share of the swarms, so workers never wait on each other.
Swarms follow the content
The video, audio and every quality of one stream live on one worker, and a viewer's connection moves to that worker at its first announce. Almost every message is then handled on a single core, with no traffic between threads.
Its own WebSocket implementation
Instead of µWebSockets, wt-tracker has its own WebSocket and TLS layer built for this workload. Like µWebSockets, it reads every connection through one shared buffer per worker, so a connection costs about 12 KB of memory with TLS (5–9 KB over plain WebSocket in load tests). Because we control it, it can also move a live connection, TLS session included, to another core — something µWebSockets doesn't offer, and what lets swarms follow the content. In our load tests on a single core, it needs up to a third less CPU per message than the Node.js implementation on µWebSockets.js and about 3–5× less memory per connection.
Zero-copy messages
WebRTC offers and answers are forwarded as slices of the received message, never copied or re-encoded.
Less traffic per peer
On a free server, outbound traffic is the scarcest resource. Outgoing offers are compressed when the browser supports it, and reconnecting viewers resume their TLS session instead of downloading the certificate chain again. One peer costs about 31 bytes per second of outbound traffic.
Proven ideas from the Node.js implementation
Swarm operations take constant time, whether a swarm has ten peers or ten thousand. Offers fan out from a random position in the swarm with no shuffling or temporary arrays. One sweep per announce interval removes silent peers instead of a timer per peer. Connection limits and allowed origins are checked during the HTTP upgrade, before a WebSocket is even created.
The results
On a 2-core Oracle Cloud Always Free Ampere A1 server with real P2P Media Loader viewers, at about 42,000 peers:
| Aquatic | wt-tracker | |
|---|---|---|
| CPU | 1.46 cores | 0.35 cores |
| Memory | 1.9 GB | 590 MB |
- Over 200,000 peers in production (216,000 at the peak) on the free server's 2 cores, at the limit of the busier core; about 120,000 on average within the free 10 TB of monthly outbound traffic.
- No complex horizontal scaling for many P2P video projects: one free server replaces a cluster.
- Private by design: self-hosting keeps information about your audience and P2P network on your own infrastructure.
- Production features: the WebTorrent "scrape" extension, Prometheus metrics and structured logs, allowed and denied origins, connection limits, a custom index page and graceful restarts.
How we tuned the server and Oracle's network, including the setting that otherwise drops new connections at about 40,000 peers, is described in our article 100k P2P Video Peers on the Oracle Cloud Always Free Tier.
What it shows
A rewrite used to be a months-long bet. With AI-assisted development, held to a written specification, differential tests against the original and conformance suites, it took two days to move a production server to a new language — and the result does on one free server what used to need a paid cluster.
Get wt-tracker
wt-tracker is free and open source under the Apache-2.0 license. It works with P2P Media Loader and any WebTorrent-compatible client. Installation, configuration and deployment are covered in the README on GitHub. The Node.js implementation remains available for Node.js setups.