Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Eio server benchmark #1009

Merged
merged 2 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cohttp-bench.opam
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading