Skip to content

Commit

Permalink
Merge pull request #1009 from Sudha247/eio-server-bench
Browse files Browse the repository at this point in the history
Add Eio server benchmark
  • Loading branch information
mseri committed Feb 1, 2024
2 parents 9d22421 + 7458216 commit c3537be
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 1 deletion.
2 changes: 2 additions & 0 deletions cohttp-bench.opam
Expand Up @@ -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}
Expand Down
5 changes: 5 additions & 0 deletions cohttp-bench/dune
Expand Up @@ -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)
Expand Down
22 changes: 22 additions & 0 deletions 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
2 changes: 1 addition & 1 deletion cohttp-bench/latency.sh
Expand Up @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions dune-project
Expand Up @@ -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
Expand Down

0 comments on commit c3537be

Please sign in to comment.