Skip to content
Projetos

Sobre

A web framework for V that owns the wire: its own HTTP/1.1, HTTP/2, WebSocket and TLS 1.3 engine, one epoll worker per CPU, no allocation per request.

Desenvolvimento web e de aplicativos

Como estes números são medidos

Crescimento medido de estrelas

em 24 h
0
em 7 dias
0
em 15 dias
+3
em 1 mês
+6

Variações líquidas em períodos sobrepostos, não totais diários. Medições ausentes ficam em branco. Estrelas indicam interesse, não qualidade.

README.md

Original

Viltrum

Viltrum

A web framework for V that owns the wire.
Its own HTTP/1.1, HTTP/2, HTTP/3, WebSocket and TLS 1.3 engine. One epoll worker per CPU. No allocation per request.

ci release MIT license HttpArena HTTP/1.1 HttpArena HTTP/2 HttpArena WebSocket

Documentation · Examples · Benchmarks · Roadmap · Changelog · Live demo · Discord


First on WebSocket, short-lived connections and latency at 10K req/s, second on HTTP/1.1 and HTTP/2 in HttpArena's Experimental category (December 2026). On 2026-10-14 the same benchmark had Viltrum 99th of 151 on its baseline. Everything between the two is in this repository: a new engine, its own TLS 1.3 records and handshake, its own DEFLATE encoder, HTTP/2, HTTP/3, and a CI gate that fails if a request allocates a single byte.

Instructions per request on GET /baseline11 for every commit on main since v1.0.0
Every commit on main, measured with callgrind: v.rustapi.cloud/fast

Quick start

v install Tuntii.Viltrum
module main

import tuntii.viltrum

struct Hello {
	message string
	name    string
}

fn main() {
	mut app := viltrum.new()
	app.use(viltrum.recover)
	app.get('/', fn (mut c viltrum.Ctx) {
		c.text(200, 'ok\n')
	})
	app.get('/hi/:name', fn (mut c viltrum.Ctx) {
		c.json(200, Hello{
			message: 'hello'
			name:    c.param('name') or { 'world' }
		})
	})
	app.listen('127.0.0.1:8080') or { panic(err) }
}
$ v run . &
$ curl localhost:8080/hi/ada
{"message":"hello","name":"ada"}

Requires V 0.5.2; CI also builds and tests on V master. Serving needs Linux (the engine is epoll). On macOS and Windows the framework builds and its unit tests run, so handlers can be written and tested there with app.handle_raw.

Working on Viltrum itself? Clone it and link the checkout as import viltrum:

git clone https://github.com/Tuntii/viltrum.git && cd viltrum
bash scripts/install.sh      # ~/.vmodules/viltrum -> this tree
v run examples/hello

Why Viltrum

The engine is the framework. The accept loop, the HTTP/1.1 parser, HTTP/2 with HPACK, HTTP/3 with QUIC and QPACK, WebSocket framing, the TLS 1.3 record layer and the common TLS 1.3 handshake (X25519, RSA-PSS) are written here, not wrapped. The rest of the crypto comes from mbedtls, which ships with V. v.mod lists no dependencies.

No allocation per request, enforced. Tests run each request shape 10,000 times and fail if the GC heap grows by one byte, on HTTP/1.1, HTTP/2, TLS, WebSocket, streaming, static files and deferred responses. Request strings are views into the connection's buffer; .clone() what you keep past the handler.

One model for every protocol. The same router, middleware chain and Ctx answer HTTP/1.1, HTTP/2 over TLS and cleartext h2c on the same port, and HTTP/3 over UDP on the same port number. WebSocket upgrades go through the same middleware. Streaming and Server-Sent Events work over HTTP/1.1 and HTTP/2.

Held to the specs. The network parsers are fuzzed in CI, 500,000 mutations each: HTTP/1.1, HPACK, HTTP/2 frames, WebSocket frames and the TLS handshake. h2spec passes 145 of 146 over TLS. Autobahn|Testsuite reports no failures in any section Viltrum implements.

What you get

