Skip to content

Add httpcats #10009

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

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
19 changes: 19 additions & 0 deletions frameworks/OCaml/httpcats/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# httpcats Benchmarking Test

### Test Type Implementation Source Code

* [JSON](httpaf_unix.ml)
* [PLAINTEXT](httpaf_unix.ml)

## Important Libraries
The tests were run with:
* [Software](https://github.com/inhabitedtype/httpaf)

## Test URLs
### JSON

http://localhost:8080/json

### PLAINTEXT

http://localhost:8080/plaintext
26 changes: 26 additions & 0 deletions frameworks/OCaml/httpcats/benchmark_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"framework": "httpcats",
"tests": [
{
"default": {
"json_url": "/json",
"plaintext_url": "/plaintext",
"port": 8080,
"approach": "Realistic",
"classification": "Platform",
"database": "None",
"framework": "None",
"language": "OCaml",
"flavor": "None",
"orm": "None",
"platform": "httpcats",
"webserver": "None",
"os": "Linux",
"database_os": "Linux",
"display_name": "httpcats",
"notes": "",
"versus": "None"
}
}
]
}
15 changes: 15 additions & 0 deletions frameworks/OCaml/httpcats/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[framework]
name = "httpcats"

[main]
urls.plaintext = "/plaintext"
urls.json = "/json"
approach = "Realistic"
classification = "Platform"
database = "None"
database_os = "Linux"
os = "Linux"
orm = "None"
platform = "httpcats"
webserver = "None"
versus = "None"
3 changes: 3 additions & 0 deletions frameworks/OCaml/httpcats/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(executable
(name server)
(libraries httpcats yojson))
1 change: 1 addition & 0 deletions frameworks/OCaml/httpcats/dune-project
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(lang dune 3.9)
22 changes: 22 additions & 0 deletions frameworks/OCaml/httpcats/httpcats.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- mode: dockerfile -*-

# https://github.com/dinosaure/techempower-ocaml-image
# Use pre-built image with all dependencies for faster test times
FROM dinosaure/techempower-ocaml-image:5.3.0

# https://caml.inria.fr/pub/docs/manual-ocaml/libref/Gc.html
# https://linux.die.net/man/1/ocamlrun
# https://blog.janestreet.com/memory-allocator-showdown/
ENV OCAMLRUNPARAM a=2,o=240

COPY . /app

WORKDIR /app

RUN \
eval $(opam env) && \
dune build --release ./server.exe

EXPOSE 8080

CMD _build/default/server.exe
101 changes: 101 additions & 0 deletions frameworks/OCaml/httpcats/server.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
(* Dates *)

let get_date () = Unix.(gettimeofday () |> gmtime)

let dow = function
| 0 -> "Sun"
| 1 -> "Mon"
| 2 -> "Tue"
| 3 -> "Wed"
| 4 -> "Thu"
| 5 -> "Fri"
| _ -> "Sat"

let month = function
| 0 -> "Jan"
| 1 -> "Feb"
| 2 -> "Mar"
| 3 -> "Apr"
| 4 -> "May"
| 5 -> "Jun"
| 6 -> "Jul"
| 7 -> "Aug"
| 8 -> "Sep"
| 9 -> "Oct"
| 10 -> "Nov"
| _ -> "Dec"

let date () =
let d = get_date () in
(* Wed, 17 Apr 2013 12:00:00 GMT *)
Format.sprintf "%s, %02d %s %4d %02d:%02d:%02d GMT" (dow d.tm_wday) d.tm_mday
(month d.tm_mon) (1900 + d.tm_year) d.tm_hour d.tm_min d.tm_sec

(* HTTP *)

