Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions frameworks/tokio-ws/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
target
.git
1 change: 1 addition & 0 deletions frameworks/tokio-ws/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
168 changes: 168 additions & 0 deletions frameworks/tokio-ws/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions frameworks/tokio-ws/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "httparena-tokio-ws"
version = "0.1.0"
edition = "2021"

[dependencies]
socket2 = { version = "0.5", features = ["all"] }
tokio = { version = "1", default-features = false, features = ["io-util", "net", "rt"] }

[profile.release]
codegen-units = 1
lto = "thin"
opt-level = 3
panic = "abort"
13 changes: 13 additions & 0 deletions frameworks/tokio-ws/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM rust:1.95 AS build
WORKDIR /app
COPY Cargo.toml Cargo.lock ./
RUN mkdir src && echo "fn main() {}" > src/main.rs \
&& cargo build --release \
&& rm -rf src target/release/httparena-tokio-ws target/release/deps/httparena_tokio_ws*
COPY src ./src
RUN RUSTFLAGS="-C target-cpu=native" cargo build --release

FROM debian:bookworm-slim
COPY --from=build /app/target/release/httparena-tokio-ws /server
EXPOSE 8080
CMD ["/server"]
46 changes: 46 additions & 0 deletions frameworks/tokio-ws/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# tokio-ws

A WebSocket echo server written directly on **raw tokio**, with the WebSocket
protocol **hand-rolled** — no `tokio-tungstenite`, no `wtx`, no WS library at all.

It exists as an `engine`-tier reference point: the lowest-level way to serve the
`echo-ws` profile on the tokio reactor, so the leaderboard shows what the runtime
itself can do once the framing is reduced to the minimum.

## What's implemented by hand

- **RFC 6455 handshake** — request parsing, `Sec-WebSocket-Accept` derivation,
and the `101 Switching Protocols` reply. SHA-1 and base64 are both written
from scratch (`src/main.rs`), so the only dependencies are `tokio` and
`socket2`.
- **Frame codec** — a streaming parser that handles 7/16/64-bit lengths,
client→server unmasking, and partial frames split across `read()`s. Echoes are
re-emitted as unmasked server frames, preserving FIN + opcode (so fragmented
messages pass through transparently).
- **Control frames** — `Ping` is answered with `Pong`; `Close` is echoed and the
connection ends.

## Serving model

One `current_thread` tokio runtime per core, each binding `0.0.0.0:8080` with
`SO_REUSEPORT` so the kernel shards new connections across cores — no shared
accept queue, no cross-core work-stealing. `TCP_NODELAY` is set per connection,
and outgoing echoes are batched per read so a pipelined burst flushes in one
write. This mirrors the other one-thread-per-core engine entries (e.g.
`rust-epoll`).

## Endpoint

| Method | Path | Behavior |
|--------|-------|-------------------------------------------|
| GET | `/ws` | WebSocket upgrade, then echo every frame |

A non-upgrade `GET /ws` is rejected with `400`; other paths return `404`.

## Build & run

```bash
cargo build --release
./target/release/httparena-tokio-ws # listens on :8080
python3 ../../scripts/validate-ws.py localhost 8080 /ws
```
14 changes: 14 additions & 0 deletions frameworks/tokio-ws/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"display_name": "tokio-ws",
"language": "Rust",
"type": "engine",
"engine": "tokio",
"description": "Hand-rolled WebSocket echo server on raw tokio — no WebSocket library. A current-thread runtime per core with SO_REUSEPORT sharding, a from-scratch RFC 6455 handshake (hand-written SHA-1 + base64) and a manual frame parser/masking + echo write path.",
"repo": "https://github.com/tokio-rs/tokio",
"enabled": true,
"tests": [
"echo-ws",
"echo-ws-pipeline"
],
"maintainers": []
}
Loading