From 87b3713632556fca9af05df84832c4c88d7b4224 Mon Sep 17 00:00:00 2001 From: Sudha Parimala Date: Fri, 24 Nov 2023 15:37:34 +0530 Subject: [PATCH 1/2] Add eio_server benchmark --- cohttp-bench/dune | 5 +++++ cohttp-bench/eio_server.ml | 22 ++++++++++++++++++++++ cohttp-bench/latency.sh | 2 +- 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 cohttp-bench/eio_server.ml diff --git a/cohttp-bench/dune b/cohttp-bench/dune index 1e9ad888b7..39903118d7 100644 --- a/cohttp-bench/dune +++ b/cohttp-bench/dune @@ -13,6 +13,11 @@ (modules async_server) (libraries cohttp-async core_unix.command_unix logs.fmt fmt.tty)) +(executable + (name eio_server) + (modules eio_server) + (libraries cohttp-eio eio_main)) + (rule (alias bench) (package cohttp-bench) diff --git a/cohttp-bench/eio_server.ml b/cohttp-bench/eio_server.ml new file mode 100644 index 0000000000..55dc22ac9f --- /dev/null +++ b/cohttp-bench/eio_server.ml @@ -0,0 +1,22 @@ +open Cohttp_eio + +let length = 2053 +let text = String.make length 'a' +let headers = Cohttp.Header.of_list [ ("content-length", Int.to_string length) ] + +let server_callback _conn _req _body = + Server.respond_string ~headers ~status:`OK ~body:text () + + +let () = + let port = ref 8080 in + Arg.parse + [ ("-p", Arg.Set_int port, " Listening port number(8080 by default)") ] + ignore "An HTTP/1.1 server"; + Eio_main.run @@ fun env -> + Eio.Switch.run @@ fun sw -> + let socket = + Eio.Net.listen env#net ~sw ~backlog:11_000 ~reuse_addr:true + (`Tcp (Eio.Net.Ipaddr.V4.loopback, !port)) + and server = Cohttp_eio.Server.make ~callback:server_callback () in + Cohttp_eio.Server.run socket server ~on_error:raise diff --git a/cohttp-bench/latency.sh b/cohttp-bench/latency.sh index 4077307e4f..9e9f145196 100755 --- a/cohttp-bench/latency.sh +++ b/cohttp-bench/latency.sh @@ -4,7 +4,7 @@ set -xe rm -rf output/* mkdir -p output -for cmd in "lwt_unix_server" "async_server" "lwt_unix_server_new"; do +for cmd in "lwt_unix_server" "async_server" "lwt_unix_server_new" "eio_server"; do ./$cmd.exe & running_pid=$! echo "Measuring latency of $cmd" From 74582165dd7e5be4df413d79b716b161039400d3 Mon Sep 17 00:00:00 2001 From: Marcello Seri Date: Thu, 1 Feb 2024 10:01:47 +0100 Subject: [PATCH 2/2] update cohttp-bench opam file --- cohttp-bench.opam | 2 ++ dune-project | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/cohttp-bench.opam b/cohttp-bench.opam index f8eb8772e8..4d2e1c565e 100644 --- a/cohttp-bench.opam +++ b/cohttp-bench.opam @@ -26,8 +26,10 @@ depends: [ "dune" {>= "3.0"} "core" {>= "v0.13.0"} "core_bench" + "eio" {>= "0.12"} "http" {= version} "cohttp" {= version} + "cohttp-eio" {= version} "cohttp-lwt-unix" {= version} "cohttp-server-lwt-unix" {= version} "cohttp-async" {= version} diff --git a/dune-project b/dune-project index 5917eeb5ad..f773e761df 100644 --- a/dune-project +++ b/dune-project @@ -346,10 +346,14 @@ (core (>= v0.13.0)) core_bench + (eio + (>= 0.12)) (http (= :version)) (cohttp (= :version)) + (cohttp-eio + (= :version)) (cohttp-lwt-unix (= :version)) (cohttp-server-lwt-unix