Scaly's HTTP stack

The http package of Scaly's standard library and its siblings, used the way an application uses them — the entry scaly in HttpArena.

What it is

Scaly is a compiled language whose memory lives in regions the compiler infers: there is no garbage collector and no borrow checker. A server written in it looks like this:

The code

A handler takes the request and the response; the router maps paths to handlers. From the entry:

; baseline: a + b, plus the body when there is one.
procedure baseline(req: ref[Request], mutable res: ref[Response])
{
    var sum parse_int_prefix(req.query_param("a")) + parse_int_prefix(req.query_param("b"))
    if req.body.length > 0
        sum := sum + parse_int_prefix(trim(req.body))
    res.send_int(sum)
}

; async: waits ms without holding a thread, then answers the number.
procedure delay(req: ref[Request], mutable res: ref[Response])
{
    let ms parse_int_prefix(req.param("ms"))
    if ms > 0
        Scheduler.sleep(ms)
    res.send_int(ms)
}

var app Router.create(Page.allocate_page())
app.any("/baseline11", &baseline)
app.get("/delay/{ms}", &delay)
app.get("/json/{count}", &json_items)          ; serializes with the json package's writer
app.compress("", "gzip", &gzip_compress)      ; text and JSON in gzip where the client takes it
serve(app, 8080)

The whole entry is three files, arena.scaly (the routes and the core handlers), db.scaly (Postgres) and stack.scaly (the production stack behind a gateway); the directory has its Dockerfile and a table of how each profile is served. A procedure names what it writes (mutable res); the compiler checks it.

What it does not do
Reproduce it

With HttpArena itself, which builds the entry's image (the released toolchain at the version its Dockerfile names, as anyone installs it) and runs every profile the entry subscribes to:

git clone https://github.com/MDA2AV/HttpArena && cd HttpArena
./scripts/validate.sh scaly
./scripts/benchmark.sh scaly

Or the server alone, in the entry's directory, on Linux with OpenSSL 3.5, ngtcp2 and libdeflate installed (the Dockerfile shows how):

curl -fsSL https://scaly.io/install.sh | sh
scaly build arena.scaly --release -o arena
./arena                                        # :8080, TLS :8081, HTTP/2 :8443, h2c :8082
curl 'http://localhost:8080/baseline11?a=1&b=2'  # 3
Results

The numbers are HttpArena's, measured on its machine against every other entry: www.http-arena.com.