ziglana/gRPC-zig
blazigly fast gRPC client & server implementation in zig
refs
A blazingly fast gRPC client & server implementation in Zig, designed for maximum performance and minimal overhead.
// Server
const server = try GrpcServer.init(allocator, 50051, "secret-key");
try server.handlers.append(.{
.name = "SayHello",
.handler_fn = sayHello,
});
try server.start();
// Client
var client = try GrpcClient.init(allocator, "localhost", 50051);
const response = try client.call("SayHello", "World", .none);
const std = @import("std");
const GrpcServer = @import("server.zig").GrpcServer;
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
var server = try GrpcServer.init(gpa.allocator(), 50051, "secret-key");
defer server.deinit();
try server.start();
}
var stream = streaming.MessageStream.init(allocator, 5);
try stream.push("First message", false);
try stream.push("Final message", true);
build.zig.zon
:.dependencies = .{
.grpc_zig = .{
.url = "https://github.com/ziglana/grpc-zig/archive/refs/tags/v0.1.0.tar.gz",
},
},
build.zig
:const grpc_zig = b.dependency("grpc_zig", .{});
exe.addModule("grpc", grpc_zig.module("grpc"));
Benchmarked against other gRPC implementations (ops/sec, lower is better):
gRPC-zig │████████░░░░░░░░░░│ 2.1ms
gRPC Go │██████████████░░░░│ 3.8ms
gRPC C++ │████████████████░░│ 4.2ms
The repository includes a built-in benchmarking tool to measure performance:
# Build the benchmark tool
zig build
# Run benchmarks with default settings
zig build benchmark
# Run with custom parameters
./zig-out/bin/grpc-benchmark --help
./zig-out/bin/grpc-benchmark --requests 1000 --clients 10 --output json
# Or use the convenient script
./scripts/run_benchmark.sh
Benchmark Options:
--host <host>
: Server host (default: localhost)--port <port>
: Server port (default: 50051) --requests <n>
: Number of requests per client (default: 1000)--clients <n>
: Number of concurrent clients (default: 10)--size <bytes>
: Request payload size (default: 1024)--output <format>
: Output format: text|json (default: text)Benchmark Metrics:
The benchmarks automatically run in CI/CD on every pull request and provide performance feedback.
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
This project is licensed under the Unlicense - see the LICENSE file for details.
If you find this project useful, please consider giving it a star on GitHub to show your support!
Made with ❤️ in Zig