Skip to content

Commit d888fe9

Browse files
Zix 0.4.x grpc (#873)
* zix-ws ignore .zig-cache & zig-out * zix-grpc 0.4.x-rc1 x86_64 musl alpine * zix-grpc head note * sync to attempt rc2 test 1 * using git with 2 repositories attempt * finalizing 0.4.x-rc2 * bump: zix 0.4.x * Benchmark results: zix-grpc --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 176b002 commit d888fe9

10 files changed

Lines changed: 83 additions & 48 deletions

File tree

frameworks/zix-grpc/Dockerfile

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
# syntax=docker/dockerfile:1.7
2-
#
3-
# zix-grpc. Zig gRPC h2c server using the zix library.
4-
# EPOLL dispatch: single accept loop + worker pool, EPOLLONESHOT per stream.
5-
# Implements benchmark.BenchmarkService/GetSum (unary) and StreamSum (server-streaming).
6-
# Built statically against musl so the runtime image is a single binary on scratch.
72

8-
FROM debian:bookworm-slim AS build
9-
ARG ZIG_VERSION=0.16.0
3+
FROM alpine:3.20 AS build
4+
ARG RETRY=6
105
ARG TARGETARCH
11-
ENV DEBIAN_FRONTEND=noninteractive
12-
RUN apt-get update && apt-get install -y --no-install-recommends \
13-
ca-certificates curl xz-utils \
14-
&& rm -rf /var/lib/apt/lists/*
6+
ARG RETRY_DELAY=3
7+
ARG ZIG_VERSION=0.16.0
8+
ARG ZIX_VERSION=0.4.x
9+
RUN apk add --no-cache ca-certificates curl git tar xz
1510

1611
RUN set -eu; \
1712
case "${TARGETARCH:-amd64}" in \
@@ -24,23 +19,51 @@ RUN set -eu; \
2419
mv "/opt/zig-${ZIG_ARCH}-linux-${ZIG_VERSION}" /opt/zig
2520
ENV PATH="/opt/zig:${PATH}"
2621

27-
# Vendor zix 0.3.x, separate layer so source-only rebuilds skip the download.
28-
# Strip the top-level directory produced by GitHub's archive.
29-
RUN mkdir -p /src/vendor/zix && \
30-
curl -fsSL https://github.com/prothegee/zix/archive/refs/heads/0.3.x.tar.gz \
31-
| tar -xz --strip-components=1 -C /src/vendor/zix
22+
# Vendor zix 0.4.x, separate layer so source-only rebuilds skip the fetch.
23+
# The Http1 raw engine work this image needs (large-body drain plus the per-worker
24+
# response cache used by the /json endpoint) must be present on the 0.4.x branch.
25+
# Four ordered attempts before giving up: curl the archive tarball from github then
26+
# codeberg, then a shallow git clone from github then codeberg. The github archive
27+
# redirects to codeload.github.com (which the benchmark runner may not resolve), so
28+
# curl can fall through to the codeberg tarball, and git clone talks to github.com
29+
# and codeberg.org directly as the deeper fallback. RETRY and RETRY_DELAY bound
30+
# every attempt.
31+
RUN set -eu; \
32+
fetch() { \
33+
rm -rf /src/vendor/zix; mkdir -p /src/vendor/zix; \
34+
curl -fsSL --retry ${RETRY} --retry-delay ${RETRY_DELAY} --retry-all-errors "$1" -o /tmp/zix.tar.gz \
35+
&& tar -xz --strip-components=1 -C /src/vendor/zix -f /tmp/zix.tar.gz; \
36+
}; \
37+
clone() { \
38+
attempt=0; \
39+
while [ "${attempt}" -lt "${RETRY}" ]; do \
40+
rm -rf /src/vendor/zix; \
41+
git clone --depth 1 --branch "${ZIX_VERSION}" "$1" /src/vendor/zix && return 0; \
42+
attempt=$((attempt + 1)); \
43+
sleep "${RETRY_DELAY}"; \
44+
done; \
45+
return 1; \
46+
}; \
47+
fetch "https://github.com/prothegee/zix/archive/refs/heads/${ZIX_VERSION}.tar.gz" \
48+
|| { echo "FAILED: curl ${RETRY} times from github" >&2; \
49+
fetch "https://codeberg.org/prothegee/zix/archive/${ZIX_VERSION}.tar.gz" \
50+
|| { echo "FAILED: curl ${RETRY} times from codeberg" >&2; \
51+
clone "https://github.com/prothegee/zix.git" \
52+
|| { echo "FAILED: git clone ${RETRY} times from github" >&2; \
53+
clone "https://codeberg.org/prothegee/zix.git" \
54+
|| { echo "FAILED: git clone ${RETRY} times from codeberg" >&2; exit 1; }; }; }; }
3255

3356
WORKDIR /src
3457
COPY build.zig build.zig.zon ./
3558
COPY src ./src
3659
RUN set -eu; \
3760
case "${TARGETARCH:-amd64}" in \
38-
amd64) ZIG_TARGET=x86_64-linux-musl ;; \
39-
arm64) ZIG_TARGET=aarch64-linux-musl ;; \
61+
amd64) ZIG_TARGET=x86_64-linux-musl; ZIG_CPU=x86_64_v3 ;; \
62+
arm64) ZIG_TARGET=aarch64-linux-musl; ZIG_CPU=baseline ;; \
4063
esac; \
41-
zig build -Dtarget="${ZIG_TARGET}" --release=fast
64+
zig build -Dtarget="${ZIG_TARGET}" -Dcpu="${ZIG_CPU}" --release=fast
4265

43-
FROM debian:bookworm-slim
66+
FROM alpine:3.20
4467
COPY --from=build /src/zig-out/bin/zix-grpc /zix-grpc
4568
EXPOSE 8080
4669
ENTRYPOINT ["/zix-grpc"]

frameworks/zix-grpc/meta.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"language": "Zig",
44
"type": "engine",
55
"engine": "zix",
6-
"description": "Zig gRPC h2c server using the zix framework. Single epoll event loop; worker pool handles one stream per slot. Implements GetSum (unary) and StreamSum (server-streaming).",
7-
"repo": "https://github.com/prothegee/zix",
6+
"description": "Zig gRPC h2c server using the zix network backend library. Shared-nothing io_uring: each worker owns its own ring and listener, multiplexing streams per connection. Implements GetSum (unary) and StreamSum (server-streaming).",
7+
"repo": "https://codeberg.org/prothegee/zix",
88
"enabled": true,
99
"tests": [
1010
"unary-grpc",

frameworks/zix-grpc/src/main.zig

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
//! HttpArena: zix-grpc
2-
//! zix version: 0.3.0
2+
//! zix version: 0.4.x
3+
//!
4+
//! zix HttpArena gRPC (h2c) entry point.
5+
//!
6+
//! Intent: demonstrate zix.Grpc (EPOLL dispatch model) against the HttpArena
7+
//! gRPC benchmark suite (unary, server-streaming).
8+
//!
9+
//! Design choices:
10+
//! - GetSum: unary SumRequest{a, b} -> SumReply{a + b}. The compute is a single
11+
//! add and the reply is a few bytes, well below the response-cache crossover,
12+
//! so caching would cost more than it saves and stays off here.
13+
//! - StreamSum: server-streaming, count replies of a + b + i.
14+
//! - max_streams is wide enough that a client opening many parallel streams is
15+
//! never refused at startup.
316
const std = @import("std");
417
const zix = @import("zix");
518

@@ -8,7 +21,7 @@ const zix = @import("zix");
821
const PORT: u16 = 8080;
922
/// Required for ipv4 and ipv6
1023
const LISTEN_IP: []const u8 = "::";
11-
const DISPATCH_MODEL: zix.Grpc.DispatchModel = .EPOLL;
24+
const DISPATCH_MODEL: zix.Grpc.DispatchModel = .URING;
1225
const KERNEL_BACKLOG: u31 = 1024 * 16;
1326
const WORKERS: usize = 0;
1427

site/data/frameworks.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -901,8 +901,8 @@
901901
},
902902
"zix-grpc": {
903903
"dir": "zix-grpc",
904-
"description": "Zig gRPC h2c server using the zix framework. Single epoll event loop; worker pool handles one stream per slot. Implements GetSum (unary) and StreamSum (server-streaming).",
905-
"repo": "https://github.com/prothegee/zix",
904+
"description": "Zig gRPC h2c server using the zix network backend library. Shared-nothing io_uring: each worker owns its own ring and listener, multiplexing streams per connection. Implements GetSum (unary) and StreamSum (server-streaming).",
905+
"repo": "https://codeberg.org/prothegee/zix",
906906
"type": "engine",
907907
"engine": "zix"
908908
},

site/data/stream-grpc-64.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,20 @@
5959
{
6060
"framework": "zix-grpc",
6161
"language": "Zig",
62-
"rps": 8331000,
63-
"avg_latency": "143.74ms",
64-
"p99_latency": "812.02ms",
65-
"cpu": "44.3%",
66-
"memory": "90MiB",
62+
"rps": 8468000,
63+
"avg_latency": "146.13ms",
64+
"p99_latency": "385.19ms",
65+
"cpu": "37.9%",
66+
"memory": "141MiB",
6767
"connections": 64,
6868
"threads": 64,
6969
"duration": "5s",
7070
"pipeline": 1,
7171
"bandwidth": "0",
7272
"reconnects": 0,
73-
"status_2xx": 8331,
73+
"status_2xx": 8468,
7474
"status_3xx": 0,
7575
"status_4xx": 0,
76-
"status_5xx": 144
76+
"status_5xx": 0
7777
}
7878
]

site/data/unary-grpc-1024.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,17 +157,18 @@
157157
{
158158
"framework": "zix-grpc",
159159
"language": "Zig",
160-
"rps": 6895367,
161-
"avg_latency": "7.74ms",
162-
"cpu": "3933.8%",
163-
"memory": "1.1GiB",
160+
"rps": 7122075,
161+
"avg_latency": "7.63ms",
162+
"p99_latency": "84.09ms",
163+
"cpu": "3008.6%",
164+
"memory": "1.2GiB",
164165
"connections": 1024,
165166
"threads": 64,
166167
"duration": "5s",
167168
"pipeline": 1,
168-
"bandwidth": "438.36MB/s",
169+
"bandwidth": "453.67MB/s",
169170
"reconnects": 0,
170-
"status_2xx": 34821605,
171+
"status_2xx": 36037700,
171172
"status_3xx": 0,
172173
"status_4xx": 0,
173174
"status_5xx": 0

site/data/unary-grpc-256.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,17 +157,18 @@
157157
{
158158
"framework": "zix-grpc",
159159
"language": "Zig",
160-
"rps": 7041146,
161-
"avg_latency": "2.29ms",
162-
"cpu": "3801.9%",
163-
"memory": "346MiB",
160+
"rps": 7239103,
161+
"avg_latency": "2.22ms",
162+
"p99_latency": "45.43ms",
163+
"cpu": "2927.0%",
164+
"memory": "394MiB",
164165
"connections": 256,
165166
"threads": 64,
166167
"duration": "5s",
167168
"pipeline": 1,
168-
"bandwidth": "447.62MB/s",
169+
"bandwidth": "457.47MB/s",
169170
"reconnects": 0,
170-
"status_2xx": 35557792,
171+
"status_2xx": 36340300,
171172
"status_3xx": 0,
172173
"status_4xx": 0,
173174
"status_5xx": 0
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
zix grpc server (epoll mux): :::8080 (64 workers)
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
zix grpc server (epoll mux): :::8080 (64 workers)
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
zix grpc server (epoll mux): :::8080 (64 workers)

0 commit comments

Comments
 (0)