perf: use a thread pool instead

This commit is contained in:
Simon Cruanes 2021-01-27 10:28:36 -05:00
parent 21f4743320
commit 643d1573df
2 changed files with 5 additions and 2 deletions

View file

@ -2,4 +2,4 @@
(executables (executables
(names echo) (names echo)
(flags :standard -warn-error -a+8) (flags :standard -warn-error -a+8)
(libraries tiny_httpd tiny_httpd_camlzip)) (libraries tiny_httpd tiny_httpd_camlzip containers-thread))

View file

@ -2,6 +2,7 @@
module S = Tiny_httpd module S = Tiny_httpd
let () = let () =
let module TP = CCPool.Make(struct let max_size=32 end) in
let port_ = ref 8080 in let port_ = ref 8080 in
let j = ref 32 in let j = ref 32 in
Arg.parse (Arg.align [ Arg.parse (Arg.align [
@ -10,7 +11,9 @@ let () =
"--debug", Arg.Unit (fun () -> S._enable_debug true), " enable debug"; "--debug", Arg.Unit (fun () -> S._enable_debug true), " enable debug";
"-j", Arg.Set_int j, " maximum number of connections"; "-j", Arg.Set_int j, " maximum number of connections";
]) (fun _ -> raise (Arg.Bad "")) "echo [option]*"; ]) (fun _ -> raise (Arg.Bad "")) "echo [option]*";
let server = S.create ~port:!port_ ~max_connections:!j () in let server = S.create ~port:!port_ ~max_connections:!j
~new_thread:(fun task -> TP.run task)
() in
Tiny_httpd_camlzip.setup ~compress_above:1024 ~buf_size:(1024*1024) server; Tiny_httpd_camlzip.setup ~compress_above:1024 ~buf_size:(1024*1024) server;
(* say hello *) (* say hello *)
S.add_route_handler ~meth:`GET server S.add_route_handler ~meth:`GET server