Area
HTTP/1.1 keep-alive, pipelining (responses batched into one write), Expect: 100-continue, HEAD. Ambiguous framing (TE+CL, duplicate or non-digit CL, obs-fold, bare CR/LF) answers 400
Engine one SO_REUSEPORT epoll worker per CPU (cpuset-aware), backpressure, read/idle/write timeouts, max_conns, buffers lent per event so an idle connection holds none, SIGINT/SIGTERM stop accepting and close open connections within a second
Routing :param, trailing *rest, groups, global and per-route middleware (c.next())
Middleware recover, gzip (on Viltrum's own DEFLATE encoder), cors, logger
JSON c.json(200, value): encoder generated per type at compile time, no reflection
TLS app.listen_tls, or app.serve for cleartext and TLS listeners together: TLS 1.3, certificates reloaded from disk without a restart (TLS)
HTTP/2 Listener{ addr, http2: true }: over TLS (ALPN) and cleartext h2c, beside HTTP/1.1 on the same port; flow control and the RFC 9113 limits (HTTP/2)
HTTP/3 Listener{ addr, http3: true, tls: ... }: QUIC over UDP on the TLS listener's port number, on the same workers; loss recovery, QPACK, UDP GSO (HTTP/3)
gRPC (unary) trailer fields over HTTP/2 (c.set_trailer), so a route can answer a gRPC call (gRPC)
Templates c.render(status, tpl, value): Mustache syntax, parsed once at startup, HTML-escaped by default, no allocation per page (Templates)
WebSocket app.ws(pattern, handler): RFC 6455, ws:// and wss://, topics with subscribe / publish across workers (WebSocket)
Streaming and SSE c.stream, c.sse: bodies written from timers, from any thread, or as the client reads them (on_drain); many streams per HTTP/2 connection (Streaming)
Static files app.static_files, c.file: ETag, Last-Modified, 304, byte ranges, precompressed .br/.gz, sendfile (Static files)
Forms c.form_value, c.form_file, c.form_parts: urlencoded and multipart, parsed in place (Forms)
Deferred responses c.after(ms, cb, arg): answer later from a per-worker timer without holding a thread
HTTP client c.fetch(upstream, method, target, cb, arg): call another HTTP service from a handler without holding the worker; keep-alive pools per worker, no allocation per fetch (Client)
Testing app.handle_raw(raw) serves a raw request in-process

Panics. V cannot catch a panic: it exits the process. recover turns a handler that wrote nothing into a 500 and closes the connection. Run the server under a supervisor such as systemd with Restart=always.

Not yet: https:// upstreams for the HTTP client, and serving off Linux.

Benchmarks

HttpArena runs every entry on the same machine (AMD Threadripper PRO 3995WX, 64 cores) with the same load generator. Medals in the Experimental category, as shown on http-arena.com/frameworks/viltrum on 2026-12-04 (each row links to its board):

Board Place
🥇 WebSocket composite 1 / 26
🥇 Short-lived connections 1 / 36
🥇 Latency at 10K req/s 1 / 34
🥇 WebSocket echo, pipelined 1 / 26
🥇 WebSocket echo, short-lived 1 / 24
🥈 HTTP/1.1 composite 2 / 36
🥈 HTTP/2 composite 2 / 21
🥈 HTTP/2 static files 2 / 20
🥈 WebSocket echo 2 / 26
🥈 JSON over TLS 2 / 33
🥉 Async (/delay) 3 / 32
🥉 1M connections 3 / 11
🥉 HTTP/2 baseline, over TLS 3 / 20
🥉 HTTP/2 baseline, cleartext (h2c) 3 / 21
🥉 JSON over h2c 3 / 21
🥉 JSON, gzip 3 / 33

Latency profiles are scored on CPU per request and latency at a fixed rate, and JSON, gzip on throughput and bytes per response together, so their places do not follow the req/s order.

Between HttpArena runs, every commit on main is measured on its own: callgrind instructions per request on one worker and one keep-alive connection, which do not move with machine noise, at v.rustapi.cloud/fast. Pull requests get the same measurement against their base and fail if a scenario is more than 1% slower.

Experimental is HttpArena's category for young frameworks without much production use yet; its default leaderboard shows flagship and emerging entries, so tick Experimental to see Viltrum there. The entry's source is benches/httparena, and the method notes are in benches/RESULTS.md. Viltrum is also entered in the-benchmarker/web-frameworks.

Examples

Example Shows
hello text responses and a :param
rest JSON in and out, shared state behind a mutex
features middleware, groups, query params, gzip, static files, a file upload
https cleartext and HTTPS listeners on the same workers
ws_chat WebSocket rooms, subscribe / publish across workers
sse Server-Sent Events: a timer clock, a chat topic, a CSV generated at the client's pace

Ports and curl lines for each are in examples/README.md.

For a whole application (API, UI, login, CRUD in one process), start from full-stack-viltrum-template. It runs the live demo.

Documentation

The guides live in docs/ and are mirrored to the wiki.

Read when Guide
Your first hour Getting started
Writing handlers and middleware Request and response
Tuning workers, limits and timeouts Connections
Serving HTTPS, HTTP/2 or HTTP/3 TLS, HTTP/2, HTTP/3
Rendering HTML pages Templates
Real-time features WebSocket, Streaming and SSE
Calling other services, serving gRPC Client, gRPC
Going to production Deploy
Coming from 1.x Upgrading

Design notes for the larger pieces: TLS, the TLS 1.3 handshake, HTTP/2, streaming, the HTTP client, HTTP/3.

Roadmap

Open work is on the project board: https:// upstreams for the HTTP client, WebSocket over HTTP/2, and metrics. Each feature gets its own decision before it starts; the plan, its principles and what Viltrum will not do are in ROADMAP.md.

Contributing

Bug reports, questions and pull requests are welcome; for questions and ideas there is also the Discord server. CONTRIBUTING.md covers setup, the checks CI runs and the commit style; releases are cut by semantic-release from conventional commits on main. Cards on the project board marked Known gaps are small, self-contained places to start. Everyone taking part follows the Code of Conduct.

Found a security problem? Report it privately as described in SECURITY.md, not in a public issue.

License

MIT

Explore projetos relacionados

Carregando…