Skip to content

Commit 3f3bdde

Browse files
committed
Parametrize thread count
1 parent de1339b commit 3f3bdde

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/main.zig

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
const std = @import("std");
2+
const log = std.log.scoped(.main);
3+
24
const zul = @import("zul");
35

46
const common = @import("common.zig");
@@ -20,7 +22,17 @@ pub fn main() !void {
2022
defer args.deinit();
2123

2224
const address = args.get("address") orelse "127.0.0.1";
23-
const port = try std.fmt.parseInt(u16, args.get("port") orelse "8080", 10);
2425

25-
try server.run(&index, address, port);
26+
const port_str = args.get("port") orelse "8080";
27+
const port = try std.fmt.parseInt(u16, port_str, 10);
28+
29+
_ = try std.net.Address.parseIp(address, port);
30+
31+
const threads_str = args.get("threads") orelse "0";
32+
var threads = try std.fmt.parseInt(u16, threads_str, 10);
33+
if (threads == 0) {
34+
threads = @intCast(try std.Thread.getCpuCount());
35+
}
36+
37+
try server.run(&index, address, port, threads);
2638
}

src/server.zig

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ const Context = struct {
1313
index: *Index,
1414
};
1515

16-
pub fn run(index: *Index, address: []const u8, port: u16) !void {
16+
pub fn run(index: *Index, address: []const u8, port: u16, threads: u16) !void {
1717
var ctx = Context{ .index = index };
1818

1919
const config = httpz.Config{
2020
.address = address,
2121
.port = port,
2222
.thread_pool = .{
23-
.count = @intCast(try std.Thread.getCpuCount()),
23+
.count = threads,
2424
},
2525
};
2626

0 commit comments

Comments
 (0)