let _plaintext reqd =
let open H1 in
let payload = "Hello, World!" in
let headers =
Headers.of_rev_list
[ ("content-length", string_of_int (String.length payload))
; ("content-type", "text/plain")
; ("server", "httpcats")
; ("date", date ()) ] in
let resp = Response.create ~headers `OK in
Reqd.respond_with_string reqd resp payload

let _json reqd =
let open H1 in
let obj = `Assoc [ ("message", `String "Hello, World!") ] in
let payload = Yojson.to_string obj in
let headers =
Headers.of_rev_list
[ ("content-length", string_of_int (String.length payload))
; ("content-type", "application/json")
; ("server", "httpcats")
; ("date", date ()) ] in
let resp = Response.create ~headers `OK in
Reqd.respond_with_string reqd resp payload

let _not_found reqd =
let open H1 in
let moo = "m00." in
let headers =
Headers.of_rev_list
[ "content-length", string_of_int (String.length moo) ] in
let resp = Response.create ~headers `OK in
Reqd.respond_with_string reqd resp moo

let[@warning "-8"] handler _
(`V1 reqd : [ `V1 of H1.Reqd.t | `V2 of H2.Reqd.t ]) =
let open H1 in
let request = Reqd.request reqd in
match request.Request.target with
| "/plaintext" -> _plaintext reqd
| "/json" -> _json reqd
| _ -> _not_found reqd

let localhost_8080 = Unix.(ADDR_INET (inet_addr_any, 8080))

let server stop =
Httpcats.Server.clear ~parallel:false ~stop ~backlog:4096 ~handler localhost_8080

let () = Sys.set_signal Sys.sigpipe Sys.Signal_ignore

let run () =
let domains =
Unix.open_process_in "getconf _NPROCESSORS_ONLN"
|> input_line |> int_of_string in
Miou_unix.run ~domains @@ fun () ->
let stop = Httpcats.Server.stop () in
let fn _sigint = Httpcats.Server.switch stop in
ignore (Miou.sys_signal Sys.sigint (Sys.Signal_handle fn));
let domains = Miou.Domain.available () in
let prm = Miou.async @@ fun () -> server stop in
if domains > 0 then
Miou.parallel server (List.init domains (Fun.const stop))
|> List.iter (function Ok () -> () | Error exn -> raise exn);
Miou.await_exn prm

let () = Unix.handle_unix_error run ()
20 changes: 20 additions & 0 deletions frameworks/OCaml/httpun/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# httpun Benchmarking Test

### Test Type Implementation Source Code

* [JSON](httpun_unix.ml)
* [PLAINTEXT](httpun_unix.ml)

## Important Libraries
The tests were run with:
* [HTTP library](https://github.com/anmonteiro/httpun)
* [Concurrency library](https://github.com/ocaml-multicore/eio)

## Test URLs
### JSON

http://localhost:8080/json

### PLAINTEXT

http://localhost:8080/plaintext
26 changes: 26 additions & 0 deletions frameworks/OCaml/httpun/benchmark_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"framework": "httpun",
"tests": [
{
"default": {
"json_url": "/json",
"plaintext_url": "/plaintext",
"port": 8080,
"approach": "Realistic",
"classification": "Platform",
"database": "None",
"framework": "None",
"language": "OCaml",
"flavor": "None",
"orm": "None",
"platform": "httpun",
"webserver": "None",
"os": "Linux",
"database_os": "Linux",
"display_name": "httpun",
"notes": "",
"versus": "None"
}
}
]
}
3 changes: 3 additions & 0 deletions frameworks/OCaml/httpun/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(executable
(name httpun_eio)
(libraries httpun httpun-eio eio eio_main eio_linux yojson unix))
1 change: 1 addition & 0 deletions frameworks/OCaml/httpun/dune-project
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(lang dune 3.9)
22 changes: 22 additions & 0 deletions frameworks/OCaml/httpun/httpun.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- mode: dockerfile -*-

# https://github.com/rbjorklin/techempower-ocaml-image
# Use pre-built image with all dependencies for faster test times
FROM rbjorklin/techempower-ocaml-image:5.3.0-4debebb5

# https://caml.inria.fr/pub/docs/manual-ocaml/libref/Gc.html
# https://linux.die.net/man/1/ocamlrun
# https://blog.janestreet.com/memory-allocator-showdown/
ENV OCAMLRUNPARAM="a=2,o=240"

COPY . /app

WORKDIR /app

RUN \
eval $(opam env) && \
dune build --release httpun_eio.exe

EXPOSE 8080

ENTRYPOINT ["_build/default/httpun_eio.exe"]
Loading