Browse Source

fix: ocaml webmachine & bump to 4.12 (#6681)

Robin Björklin 4 years ago
parent
commit
80ff402b9a

+ 0 - 2
frameworks/OCaml/webmachine/haproxy.cfg

@@ -4,14 +4,12 @@ global
     maxconn     32768
     maxconn     32768
     user        haproxy
     user        haproxy
     group       haproxy
     group       haproxy
-    nbthread    2
 
 
 defaults
 defaults
     mode                    tcp
     mode                    tcp
     log                     global
     log                     global
     option                  dontlognull
     option                  dontlognull
     option http-server-close
     option http-server-close
-    option forwardfor       except 127.0.0.0/8
     option                  redispatch
     option                  redispatch
     retries                 3
     retries                 3
     timeout http-request    10s
     timeout http-request    10s

+ 10 - 10
frameworks/OCaml/webmachine/src/dune-project

@@ -11,21 +11,21 @@
  (name tfb)
  (name tfb)
  (synopsis "Rudimentary implementation of the Tech Empower Benchmark suite")
  (synopsis "Rudimentary implementation of the Tech Empower Benchmark suite")
  (depends
  (depends
-  (dune (>= 2.7.1))
-  (webmachine (>= 0.6.2))
-  (lwt (>= 5.3.0))
-  (conf-libev (>= 4-11))
-  (caqti (>= 1.2.3))
-  (caqti-lwt (>= 1.2.0))
-  (caqti-driver-postgresql (>= 1.2.4))
-  (cohttp-lwt-unix (>= 2.5.4))
-  (lwt_ppx (>= 2.0.1))))
+  (dune (>= 2.8.5))
+  (webmachine (>= 0.7.0))
+  (lwt (>= 5.4.1))
+  (conf-libev (>= 4-12))
+  (caqti (>= 1.6.0))
+  (caqti-lwt (>= 1.6.0))
+  (caqti-driver-postgresql (>= 1.6.0))
+  (cohttp-lwt-unix (>= 4.0.0))
+  (lwt_ppx (>= 2.0.2))))
 
 
 (package
 (package
  (name lib)
  (name lib)
  (synopsis "WIP library")
  (synopsis "WIP library")
  (depends
  (depends
-  (dune (>= 2.7.1))
+  (dune (>= 2.8.5))
   (biniou (>= 1.2.1))
   (biniou (>= 1.2.1))
   (yojson (>= 1.7.0))
   (yojson (>= 1.7.0))
   (atd (>= 2.2.1))
   (atd (>= 2.2.1))

+ 1 - 1
frameworks/OCaml/webmachine/src/lib.opam

@@ -6,7 +6,7 @@ license: "MIT"
 homepage: "https://github.com/TechEmpower/FrameworkBenchmarks"
 homepage: "https://github.com/TechEmpower/FrameworkBenchmarks"
 bug-reports: "https://github.com/TechEmpower/FrameworkBenchmarks/issues"
 bug-reports: "https://github.com/TechEmpower/FrameworkBenchmarks/issues"
 depends: [
 depends: [
-  "dune" {>= "2.7" & >= "2.7.1"}
+  "dune" {>= "2.7" & >= "2.8.5"}
   "biniou" {>= "1.2.1"}
   "biniou" {>= "1.2.1"}
   "yojson" {>= "1.7.0"}
   "yojson" {>= "1.7.0"}
   "atd" {>= "2.2.1"}
   "atd" {>= "2.2.1"}

+ 1 - 2
frameworks/OCaml/webmachine/src/src/bin/dune

@@ -1,6 +1,5 @@
 (executable
 (executable
- (libraries webmachine lwt cohttp-lwt-unix ptime ptime.clock ptime.clock.os
-            caqti caqti-lwt caqti-driver-postgresql yojson atdgen-runtime lib)
+ (libraries webmachine lwt cohttp-lwt-unix caqti caqti-lwt caqti-driver-postgresql yojson atdgen-runtime lib)
  (preprocess (pps lwt_ppx))
  (preprocess (pps lwt_ppx))
  (public_name tfb)
  (public_name tfb)
  (package tfb)
  (package tfb)

+ 1 - 1
frameworks/OCaml/webmachine/src/src/bin/tfb.ml

@@ -166,7 +166,7 @@ let main () =
   (* https://github.com/mirage/ocaml-cohttp/issues/328#issuecomment-222583580 *)
   (* https://github.com/mirage/ocaml-cohttp/issues/328#issuecomment-222583580 *)
   Lwt_io.set_default_buffer_size 0x10000;
   Lwt_io.set_default_buffer_size 0x10000;
   let nproc =
   let nproc =
-    match Sys.getenv "CORE_COUNT" with
+    match Sys.getenv "APP_INSTANCES" with
     | x -> int_of_string x
     | x -> int_of_string x
     | exception Not_found ->
     | exception Not_found ->
         Unix.open_process_in "getconf _NPROCESSORS_ONLN"
         Unix.open_process_in "getconf _NPROCESSORS_ONLN"

+ 9 - 9
frameworks/OCaml/webmachine/src/tfb.opam

@@ -6,15 +6,15 @@ license: "MIT"
 homepage: "https://github.com/TechEmpower/FrameworkBenchmarks"
 homepage: "https://github.com/TechEmpower/FrameworkBenchmarks"
 bug-reports: "https://github.com/TechEmpower/FrameworkBenchmarks/issues"
 bug-reports: "https://github.com/TechEmpower/FrameworkBenchmarks/issues"
 depends: [
 depends: [
-  "dune" {>= "2.7" & >= "2.7.1"}
-  "webmachine" {>= "0.6.2"}
-  "lwt" {>= "5.3.0"}
-  "conf-libev" {>= "4-11"}
-  "caqti" {>= "1.2.3"}
-  "caqti-lwt" {>= "1.2.0"}
-  "caqti-driver-postgresql" {>= "1.2.4"}
-  "cohttp-lwt-unix" {>= "2.5.4"}
-  "lwt_ppx" {>= "2.0.1"}
+  "dune" {>= "2.7" & >= "2.8.5"}
+  "webmachine" {>= "0.7.0"}
+  "lwt" {>= "5.4.1"}
+  "conf-libev" {>= "4-12"}
+  "caqti" {>= "1.6.0"}
+  "caqti-lwt" {>= "1.6.0"}
+  "caqti-driver-postgresql" {>= "1.6.0"}
+  "cohttp-lwt-unix" {>= "4.0.0"}
+  "lwt_ppx" {>= "2.0.2"}
   "odoc" {with-doc}
   "odoc" {with-doc}
 ]
 ]
 build: [
 build: [

+ 5 - 2
frameworks/OCaml/webmachine/start-servers.sh

@@ -1,10 +1,13 @@
 #!/bin/sh
 #!/bin/sh
 
 
+CMD=$1
 CPU_COUNT=$(nproc)
 CPU_COUNT=$(nproc)
 P=9000
 P=9000
 END=$(($P+$CPU_COUNT))
 END=$(($P+$CPU_COUNT))
 
 
 while [ $P -lt $END ]; do
 while [ $P -lt $END ]; do
-  PORT=$P /webmachine/_build/default/src/bin/tfb.exe &
-  let P=P+1
+  PORT=$P $CMD &
+  P=$((P+1))
 done
 done
+sleep 2
+exec /usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid

+ 29 - 9
frameworks/OCaml/webmachine/webmachine-flambda.dockerfile

@@ -1,6 +1,6 @@
-FROM ocurrent/opam:debian-10-ocaml-4.11-flambda
+FROM ocaml/opam:debian-10-ocaml-4.12-flambda
 
 
-ENV DIR webmachine
+ENV DIR project
 # https://blog.packagecloud.io/eng/2017/02/21/set-environment-variable-save-thousands-of-system-calls/
 # https://blog.packagecloud.io/eng/2017/02/21/set-environment-variable-save-thousands-of-system-calls/
 ENV TZ  :/etc/localtime
 ENV TZ  :/etc/localtime
 
 
@@ -9,19 +9,39 @@ ENV TZ  :/etc/localtime
 # https://blog.janestreet.com/memory-allocator-showdown/
 # https://blog.janestreet.com/memory-allocator-showdown/
 ENV OCAMLRUNPARAM a=2,o=240
 ENV OCAMLRUNPARAM a=2,o=240
 
 
-RUN sudo apt-get install -y libpq-dev libev-dev pkg-config m4
+ENV PKGS="\
+atdgen>=2.2.1 \
+atdgen-runtime>=2.2.1 \
+caqti>=1.6.0 \
+caqti-driver-postgresql>=1.6.0 \
+caqti-lwt>=1.6.0 \
+cohttp-lwt-unix>=4.0.0 \
+conf-libev>=4-12 \
+dune>=2.8.5 \
+httpaf>=0.7.1 \
+httpaf-lwt-unix>=0.7.1 \
+lwt>=5.4.1 \
+lwt_ppx>=2.0.2 \
+opium>=0.20.0 \
+ppx_deriving_yojson>=3.6.1 \
+ppx_rapper>=3.0.0 \
+tiny_httpd>=0.8 \
+tyxml>=4.5.0 \
+webmachine>=0.7.0 \
+yojson>=1.7.0 \
+"
+
+RUN \
+  opam update && \
+  opam depext $PKGS && \
+  opam install $PKGS
 
 
 WORKDIR /${DIR}
 WORKDIR /${DIR}
 
 
-COPY src/tfb.opam src/Makefile /${DIR}/
-COPY src/lib.opam src/Makefile /${DIR}/
-
-RUN make install
-
 COPY ./src /${DIR}
 COPY ./src /${DIR}
 
 
 RUN sudo chown -R opam: . && make build
 RUN sudo chown -R opam: . && make build
 
 
 EXPOSE 8080
 EXPOSE 8080
 
 
-ENTRYPOINT _build/default/src/bin/tfb.exe
+ENTRYPOINT ["_build/default/src/bin/tfb.exe"]

+ 39 - 15
frameworks/OCaml/webmachine/webmachine-haproxy.dockerfile

@@ -1,6 +1,6 @@
-FROM ocurrent/opam:fedora-32-ocaml-4.11
+FROM ocaml/opam:debian-10-ocaml-4.12
 
 
-ENV DIR webmachine
+ENV DIR project
 # https://blog.packagecloud.io/eng/2017/02/21/set-environment-variable-save-thousands-of-system-calls/
 # https://blog.packagecloud.io/eng/2017/02/21/set-environment-variable-save-thousands-of-system-calls/
 ENV TZ  :/etc/localtime
 ENV TZ  :/etc/localtime
 
 
@@ -8,28 +8,52 @@ ENV TZ  :/etc/localtime
 # https://linux.die.net/man/1/ocamlrun
 # https://linux.die.net/man/1/ocamlrun
 # https://blog.janestreet.com/memory-allocator-showdown/
 # https://blog.janestreet.com/memory-allocator-showdown/
 ENV OCAMLRUNPARAM a=2,o=240
 ENV OCAMLRUNPARAM a=2,o=240
-# This makes the program only spawn one child process to serve requests
-ENV CORE_COUNT 1
 
 
-RUN sudo dnf install --assumeyes diffutils postgresql-devel libev-devel
+ENV PKGS="\
+atdgen>=2.2.1 \
+atdgen-runtime>=2.2.1 \
+caqti>=1.6.0 \
+caqti-driver-postgresql>=1.6.0 \
+caqti-lwt>=1.6.0 \
+cohttp-lwt-unix>=4.0.0 \
+conf-libev>=4-12 \
+dune>=2.8.5 \
+httpaf>=0.7.1 \
+httpaf-lwt-unix>=0.7.1 \
+lwt>=5.4.1 \
+lwt_ppx>=2.0.2 \
+opium>=0.20.0 \
+ppx_deriving_yojson>=3.6.1 \
+ppx_rapper>=3.0.0 \
+tiny_httpd>=0.8 \
+tyxml>=4.5.0 \
+webmachine>=0.7.0 \
+yojson>=1.7.0 \
+"
+
+RUN \
+  opam update && \
+  opam depext $PKGS && \
+  opam install $PKGS
 
 
 WORKDIR /${DIR}
 WORKDIR /${DIR}
 
 
-COPY src/tfb.opam src/Makefile /${DIR}/
-COPY src/lib.opam src/Makefile /${DIR}/
-
-RUN make install
-
 COPY ./src /${DIR}
 COPY ./src /${DIR}
 
 
 RUN sudo chown -R opam: . && make build
 RUN sudo chown -R opam: . && make build
 
 
+EXPOSE 8080
+
 # try to keep everything above here in sync with other dockerfiles in project for more efficent use of docker build cache
 # try to keep everything above here in sync with other dockerfiles in project for more efficent use of docker build cache
-RUN sudo dnf install --assumeyes haproxy
+
+# This makes the program only spawn one child process to serve requests
+ENV APP_INSTANCES 1
+
+USER root
+
+RUN apt-get update && apt-get install -y haproxy
 COPY haproxy.cfg /etc/haproxy/haproxy.cfg
 COPY haproxy.cfg /etc/haproxy/haproxy.cfg
 COPY start-servers.sh ./start-servers.sh
 COPY start-servers.sh ./start-servers.sh
-RUN sudo chown -R opam: . && chmod +x ./start-servers.sh
-
-EXPOSE 8080
+RUN chown -R opam: . && chmod +x ./start-servers.sh
 
 
-ENTRYPOINT ./start-servers.sh && sudo /usr/sbin/haproxy -W -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid
+ENTRYPOINT ["/project/start-servers.sh", "_build/default/src/bin/tfb.exe"]

+ 29 - 9
frameworks/OCaml/webmachine/webmachine.dockerfile

@@ -1,6 +1,6 @@
-FROM ocurrent/opam:fedora-32-ocaml-4.11
+FROM ocaml/opam:debian-10-ocaml-4.12
 
 
-ENV DIR webmachine
+ENV DIR project
 # https://blog.packagecloud.io/eng/2017/02/21/set-environment-variable-save-thousands-of-system-calls/
 # https://blog.packagecloud.io/eng/2017/02/21/set-environment-variable-save-thousands-of-system-calls/
 ENV TZ  :/etc/localtime
 ENV TZ  :/etc/localtime
 
 
@@ -9,19 +9,39 @@ ENV TZ  :/etc/localtime
 # https://blog.janestreet.com/memory-allocator-showdown/
 # https://blog.janestreet.com/memory-allocator-showdown/
 ENV OCAMLRUNPARAM a=2,o=240
 ENV OCAMLRUNPARAM a=2,o=240
 
 
-RUN sudo dnf install --assumeyes diffutils postgresql-devel libev-devel
+ENV PKGS="\
+atdgen>=2.2.1 \
+atdgen-runtime>=2.2.1 \
+caqti>=1.6.0 \
+caqti-driver-postgresql>=1.6.0 \
+caqti-lwt>=1.6.0 \
+cohttp-lwt-unix>=4.0.0 \
+conf-libev>=4-12 \
+dune>=2.8.5 \
+httpaf>=0.7.1 \
+httpaf-lwt-unix>=0.7.1 \
+lwt>=5.4.1 \
+lwt_ppx>=2.0.2 \
+opium>=0.20.0 \
+ppx_deriving_yojson>=3.6.1 \
+ppx_rapper>=3.0.0 \
+tiny_httpd>=0.8 \
+tyxml>=4.5.0 \
+webmachine>=0.7.0 \
+yojson>=1.7.0 \
+"
+
+RUN \
+  opam update && \
+  opam depext $PKGS && \
+  opam install $PKGS
 
 
 WORKDIR /${DIR}
 WORKDIR /${DIR}
 
 
-COPY src/tfb.opam src/Makefile /${DIR}/
-COPY src/lib.opam src/Makefile /${DIR}/
-
-RUN make install
-
 COPY ./src /${DIR}
 COPY ./src /${DIR}
 
 
 RUN sudo chown -R opam: . && make build
 RUN sudo chown -R opam: . && make build
 
 
 EXPOSE 8080
 EXPOSE 8080
 
 
-ENTRYPOINT _build/default/src/bin/tfb.exe
+ENTRYPOINT ["_build/default/src/bin/tfb.exe"]