From 643d1573df80f58570e30e2fb5db8f2e1b7d9c5a Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Wed, 27 Jan 2021 10:28:36 -0500 Subject: [PATCH] perf: use a thread pool instead --- src/examples/dune | 2 +- src/examples/echo.ml | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/examples/dune b/src/examples/dune index 409ea47e..b731a63a 100644 --- a/src/examples/dune +++ b/src/examples/dune @@ -2,4 +2,4 @@ (executables (names echo) (flags :standard -warn-error -a+8) - (libraries tiny_httpd tiny_httpd_camlzip)) + (libraries tiny_httpd tiny_httpd_camlzip containers-thread)) diff --git a/src/examples/echo.ml b/src/examples/echo.ml index 3b7c7700..384698f3 100644 --- a/src/examples/echo.ml +++ b/src/examples/echo.ml @@ -2,6 +2,7 @@ module S = Tiny_httpd let () = + let module TP = CCPool.Make(struct let max_size=32 end) in let port_ = ref 8080 in let j = ref 32 in Arg.parse (Arg.align [ @@ -10,7 +11,9 @@ let () = "--debug", Arg.Unit (fun () -> S._enable_debug true), " enable debug"; "-j", Arg.Set_int j, " maximum number of connections"; ]) (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; (* say hello *) S.add_route_handler ~meth:`GET server