From 5c2e34eef692d2f1084faeead851ace2e7aa5cd7 Mon Sep 17 00:00:00 2001 From: therealgaxbo <9946712+therealgaxbo@users.noreply.github.com> Date: Sat, 18 Jun 2022 19:24:46 +0100 Subject: [PATCH 1/3] Run pv inside docker container instead of the host Piping the fizzbuzz output to the host for measurement is bad for performance, especially as by default every line will also go to journald. --- submissions/php/no_gravity_multi/Dockerfile | 3 ++- submissions/php/no_gravity_multi/Makefile | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/submissions/php/no_gravity_multi/Dockerfile b/submissions/php/no_gravity_multi/Dockerfile index 85de66c..7175c1d 100644 --- a/submissions/php/no_gravity_multi/Dockerfile +++ b/submissions/php/no_gravity_multi/Dockerfile @@ -6,7 +6,8 @@ RUN apt-get install -y \ zlib1g-dev \ libpng-dev \ libfreetype6-dev \ - libjpeg62-turbo-dev + libjpeg62-turbo-dev \ + pv RUN docker-php-ext-configure gd --with-freetype --with-jpeg diff --git a/submissions/php/no_gravity_multi/Makefile b/submissions/php/no_gravity_multi/Makefile index e557a10..b5f8139 100644 --- a/submissions/php/no_gravity_multi/Makefile +++ b/submissions/php/no_gravity_multi/Makefile @@ -4,8 +4,8 @@ docker_build: .PHONY: run run: docker_build - docker run -v $(PWD):/work php php /work/fizzbuzz.php | pv --force > /dev/null + docker run -v $(CURDIR):/work:Z -it --rm --log-driver=none php bash -c 'php work/fizzbuzz.php | pv --force > /dev/null' .PHONY: output output: docker_build - docker run -v $(PWD):/work php php /work/fizzbuzz.php + docker run -v $(CURDIR):/work:Z -it --rm --log-driver=none php php work/fizzbuzz.php From 330bcee3449648c97082140a8ceb5b9435f1398b Mon Sep 17 00:00:00 2001 From: therealgaxbo <9946712+therealgaxbo@users.noreply.github.com> Date: Sat, 18 Jun 2022 19:30:34 +0100 Subject: [PATCH 2/3] Don't use ZTS build of PHP. Enable opcacheJIT compiler. ZTS builds are only needed when running in a multithreaded SAPI and have a performance penalty. --- submissions/php/no_gravity_multi/Dockerfile | 20 +++++++------------- submissions/php/no_gravity_multi/Makefile | 4 ++-- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/submissions/php/no_gravity_multi/Dockerfile b/submissions/php/no_gravity_multi/Dockerfile index 7175c1d..999298d 100644 --- a/submissions/php/no_gravity_multi/Dockerfile +++ b/submissions/php/no_gravity_multi/Dockerfile @@ -1,17 +1,11 @@ -FROM php:8.1-zts-buster +FROM php:8.1-cli RUN apt-get update -RUN apt-get install -y \ - zlib1g-dev \ - libpng-dev \ - libfreetype6-dev \ - libjpeg62-turbo-dev \ - pv +RUN apt-get install -y pv -RUN docker-php-ext-configure gd --with-freetype --with-jpeg - -RUN docker-php-ext-install -j$(nproc) sysvsem -RUN docker-php-ext-install -j$(nproc) sysvshm -RUN docker-php-ext-install -j$(nproc) sysvmsg -RUN docker-php-ext-install -j$(nproc) pcntl +RUN docker-php-ext-install -j$(nproc) sysvsem sysvshm sysvshm pcntl opcache +#RUN docker-php-ext-install -j$(nproc) sysvsem +#RUN docker-php-ext-install -j$(nproc) sysvshm +#RUN docker-php-ext-install -j$(nproc) pcntl +#RUN docker-php-ext-install -j$(nproc) opcache diff --git a/submissions/php/no_gravity_multi/Makefile b/submissions/php/no_gravity_multi/Makefile index b5f8139..48f7052 100644 --- a/submissions/php/no_gravity_multi/Makefile +++ b/submissions/php/no_gravity_multi/Makefile @@ -4,8 +4,8 @@ docker_build: .PHONY: run run: docker_build - docker run -v $(CURDIR):/work:Z -it --rm --log-driver=none php bash -c 'php work/fizzbuzz.php | pv --force > /dev/null' + docker run -v $(CURDIR):/work:Z -it --rm --log-driver=none php bash -c 'php -d opcache.enable_cli=1 -d opcache.jit_buffer_size=64M work/fizzbuzz.php | pv --force > /dev/null' .PHONY: output output: docker_build - docker run -v $(CURDIR):/work:Z -it --rm --log-driver=none php php work/fizzbuzz.php + docker run -v $(CURDIR):/work:Z -it --rm --log-driver=none php php -d opcache.enable_cli=1 -d opcache.jit_buffer_size=64M work/fizzbuzz.php From c6c50dc0b1968f826fee265c1b24d0750c915598 Mon Sep 17 00:00:00 2001 From: therealgaxbo <9946712+therealgaxbo@users.noreply.github.com> Date: Mon, 20 Jun 2022 12:17:11 +0100 Subject: [PATCH 3/3] Make docker play well with score.py The docker container runs in its own process group so score.py does not kill it. Work around this by trapping EXIT and killing the container directly. --- submissions/php/no_gravity_multi/Makefile | 2 +- submissions/php/no_gravity_multi/start-container.sh | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100755 submissions/php/no_gravity_multi/start-container.sh diff --git a/submissions/php/no_gravity_multi/Makefile b/submissions/php/no_gravity_multi/Makefile index 48f7052..d285cf8 100644 --- a/submissions/php/no_gravity_multi/Makefile +++ b/submissions/php/no_gravity_multi/Makefile @@ -4,7 +4,7 @@ docker_build: .PHONY: run run: docker_build - docker run -v $(CURDIR):/work:Z -it --rm --log-driver=none php bash -c 'php -d opcache.enable_cli=1 -d opcache.jit_buffer_size=64M work/fizzbuzz.php | pv --force > /dev/null' + ./start-container.sh .PHONY: output output: docker_build diff --git a/submissions/php/no_gravity_multi/start-container.sh b/submissions/php/no_gravity_multi/start-container.sh new file mode 100755 index 0000000..7d34629 --- /dev/null +++ b/submissions/php/no_gravity_multi/start-container.sh @@ -0,0 +1,3 @@ +#!/bin/sh +trap 'docker kill no_gravity_multi' EXIT +docker run -v `pwd`:/work:Z --name no_gravity_multi -it --rm -log-driver=none php bash -c 'php -d opcache.enable_cli=1 -d opcache.jit_buffer_size=64M work/fizzbuzz.php | pv > /dev/null' >&2