From d4eab6408e4cacdf17126059dd4e83cc0a0bd060 Mon Sep 17 00:00:00 2001 From: dravenk Date: Mon, 23 Sep 2024 13:40:21 +0800 Subject: [PATCH 01/11] Adding Zinc framework --- frameworks/Zig/zinc/.gitignore | 2 + frameworks/Zig/zinc/README.md | 93 +++++++++++++++++++++++ frameworks/Zig/zinc/benchmark_config.json | 26 +++++++ frameworks/Zig/zinc/build.zig | 78 +++++++++++++++++++ frameworks/Zig/zinc/build.zig.zon | 19 +++++ frameworks/Zig/zinc/run.sh | 3 + frameworks/Zig/zinc/src/main.zig | 38 +++++++++ frameworks/Zig/zinc/zinc.dockerfile | 22 ++++++ 8 files changed, 281 insertions(+) create mode 100644 frameworks/Zig/zinc/.gitignore create mode 100755 frameworks/Zig/zinc/README.md create mode 100755 frameworks/Zig/zinc/benchmark_config.json create mode 100644 frameworks/Zig/zinc/build.zig create mode 100644 frameworks/Zig/zinc/build.zig.zon create mode 100644 frameworks/Zig/zinc/run.sh create mode 100644 frameworks/Zig/zinc/src/main.zig create mode 100644 frameworks/Zig/zinc/zinc.dockerfile diff --git a/frameworks/Zig/zinc/.gitignore b/frameworks/Zig/zinc/.gitignore new file mode 100644 index 00000000000..170dc0f1403 --- /dev/null +++ b/frameworks/Zig/zinc/.gitignore @@ -0,0 +1,2 @@ +zig-cache/**/*', +zig-out: 'zig-out/**/*', diff --git a/frameworks/Zig/zinc/README.md b/frameworks/Zig/zinc/README.md new file mode 100755 index 00000000000..d6cf8af0cf8 --- /dev/null +++ b/frameworks/Zig/zinc/README.md @@ -0,0 +1,93 @@ +# Congratulations! + +You have successfully built a new test in the suite! + +There are some remaining tasks to do before you are ready to open a pull request, however. + +## Next Steps + +1. Gather your source code. + +You will need to ensure that your source code is beneath this directory. The most common solution is to include a `src` directory and place your source code there. + +2. Edit `benchmark_config.json` + +You will need alter `benchmark_config.json` to have the appropriate end-points and port specified. + +3. Create `zinc.dockerfile` + +This is the dockerfile that is built into a docker image and run when a benchmark test is run. Specifically, this file tells the suite how to build and start your test application. + +You can create multiple implementations and they will all conform to `[name in benchmark_config.json].dockerfile`. For example, the `default` implementation in `benchmark_config.json` will be `zinc.dockerfile`, but if you wanted to make another implementation that did only the database tests for MySQL, you could make `zinc-mysql.dockerfile` and have an entry in your `benchmark_config.json` for `zinc-mysql`. + +4. Test your application + + $ tfb --mode verify --test zinc + +This will run the suite in `verify` mode for your test. This means that no benchmarks will be captured and we will test that we can hit your implementation end-points specified by `benchmark_config.json` and that the response is correct. + +Once you are able to successfully run your test through our suite in this way **and** your test passes our validation, you may move on to the next step. + +5. Add your test to `.github/workflows/build.yml` + +Edit `.github/workflows/build.yml` to ensure that Github Actions will automatically run our verification tests against your new test. This file is kept in alphabetical order, so find where `TESTDIR=Zig/zinc` should be inserted under `env > matrix` and put it there. + +6. Fix this `README.md` and open a pull request + +Starting on line 49 is your actual `README.md` that will sit with your test implementation. Update all the dummy values to their correct values so that when people visit your test in our Github repository, they will be greated with information on how your test implementation works and where to look for useful source code. + +After you have the real `README.md` file in place, delete everything above line 59 and you are ready to open a pull request. + +Thanks and Cheers! + + + + + + + +# Zinc Benchmarking Test + +### Test Type Implementation Source Code + +* [JSON](Relative/Path/To/Your/Source/File) +* [PLAINTEXT](Relative/Path/To/Your/Source/File) +* [DB](Relative/Path/To/Your/Source/File) +* [QUERY](Relative/Path/To/Your/Source/File) +* [CACHED QUERY](Relative/Path/To/Your/Source/File) +* [UPDATE](Relative/Path/To/Your/Source/File) +* [FORTUNES](Relative/Path/To/Your/Source/File) + +## Important Libraries +The tests were run with: +* [Software](https://www.example1.com/) +* [Example](http://www.example2.com/) + +## Test URLs +### JSON + +http://localhost:8080/json + +### PLAINTEXT + +http://localhost:8080/plaintext + +### DB + +http://localhost:8080/db + +### QUERY + +http://localhost:8080/query?queries= + +### CACHED QUERY + +http://localhost:8080/cached_query?queries= + +### UPDATE + +http://localhost:8080/update?queries= + +### FORTUNES + +http://localhost:8080/fortunes diff --git a/frameworks/Zig/zinc/benchmark_config.json b/frameworks/Zig/zinc/benchmark_config.json new file mode 100755 index 00000000000..dd009267df5 --- /dev/null +++ b/frameworks/Zig/zinc/benchmark_config.json @@ -0,0 +1,26 @@ +{ + "framework": "zinc", + "tests": [ + { + "default": { + "json_url": "/json", + "plaintext_url": "/plaintext", + "port": 8080, + "approach": "Stripped", + "classification": "Fullstack", + "database": "None", + "framework": "Zinc", + "language": "Zig", + "flavor": "None", + "orm": "None", + "platform": "None", + "webserver": "None", + "os": "Linux", + "database_os": "Linux", + "display_name": "Zinc", + "notes": "", + "versus": "None" + } + } + ] +} diff --git a/frameworks/Zig/zinc/build.zig b/frameworks/Zig/zinc/build.zig new file mode 100644 index 00000000000..e5be63940e5 --- /dev/null +++ b/frameworks/Zig/zinc/build.zig @@ -0,0 +1,78 @@ +const std = @import("std"); + +// Although this function looks imperative, note that its job is to +// declaratively construct a build graph that will be executed by an external +// runner. +pub fn build(b: *std.Build) void { + // Standard target options allows the person running `zig build` to choose + // what target to build for. Here we do not override the defaults, which + // means any target is allowed, and the default is native. Other options + // for restricting supported target set are available. + const target = b.standardTargetOptions(.{}); + + // Standard optimization options allow the person running `zig build` to select + // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not + // set a preferred release mode, allowing the user to decide how to optimize. + const optimize = b.standardOptimizeOption(.{}); + + const exe = b.addExecutable(.{ + .name = "zinc", + .root_source_file = b.path("src/main.zig"), + .target = target, + .optimize = optimize, + }); + + const zinc = b.dependency("zinc", .{ + .target = target, + .optimize = optimize, + }); + exe.root_module.addImport("zinc", zinc.module("zinc")); + + const datetime = b.dependency("zig-datetime", .{ + .target = target, + .optimize = optimize, + }); + exe.root_module.addImport("datetime", datetime.module("zig-datetime")); + + // This declares intent for the executable to be installed into the + // standard location when the user invokes the "install" step (the default + // step when running `zig build`). + b.installArtifact(exe); + + // This *creates* a Run step in the build graph, to be executed when another + // step is evaluated that depends on it. The next line below will establish + // such a dependency. + const run_cmd = b.addRunArtifact(exe); + + // By making the run step depend on the install step, it will be run from the + // installation directory rather than directly from within the cache directory. + // This is not necessary, however, if the application depends on other installed + // files, this ensures they will be present and in the expected location. + run_cmd.step.dependOn(b.getInstallStep()); + + // This allows the user to pass arguments to the application in the build + // command itself, like this: `zig build run -- arg1 arg2 etc` + if (b.args) |args| { + run_cmd.addArgs(args); + } + + // This creates a build step. It will be visible in the `zig build --help` menu, + // and can be selected like this: `zig build run` + // This will evaluate the `run` step rather than the default, which is "install". + const run_step = b.step("run", "Run the app"); + run_step.dependOn(&run_cmd.step); + + const exe_unit_tests = b.addTest(.{ + .root_source_file = b.path("src/main.zig"), + .target = target, + .optimize = optimize, + }); + + const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests); + + // Similar to creating the run step earlier, this exposes a `test` step to + // the `zig build --help` menu, providing a way for the user to request + // running the unit tests. + const test_step = b.step("test", "Run unit tests"); + test_step.dependOn(&run_exe_unit_tests.step); +} diff --git a/frameworks/Zig/zinc/build.zig.zon b/frameworks/Zig/zinc/build.zig.zon new file mode 100644 index 00000000000..ba3dbe917a8 --- /dev/null +++ b/frameworks/Zig/zinc/build.zig.zon @@ -0,0 +1,19 @@ +.{ + .name = "zinc", + .version = "0.1.0", + .dependencies = .{ + .zinc = .{ + .url = "https://github.com/zon-dev/zinc/archive/refs/heads/main.zip", + .hash = "1220bbd81a53f8268d970dfbf92268c36a25b50978dd8e7dcbf551e69b2c03677e33", + }, + .@"zig-datetime" = .{ + .url = "https://github.com/frmdstryr/zig-datetime/archive/refs/heads/master.zip", + .hash = "122077215ce36e125a490e59ec1748ffd4f6ba00d4d14f7308978e5360711d72d77f", + }, + }, + .paths = .{ + "build.zig", + "build.zig.zon", + "src", + }, +} diff --git a/frameworks/Zig/zinc/run.sh b/frameworks/Zig/zinc/run.sh new file mode 100644 index 00000000000..639c542fc3e --- /dev/null +++ b/frameworks/Zig/zinc/run.sh @@ -0,0 +1,3 @@ +echo "Waiting for Zinc framework to start..." + +zinc \ No newline at end of file diff --git a/frameworks/Zig/zinc/src/main.zig b/frameworks/Zig/zinc/src/main.zig new file mode 100644 index 00000000000..cb46afc1fc5 --- /dev/null +++ b/frameworks/Zig/zinc/src/main.zig @@ -0,0 +1,38 @@ +const std = @import("std"); +const zinc = @import("zinc"); +const Datetime = @import("datetime").datetime.Datetime; + +pub fn main() !void { + var gpa = std.heap.GeneralPurposeAllocator(.{}){}; + const allocator = gpa.allocator(); + + var z = try zinc.init(.{ .port = 8080, .allocator = allocator, .num_threads = 255 }); + + var router = z.getRouter(); + try router.use(&.{setupHeader}); + + try router.get("/json", json); + try router.get("/plaintext", plaintext); + + try z.run(); +} + +fn plaintext(ctx: *zinc.Context) anyerror!void { + try ctx.text("Hello, World!", .{}); +} + +fn json(ctx: *zinc.Context) anyerror!void { + try ctx.json(.{ .message = "Hello, World!" }, .{}); +} + +fn setupHeader(ctx: *zinc.Context) anyerror!void { + try ctx.setHeader("Server", "Zinc"); + // try ctx.setHeader("date", "Sun Sep 22 10:01:11 CEST 2024"); + // In UTC + const now = Datetime.now(); + const now_str = try now.formatHttp(ctx.allocator); + // defer ctx.allocator.free(now_str); + // std.debug.warn("The time is now: {}\n", .{now_str}); + // The time is now: Fri, 20 Dec 2019 22:03:02 UTC + try ctx.setHeader("date", now_str); +} diff --git a/frameworks/Zig/zinc/zinc.dockerfile b/frameworks/Zig/zinc/zinc.dockerfile new file mode 100644 index 00000000000..80c1888aa48 --- /dev/null +++ b/frameworks/Zig/zinc/zinc.dockerfile @@ -0,0 +1,22 @@ +FROM fedora:40 AS build + +WORKDIR /zinc + +COPY src src +COPY run.sh run.sh + +COPY build.zig.zon build.zig.zon +COPY build.zig build.zig + +RUN dnf install -y zig +RUN zig version +# RUN zig build -Doptimize=ReleaseFast +RUN zig build +RUN cp /zinc/zig-out/bin/zinc /usr/local/bin + +EXPOSE 8080 +ARG BENCHMARK_ENV +ARG TFB_TEST_DATABASE +ARG TFB_TEST_NAME + +CMD ["sh", "run.sh"] From ef58fe4be484f406fb28491c4cdec21e3bbec36f Mon Sep 17 00:00:00 2001 From: dravenk Date: Sat, 28 Sep 2024 23:46:06 +0800 Subject: [PATCH 02/11] Update num_threads and fixed headers --- frameworks/Zig/zinc/build.zig.zon | 2 +- frameworks/Zig/zinc/src/main.zig | 27 ++++++++++++++++++--------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/frameworks/Zig/zinc/build.zig.zon b/frameworks/Zig/zinc/build.zig.zon index ba3dbe917a8..48436472c53 100644 --- a/frameworks/Zig/zinc/build.zig.zon +++ b/frameworks/Zig/zinc/build.zig.zon @@ -4,7 +4,7 @@ .dependencies = .{ .zinc = .{ .url = "https://github.com/zon-dev/zinc/archive/refs/heads/main.zip", - .hash = "1220bbd81a53f8268d970dfbf92268c36a25b50978dd8e7dcbf551e69b2c03677e33", + .hash = "12201f5d2138d81c9aa85bf18a550df6329d98f02645bc5f9e1eb82b2ed98d211bb6", }, .@"zig-datetime" = .{ .url = "https://github.com/frmdstryr/zig-datetime/archive/refs/heads/master.zip", diff --git a/frameworks/Zig/zinc/src/main.zig b/frameworks/Zig/zinc/src/main.zig index cb46afc1fc5..b0020058811 100644 --- a/frameworks/Zig/zinc/src/main.zig +++ b/frameworks/Zig/zinc/src/main.zig @@ -3,10 +3,21 @@ const zinc = @import("zinc"); const Datetime = @import("datetime").datetime.Datetime; pub fn main() !void { - var gpa = std.heap.GeneralPurposeAllocator(.{}){}; - const allocator = gpa.allocator(); - - var z = try zinc.init(.{ .port = 8080, .allocator = allocator, .num_threads = 255 }); + var gpa = std.heap.GeneralPurposeAllocator(.{ + .thread_safe = true, + }){}; + var tsa = std.heap.ThreadSafeAllocator{ + .child_allocator = gpa.allocator(), + }; + const allocator = tsa.allocator(); + + const cpuCount = @as(u8, @intCast(std.Thread.getCpuCount() catch 1)); + + var z = try zinc.init(.{ + .port = 8080, + .allocator = allocator, + .num_threads = 16 * cpuCount, + }); var router = z.getRouter(); try router.use(&.{setupHeader}); @@ -14,7 +25,7 @@ pub fn main() !void { try router.get("/json", json); try router.get("/plaintext", plaintext); - try z.run(); + z.run() catch |err| std.debug.print("Error: {any}\n", .{err}); } fn plaintext(ctx: *zinc.Context) anyerror!void { @@ -27,12 +38,10 @@ fn json(ctx: *zinc.Context) anyerror!void { fn setupHeader(ctx: *zinc.Context) anyerror!void { try ctx.setHeader("Server", "Zinc"); - // try ctx.setHeader("date", "Sun Sep 22 10:01:11 CEST 2024"); - // In UTC + try ctx.setHeader("Connection", "keep-alive"); + const now = Datetime.now(); const now_str = try now.formatHttp(ctx.allocator); - // defer ctx.allocator.free(now_str); - // std.debug.warn("The time is now: {}\n", .{now_str}); // The time is now: Fri, 20 Dec 2019 22:03:02 UTC try ctx.setHeader("date", now_str); } From 9a53dafdef689bcecff27caa802eb29edfe9ef3b Mon Sep 17 00:00:00 2001 From: dravenk Date: Sun, 29 Sep 2024 00:51:10 +0800 Subject: [PATCH 03/11] Update dependency --- frameworks/Zig/zinc/build.zig.zon | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/Zig/zinc/build.zig.zon b/frameworks/Zig/zinc/build.zig.zon index 48436472c53..25d5b143cb4 100644 --- a/frameworks/Zig/zinc/build.zig.zon +++ b/frameworks/Zig/zinc/build.zig.zon @@ -3,7 +3,7 @@ .version = "0.1.0", .dependencies = .{ .zinc = .{ - .url = "https://github.com/zon-dev/zinc/archive/refs/heads/main.zip", + .url = "https://github.com/zon-dev/zinc/archive/refs/tags/0.1.0-beta4.tar.gz", .hash = "12201f5d2138d81c9aa85bf18a550df6329d98f02645bc5f9e1eb82b2ed98d211bb6", }, .@"zig-datetime" = .{ From 67881e73b3b8fef25311f9a3e774feae302f228a Mon Sep 17 00:00:00 2001 From: dravenk Date: Sun, 29 Sep 2024 00:58:12 +0800 Subject: [PATCH 04/11] Update build command --- frameworks/Zig/zinc/zinc.dockerfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/frameworks/Zig/zinc/zinc.dockerfile b/frameworks/Zig/zinc/zinc.dockerfile index 80c1888aa48..244e04a6556 100644 --- a/frameworks/Zig/zinc/zinc.dockerfile +++ b/frameworks/Zig/zinc/zinc.dockerfile @@ -10,8 +10,7 @@ COPY build.zig build.zig RUN dnf install -y zig RUN zig version -# RUN zig build -Doptimize=ReleaseFast -RUN zig build +RUN zig build -Doptimize=ReleaseFast RUN cp /zinc/zig-out/bin/zinc /usr/local/bin EXPOSE 8080 From 9ae178d6e805ffb1e163fa4d81aa399f9df49758 Mon Sep 17 00:00:00 2001 From: dravenk Date: Sun, 29 Sep 2024 01:10:54 +0800 Subject: [PATCH 05/11] Update Zinc documentation --- frameworks/Zig/zinc/README.md | 93 ++++++----------------------------- 1 file changed, 16 insertions(+), 77 deletions(-) diff --git a/frameworks/Zig/zinc/README.md b/frameworks/Zig/zinc/README.md index d6cf8af0cf8..acf0f93bbcb 100755 --- a/frameworks/Zig/zinc/README.md +++ b/frameworks/Zig/zinc/README.md @@ -1,67 +1,26 @@ -# Congratulations! +# [Zinc](https://zinc.zon.dev) web framework -You have successfully built a new test in the suite! +## Description -There are some remaining tasks to do before you are ready to open a pull request, however. +Zinc is a web framework written in pure Zig with a focus on high performance, usability, security, and extensibility. -## Next Steps +* [Documentation](https://zinc.zon.dev/) -1. Gather your source code. - -You will need to ensure that your source code is beneath this directory. The most common solution is to include a `src` directory and place your source code there. - -2. Edit `benchmark_config.json` - -You will need alter `benchmark_config.json` to have the appropriate end-points and port specified. - -3. Create `zinc.dockerfile` - -This is the dockerfile that is built into a docker image and run when a benchmark test is run. Specifically, this file tells the suite how to build and start your test application. - -You can create multiple implementations and they will all conform to `[name in benchmark_config.json].dockerfile`. For example, the `default` implementation in `benchmark_config.json` will be `zinc.dockerfile`, but if you wanted to make another implementation that did only the database tests for MySQL, you could make `zinc-mysql.dockerfile` and have an entry in your `benchmark_config.json` for `zinc-mysql`. - -4. Test your application - - $ tfb --mode verify --test zinc - -This will run the suite in `verify` mode for your test. This means that no benchmarks will be captured and we will test that we can hit your implementation end-points specified by `benchmark_config.json` and that the response is correct. - -Once you are able to successfully run your test through our suite in this way **and** your test passes our validation, you may move on to the next step. - -5. Add your test to `.github/workflows/build.yml` - -Edit `.github/workflows/build.yml` to ensure that Github Actions will automatically run our verification tests against your new test. This file is kept in alphabetical order, so find where `TESTDIR=Zig/zinc` should be inserted under `env > matrix` and put it there. - -6. Fix this `README.md` and open a pull request - -Starting on line 49 is your actual `README.md` that will sit with your test implementation. Update all the dummy values to their correct values so that when people visit your test in our Github repository, they will be greated with information on how your test implementation works and where to look for useful source code. - -After you have the real `README.md` file in place, delete everything above line 59 and you are ready to open a pull request. - -Thanks and Cheers! - - - - - - - -# Zinc Benchmarking Test - -### Test Type Implementation Source Code - -* [JSON](Relative/Path/To/Your/Source/File) -* [PLAINTEXT](Relative/Path/To/Your/Source/File) -* [DB](Relative/Path/To/Your/Source/File) -* [QUERY](Relative/Path/To/Your/Source/File) -* [CACHED QUERY](Relative/Path/To/Your/Source/File) -* [UPDATE](Relative/Path/To/Your/Source/File) -* [FORTUNES](Relative/Path/To/Your/Source/File) +### Some features are: +- **Fast** +- **Custom allocator** +- **Multithreading** +- **Middleware** +- **Routes grouping** +- **Rendering built-in** +- **Extensible** +- **Suite of unit tests** +- **Usability** ## Important Libraries The tests were run with: -* [Software](https://www.example1.com/) -* [Example](http://www.example2.com/) +* [Software](https://zinc.zon.dev/) +* [Example](https://github.com/zon-dev/zinc-examples) ## Test URLs ### JSON @@ -71,23 +30,3 @@ http://localhost:8080/json ### PLAINTEXT http://localhost:8080/plaintext - -### DB - -http://localhost:8080/db - -### QUERY - -http://localhost:8080/query?queries= - -### CACHED QUERY - -http://localhost:8080/cached_query?queries= - -### UPDATE - -http://localhost:8080/update?queries= - -### FORTUNES - -http://localhost:8080/fortunes From 042f1a0bc519cf5ab741cefae406f75561342bb5 Mon Sep 17 00:00:00 2001 From: dravenk Date: Sun, 29 Sep 2024 01:20:08 +0800 Subject: [PATCH 06/11] Run workflow --- frameworks/Zig/zinc/src/main.zig | 1 + 1 file changed, 1 insertion(+) diff --git a/frameworks/Zig/zinc/src/main.zig b/frameworks/Zig/zinc/src/main.zig index b0020058811..f97e52362db 100644 --- a/frameworks/Zig/zinc/src/main.zig +++ b/frameworks/Zig/zinc/src/main.zig @@ -20,6 +20,7 @@ pub fn main() !void { }); var router = z.getRouter(); + try router.use(&.{setupHeader}); try router.get("/json", json); From b9b2a13c4b58b8d2a37db210f4b24738bc060b7d Mon Sep 17 00:00:00 2001 From: dravenk Date: Wed, 2 Oct 2024 15:42:54 +0800 Subject: [PATCH 07/11] Update Zinc approach --- frameworks/Zig/zinc/benchmark_config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/Zig/zinc/benchmark_config.json b/frameworks/Zig/zinc/benchmark_config.json index dd009267df5..0b1c6562f92 100755 --- a/frameworks/Zig/zinc/benchmark_config.json +++ b/frameworks/Zig/zinc/benchmark_config.json @@ -6,7 +6,7 @@ "json_url": "/json", "plaintext_url": "/plaintext", "port": 8080, - "approach": "Stripped", + "approach": "Realistic", "classification": "Fullstack", "database": "None", "framework": "Zinc", From 717dd389dfdc92855cb1e6fc906f40fecf985b86 Mon Sep 17 00:00:00 2001 From: dravenk Date: Wed, 9 Oct 2024 14:54:23 +0800 Subject: [PATCH 08/11] Update zinc Allocator and plaintext test --- frameworks/Zig/zinc/src/main.zig | 27 +++++++++------------------ frameworks/Zig/zinc/zinc.dockerfile | 2 +- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/frameworks/Zig/zinc/src/main.zig b/frameworks/Zig/zinc/src/main.zig index f97e52362db..5b3b0d8e4ad 100644 --- a/frameworks/Zig/zinc/src/main.zig +++ b/frameworks/Zig/zinc/src/main.zig @@ -3,34 +3,24 @@ const zinc = @import("zinc"); const Datetime = @import("datetime").datetime.Datetime; pub fn main() !void { - var gpa = std.heap.GeneralPurposeAllocator(.{ - .thread_safe = true, - }){}; - var tsa = std.heap.ThreadSafeAllocator{ - .child_allocator = gpa.allocator(), - }; - const allocator = tsa.allocator(); - - const cpuCount = @as(u8, @intCast(std.Thread.getCpuCount() catch 1)); - var z = try zinc.init(.{ - .port = 8080, - .allocator = allocator, - .num_threads = 16 * cpuCount, + .port = 3000, + .allocator = std.heap.c_allocator, + .num_threads = 16 * @as(u8, @intCast(std.Thread.getCpuCount() catch 1)), }); + defer z.deinit(); var router = z.getRouter(); - try router.use(&.{setupHeader}); - try router.get("/json", json); try router.get("/plaintext", plaintext); - z.run() catch |err| std.debug.print("Error: {any}\n", .{err}); + try z.run(); } fn plaintext(ctx: *zinc.Context) anyerror!void { - try ctx.text("Hello, World!", .{}); + try ctx.setHeader("Content-Type", "text/plain; charset=utf-8"); + try ctx.setBody("Hello, world!", .{}); } fn json(ctx: *zinc.Context) anyerror!void { @@ -39,10 +29,11 @@ fn json(ctx: *zinc.Context) anyerror!void { fn setupHeader(ctx: *zinc.Context) anyerror!void { try ctx.setHeader("Server", "Zinc"); - try ctx.setHeader("Connection", "keep-alive"); const now = Datetime.now(); const now_str = try now.formatHttp(ctx.allocator); + // defer ctx.allocator.free(now_str); + // The time is now: Fri, 20 Dec 2019 22:03:02 UTC try ctx.setHeader("date", now_str); } diff --git a/frameworks/Zig/zinc/zinc.dockerfile b/frameworks/Zig/zinc/zinc.dockerfile index 244e04a6556..bbeb5f0e80e 100644 --- a/frameworks/Zig/zinc/zinc.dockerfile +++ b/frameworks/Zig/zinc/zinc.dockerfile @@ -13,7 +13,7 @@ RUN zig version RUN zig build -Doptimize=ReleaseFast RUN cp /zinc/zig-out/bin/zinc /usr/local/bin -EXPOSE 8080 +EXPOSE 3000 ARG BENCHMARK_ENV ARG TFB_TEST_DATABASE ARG TFB_TEST_NAME From 1c93ce8fe2f3adcfbd1d5ab65e49b36a29b5382a Mon Sep 17 00:00:00 2001 From: dravenk Date: Fri, 11 Oct 2024 12:59:16 +0800 Subject: [PATCH 09/11] Update zinc dependencies --- frameworks/Zig/zinc/build.zig.zon | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/frameworks/Zig/zinc/build.zig.zon b/frameworks/Zig/zinc/build.zig.zon index 25d5b143cb4..69a132c62e2 100644 --- a/frameworks/Zig/zinc/build.zig.zon +++ b/frameworks/Zig/zinc/build.zig.zon @@ -3,13 +3,21 @@ .version = "0.1.0", .dependencies = .{ .zinc = .{ - .url = "https://github.com/zon-dev/zinc/archive/refs/tags/0.1.0-beta4.tar.gz", - .hash = "12201f5d2138d81c9aa85bf18a550df6329d98f02645bc5f9e1eb82b2ed98d211bb6", + .url = "https://github.com/zon-dev/zinc/archive/refs/tags/0.1.0-beta.5.tar.gz", + .hash = "12201444aa36b4a83f262f319e7c17ccdcff9fbde2efbeb5fc94f1a07eda0d99428e", }, .@"zig-datetime" = .{ - .url = "https://github.com/frmdstryr/zig-datetime/archive/refs/heads/master.zip", + .url = "git+https://github.com/frmdstryr/zig-datetime#70aebf28fb3e137cd84123a9349d157a74708721", .hash = "122077215ce36e125a490e59ec1748ffd4f6ba00d4d14f7308978e5360711d72d77f", }, + .pg = .{ + .url = "git+https://github.com/karlseguin/pg.zig", + .hash = "1220df8995ceea78a4a37a505fc779ded75725d0606c33fded26103953524dde1619", + }, + .mustache = .{ + .url = "git+https://github.com/batiati/mustache-zig", + .hash = "1220cd6e1b49bdd0a568682957dab9a6864554755908f7de990ec7c050f58cf41da2", + }, }, .paths = .{ "build.zig", From e34791e67b0526033bb807dbbfcea275be07caf4 Mon Sep 17 00:00:00 2001 From: dravenk Date: Fri, 11 Oct 2024 13:06:32 +0800 Subject: [PATCH 10/11] bug fix --- frameworks/Zig/zinc/build.zig.zon | 2 +- frameworks/Zig/zinc/src/main.zig | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frameworks/Zig/zinc/build.zig.zon b/frameworks/Zig/zinc/build.zig.zon index 69a132c62e2..e8d161519f9 100644 --- a/frameworks/Zig/zinc/build.zig.zon +++ b/frameworks/Zig/zinc/build.zig.zon @@ -11,7 +11,7 @@ .hash = "122077215ce36e125a490e59ec1748ffd4f6ba00d4d14f7308978e5360711d72d77f", }, .pg = .{ - .url = "git+https://github.com/karlseguin/pg.zig", + .url = "git+https://github.com/karlseguin/pg.zig#21db2306aff657802f9cb10a1e7f8fe9c33e7990", .hash = "1220df8995ceea78a4a37a505fc779ded75725d0606c33fded26103953524dde1619", }, .mustache = .{ diff --git a/frameworks/Zig/zinc/src/main.zig b/frameworks/Zig/zinc/src/main.zig index 5b3b0d8e4ad..ae1a693b2ff 100644 --- a/frameworks/Zig/zinc/src/main.zig +++ b/frameworks/Zig/zinc/src/main.zig @@ -20,7 +20,7 @@ pub fn main() !void { fn plaintext(ctx: *zinc.Context) anyerror!void { try ctx.setHeader("Content-Type", "text/plain; charset=utf-8"); - try ctx.setBody("Hello, world!", .{}); + try ctx.setBody("Hello, world!"); } fn json(ctx: *zinc.Context) anyerror!void { From 2a0167415dbec673416b8572ce297cc9a3d754ae Mon Sep 17 00:00:00 2001 From: dravenk Date: Fri, 11 Oct 2024 13:44:03 +0800 Subject: [PATCH 11/11] Fixed zinc dependencies and port --- frameworks/Zig/zinc/benchmark_config.json | 2 +- frameworks/Zig/zinc/build.zig.zon | 2 +- frameworks/Zig/zinc/src/main.zig | 6 +++++- frameworks/Zig/zinc/zinc.dockerfile | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/frameworks/Zig/zinc/benchmark_config.json b/frameworks/Zig/zinc/benchmark_config.json index 0b1c6562f92..2e2e874ba2d 100755 --- a/frameworks/Zig/zinc/benchmark_config.json +++ b/frameworks/Zig/zinc/benchmark_config.json @@ -5,7 +5,7 @@ "default": { "json_url": "/json", "plaintext_url": "/plaintext", - "port": 8080, + "port": 3000, "approach": "Realistic", "classification": "Fullstack", "database": "None", diff --git a/frameworks/Zig/zinc/build.zig.zon b/frameworks/Zig/zinc/build.zig.zon index e8d161519f9..9a4c8f302cf 100644 --- a/frameworks/Zig/zinc/build.zig.zon +++ b/frameworks/Zig/zinc/build.zig.zon @@ -15,7 +15,7 @@ .hash = "1220df8995ceea78a4a37a505fc779ded75725d0606c33fded26103953524dde1619", }, .mustache = .{ - .url = "git+https://github.com/batiati/mustache-zig", + .url = "git+https://github.com/batiati/mustache-zig#ac358646ab9e6123285b90c947ecd40f7966d531", .hash = "1220cd6e1b49bdd0a568682957dab9a6864554755908f7de990ec7c050f58cf41da2", }, }, diff --git a/frameworks/Zig/zinc/src/main.zig b/frameworks/Zig/zinc/src/main.zig index ae1a693b2ff..f06104dc4f1 100644 --- a/frameworks/Zig/zinc/src/main.zig +++ b/frameworks/Zig/zinc/src/main.zig @@ -3,9 +3,13 @@ const zinc = @import("zinc"); const Datetime = @import("datetime").datetime.Datetime; pub fn main() !void { + var gpa = std.heap.GeneralPurposeAllocator(.{ .thread_safe = true }){}; + defer _ = gpa.deinit(); + const allocator = gpa.allocator(); + var z = try zinc.init(.{ .port = 3000, - .allocator = std.heap.c_allocator, + .allocator = allocator, .num_threads = 16 * @as(u8, @intCast(std.Thread.getCpuCount() catch 1)), }); defer z.deinit(); diff --git a/frameworks/Zig/zinc/zinc.dockerfile b/frameworks/Zig/zinc/zinc.dockerfile index bbeb5f0e80e..11b64881d2c 100644 --- a/frameworks/Zig/zinc/zinc.dockerfile +++ b/frameworks/Zig/zinc/zinc.dockerfile @@ -10,7 +10,7 @@ COPY build.zig build.zig RUN dnf install -y zig RUN zig version -RUN zig build -Doptimize=ReleaseFast +RUN zig build -Doptimize=ReleaseFast RUN cp /zinc/zig-out/bin/zinc /usr/local/bin EXPOSE 3000