This commit is contained in:
swrup 2025-11-11 02:07:51 +01:00
parent aa2ff7b2f0
commit 2f3113f55d
11742 changed files with 1223940 additions and 0 deletions

View file

@ -0,0 +1,20 @@
(executable
(name wrk_async_benchmark)
(modules wrk_async_benchmark)
(libraries
httpun
httpun_examples
httpun-async
async
core
core_unix.command_unix))
(executable
(name wrk_lwt_benchmark)
(modules Wrk_lwt_benchmark)
(libraries httpun httpun_examples httpun-lwt-unix lwt.unix base))
(alias
(name benchmarks)
(deps
(glob_files *.exe)))

View file

@ -0,0 +1,29 @@
open Core
open Async
open Httpun_async
let main port max_accepts_per_batch () =
let where_to_listen = Tcp.Where_to_listen.of_port port in
let request_handler _ = Httpun_examples.Server.benchmark in
let error_handler _ = Httpun_examples.Server.error_handler in
Tcp.(Server.create_sock ~on_handler_error:`Ignore
~backlog:11_000 ~max_connections:10_000 ~max_accepts_per_batch where_to_listen)
(Server.create_connection_handler ~request_handler ~error_handler)
>>= fun server ->
Deferred.forever () (fun () ->
Clock.after Time_float.Span.(of_sec 0.5) >>| fun () ->
Log.Global.printf "conns: %d" (Tcp.Server.num_connections server));
Deferred.never ()
let () =
Command.async
~summary:"Start a hello world Async server"
Command.Param.(
map (both
(flag "-p" (optional_with_default 8080 int)
~doc:"int Source port to listen on")
(flag "-a" (optional_with_default 1 int)
~doc:"int Maximum accepts per batch"))
~f:(fun (port, accepts) ->
(fun () -> main port accepts ())))
|> Command_unix.run

View file

@ -0,0 +1,28 @@
open Base
open Httpun_lwt_unix
module Arg = Stdlib.Arg
let main port =
let open Lwt.Infix in
let listen_address = Unix.(ADDR_INET (inet_addr_loopback, port)) in
let request_handler _ = Httpun_examples.Server.benchmark in
let error_handler _ = Httpun_examples.Server.error_handler in
Lwt.async begin fun () ->
Lwt_io.establish_server_with_client_socket
~backlog:11_000
listen_address
(Server.create_connection_handler ~request_handler ~error_handler)
>>= fun _server -> Lwt.return_unit
end;
let forever, _ = Lwt.wait () in
Lwt_main.run forever
;;
let () =
let port = ref 8080 in
Arg.parse
["-p", Arg.Set_int port, " Listening port number (8080 by default)"]
ignore
"Responds to requests with a fixed string for benchmarking purposes.";
main !port
;;