11const std = @import ("std" );
2+ const builtin = @import ("builtin" );
23const zap = @import ("zap" );
34const pg = @import ("pg" );
45const regex = @import ("regex" );
5- const dns = @import ("dns" );
66const pool = @import ("pool.zig" );
77
88const endpoints = @import ("endpoints.zig" );
@@ -23,6 +23,24 @@ pub fn main() !void {
2323
2424 const allocator = tsa .allocator ();
2525
26+ var zap_port : []u8 = undefined ;
27+ var arg_string = try std .fmt .allocPrint (allocator , "{s}" , .{"0" });
28+ defer allocator .free (arg_string );
29+
30+ var args = try std .process .argsWithAllocator (allocator );
31+ defer args .deinit ();
32+ while (args .next ()) | arg | {
33+ arg_string = try std .fmt .allocPrint (allocator , "{s}" , .{arg });
34+
35+ zap_port = arg_string ; // use arg
36+ }
37+
38+ var port = try std .fmt .parseInt (u16 , zap_port , 0 );
39+
40+ if (port == 0 ) {
41+ port = 3000 ;
42+ }
43+
2644 var pg_pool = try pool .initPool (allocator );
2745 defer pg_pool .deinit ();
2846
@@ -68,7 +86,7 @@ pub fn main() !void {
6886 var listener = try zap .Middleware .Listener (middleware .Context ).init (
6987 .{
7088 .on_request = null , // must be null
71- .port = 3000 ,
89+ .port = port ,
7290 .log = false ,
7391 .max_clients = 100000 ,
7492 },
@@ -78,13 +96,15 @@ pub fn main() !void {
7896 );
7997 try listener .listen ();
8098
81- const cpuCount = @as (i16 , @intCast (std .Thread .getCpuCount () catch 1 ));
99+ //const cpuCount = @as(i16, @intCast(std.Thread.getCpuCount() catch 1));
100+ //const workers = if (builtin.mode == .Debug) 1 else cpuCount;
101+ const threads = 128 ;
82102
83- std .debug .print ("Listening on 0.0.0.0:3000 on {d} threads\n " , .{cpuCount });
103+ std .debug .print ("Listening at 0.0.0.0:{d} on {d} threads\n " , .{port , threads });
84104
85105 // start worker threads
86106 zap .start (.{
87- .threads = 16 * cpuCount ,
107+ .threads = threads ,
88108 .workers = 1 ,
89109 });
90110}
0 commit comments