mirror of
https://github.com/c-cube/tiny_httpd.git
synced 2025-12-06 03:05:29 -05:00
wip: try jemalloc
This commit is contained in:
parent
64e232e459
commit
66c4525726
3 changed files with 25 additions and 5 deletions
|
|
@ -796,7 +796,7 @@ let run (self:t) : (unit,_) result =
|
||||||
with e ->
|
with e ->
|
||||||
Sem_.release self.sem_max_connections;
|
Sem_.release self.sem_max_connections;
|
||||||
close_();
|
close_();
|
||||||
raise e
|
_debug (fun k->k "error in thread: %s" (Printexc.to_string e));
|
||||||
);
|
);
|
||||||
done;
|
done;
|
||||||
Ok ()
|
Ok ()
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
|
|
||||||
(executables
|
(executables
|
||||||
(names echo)
|
(names echo)
|
||||||
(libraries tiny_httpd statmemprof-notty))
|
(libraries tiny_httpd containers.thread jemalloc))
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,23 @@
|
||||||
|
|
||||||
module S = Tiny_httpd
|
module S = Tiny_httpd
|
||||||
|
|
||||||
|
(*
|
||||||
|
open Jemalloc
|
||||||
|
|
||||||
|
let show_crt_info () =
|
||||||
|
let b = string_of_int in
|
||||||
|
try
|
||||||
|
let memory = get_memory_stats () in
|
||||||
|
Printf.sprintf "MALLOC: size %s, used %s, heap %s, free %s" (b memory.mapped) (b memory.active) (b memory.allocated) (b (memory.mapped - memory.active))
|
||||||
|
with exn ->
|
||||||
|
Printf.sprintf "MALLOC:? (error %s)" (Printexc.to_string exn)
|
||||||
|
|
||||||
|
let setup () =
|
||||||
|
Memory.show_crt_info := show_crt_info;
|
||||||
|
Memory.malloc_release := release_free_memory;
|
||||||
|
()
|
||||||
|
*)
|
||||||
|
|
||||||
let () =
|
let () =
|
||||||
let port_ = ref 8080 in
|
let port_ = ref 8080 in
|
||||||
let j = ref 32 in
|
let j = ref 32 in
|
||||||
|
|
@ -10,7 +27,10 @@ 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 module P = CCPool.Make(struct let max_size = 30 end) in *)
|
||||||
|
let server = S.create ~port:!port_ ~max_connections:!j
|
||||||
|
(* ~new_thread:P.run *)
|
||||||
|
() in
|
||||||
(* say hello *)
|
(* say hello *)
|
||||||
S.add_path_handler ~meth:`GET server
|
S.add_path_handler ~meth:`GET server
|
||||||
"/hello/%s@/" (fun name _req -> S.Response.make_string (Ok ("hello " ^name ^"!\n")));
|
"/hello/%s@/" (fun name _req -> S.Response.make_string (Ok ("hello " ^name ^"!\n")));
|
||||||
|
|
@ -20,7 +40,7 @@ let () =
|
||||||
S.add_path_handler ~meth:`POST server
|
S.add_path_handler ~meth:`POST server
|
||||||
"/debug/%B" (fun b _req -> S._enable_debug b; S.Response.make_string (Ok "ok"));
|
"/debug/%B" (fun b _req -> S._enable_debug b; S.Response.make_string (Ok "ok"));
|
||||||
S.add_path_handler ~meth:`POST server
|
S.add_path_handler ~meth:`POST server
|
||||||
"/compact/" (fun _req -> Gc.compact(); S.Response.make_string (Ok "gc.compact: done"));
|
"/compact/" (fun _req -> Gc.compact(); Jemalloc.release_free_memory(); S.Response.make_string (Ok "gc.compact: done"));
|
||||||
S.add_path_handler ~meth:`POST server
|
S.add_path_handler ~meth:`POST server
|
||||||
"/quit/" (fun _req -> S.stop server; S.Response.make_string (Ok "bye"));
|
"/quit/" (fun _req -> S.stop server; S.Response.make_string (Ok "bye"));
|
||||||
S.add_path_handler ~meth:`PUT server
|
S.add_path_handler ~meth:`PUT server
|
||||||
|
|
@ -35,7 +55,7 @@ let () =
|
||||||
S.Response.fail ~code:500 "couldn't upload file: %s" (Printexc.to_string e)
|
S.Response.fail ~code:500 "couldn't upload file: %s" (Printexc.to_string e)
|
||||||
);
|
);
|
||||||
Printf.printf "listening on http://%s:%d\n%!" (S.addr server) (S.port server);
|
Printf.printf "listening on http://%s:%d\n%!" (S.addr server) (S.port server);
|
||||||
ignore @@ Thread.create (fun () -> Statmemprof_inuit.start 1e-4 300 2) ();
|
(* ignore @@ Thread.create (fun () -> Statmemprof_inuit.start 1e-4 300 2) (); *)
|
||||||
match S.run server with
|
match S.run server with
|
||||||
| Ok () -> ()
|
| Ok () -> ()
|
||||||
| Error e -> raise e
|
| Error e -> raise e
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue