diff --git a/cohttp-bench.opam b/cohttp-bench.opam index f8eb8772e..4d2e1c565 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/cohttp-bench/dune b/cohttp-bench/dune index 1e9ad888b..39903118d 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 000000000..55dc22ac9 --- /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 4077307e4..9e9f14519 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" diff --git a/dune-project b/dune-project index 5917eeb5a..f773e761d 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