Skip to content

Commit 3213edf

Browse files
authored
Merge pull request #21 from BennyFranciscus/add-blitz
Add blitz: Zig HTTP server with epoll multi-threading
2 parents 511d334 + 3b38f11 commit 3213edf

6 files changed

Lines changed: 822 additions & 0 deletions

File tree

frameworks/blitz/Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM debian:bookworm-slim AS build
2+
RUN apt-get update && apt-get install -y wget xz-utils && \
3+
wget -q https://ziglang.org/download/0.14.0/zig-linux-x86_64-0.14.0.tar.xz && \
4+
tar xf zig-linux-x86_64-0.14.0.tar.xz && \
5+
mv zig-linux-x86_64-0.14.0 /usr/local/zig
6+
ENV PATH="/usr/local/zig:$PATH"
7+
WORKDIR /app
8+
COPY build.zig build.zig.zon ./
9+
COPY src ./src
10+
RUN zig build -Doptimize=ReleaseFast
11+
12+
FROM debian:bookworm-slim
13+
COPY --from=build /app/zig-out/bin/blitz /server
14+
EXPOSE 8080
15+
CMD ["/server"]

frameworks/blitz/README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# blitz ⚡
2+
3+
A blazing-fast HTTP/1.1 server written in Zig, built to compete in [HttpArena](https://github.com/MDA2AV/HttpArena).
4+
5+
## Design
6+
7+
- **Language:** Zig — C-level performance with better ergonomics
8+
- **I/O:** epoll with edge-triggered notifications
9+
- **Threading:** SO_REUSEPORT multi-threading (one accept socket per core, no lock contention)
10+
- **Parsing:** Zero-copy HTTP request parsing
11+
- **Responses:** Pre-computed static responses, pipeline batching
12+
- **Memory:** Arena-style per-connection buffers, minimal heap allocations in hot path
13+
14+
## Endpoints
15+
16+
| Endpoint | Method | Description |
17+
|----------|--------|-------------|
18+
| `/pipeline` | GET | Returns "ok" — pipelining benchmark |
19+
| `/baseline11` | GET/POST | Query param sum, optional body parsing |
20+
| `/baseline2` | GET | Query param sum (H2 baseline) |
21+
| `/json` | GET | Pre-computed JSON dataset response |
22+
| `/upload` | POST | Returns body byte count |
23+
| `/static/{file}` | GET | Pre-loaded static files |
24+
25+
## Building
26+
27+
```bash
28+
zig build -Doptimize=ReleaseFast
29+
```
30+
31+
## Running
32+
33+
```bash
34+
./zig-out/bin/blitz
35+
```
36+
37+
The server listens on port 8080 and spawns one worker thread per available CPU core.

frameworks/blitz/build.zig

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const std = @import("std");
2+
3+
pub fn build(b: *std.Build) void {
4+
const target = b.standardTargetOptions(.{});
5+
const optimize = b.standardOptimizeOption(.{});
6+
7+
const exe = b.addExecutable(.{
8+
.name = "blitz",
9+
.root_source_file = b.path("src/main.zig"),
10+
.target = target,
11+
.optimize = optimize,
12+
.single_threaded = false,
13+
});
14+
15+
exe.linkLibC();
16+
17+
b.installArtifact(exe);
18+
19+
const run_cmd = b.addRunArtifact(exe);
20+
run_cmd.step.dependOn(b.getInstallStep());
21+
const run_step = b.step("run", "Run the server");
22+
run_step.dependOn(&run_cmd.step);
23+
}

frameworks/blitz/build.zig.zon

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.{
2+
.name = .blitz,
3+
.version = "0.1.0",
4+
.fingerprint = 0xe8a54ff4e60f9038,
5+
.paths = .{
6+
"build.zig",
7+
"build.zig.zon",
8+
"src",
9+
},
10+
}

frameworks/blitz/meta.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"display_name": "blitz",
3+
"language": "Zig",
4+
"type": "engine",
5+
"engine": "epoll",
6+
"description": "Custom Zig HTTP server built on epoll with SO_REUSEPORT multi-threading. Zero allocations in the hot path, pre-computed responses, pipeline batching.",
7+
"repo": "https://github.com/BennyFranciscus/blitz",
8+
"enabled": true,
9+
"tests": [
10+
"baseline",
11+
"pipelined",
12+
"noisy",
13+
"limited-conn",
14+
"json",
15+
"upload"
16+
]
17+
}

0 commit comments

Comments
 (0)