diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml new file mode 100644 index 00000000..8b883e56 --- /dev/null +++ b/.github/workflows/benchmark.yml @@ -0,0 +1,38 @@ +name: Benchmark + +on: + workflow_dispatch: + push: + +concurrency: + group: ${{ github.workflow }}-${{ github.sha }} + cancel-in-progress: true + +jobs: + benchmark: + name: Run benchmark + runs-on: ubuntu-22.04 + timeout-minutes: 60 + strategy: + fail-fast: false + matrix: + language: + - "crystal" + - "go" + - "nodejs" + - "php" + - "python" + - "python_sanic" + - "ruby" + steps: + - uses: actions/checkout@v2 + - run: echo 'Run benchmark for ISHOCON2' + - run: | + sed -i 's/python/'"$ISHOCON_APP_LANG"'/g' ./docker-compose.yml + cat ./docker-compose.yml + make build + env: + ISHOCON_APP_LANG: ${{ matrix.language }} + - run: make up && sleep 30 + - run: make bench + timeout-minutes: 5 diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..1d19f64a --- /dev/null +++ b/Makefile @@ -0,0 +1,14 @@ +common: + docker build -f docker/app/base/Dockerfile -t showwin/ishocon2_app_base:latest . + +build: common + docker compose build + +up: build + docker compose up -d + +down: + docker compose down + +bench: + docker exec -i ishocon2-bench-1 sh -c "./benchmark --ip app:443" diff --git a/doc/local_manual.md b/doc/local_manual.md index 71d526f7..7206bfea 100644 --- a/doc/local_manual.md +++ b/doc/local_manual.md @@ -43,6 +43,6 @@ $ docker exec -it ishocon2_app_1 /bin/bash ## ベンチマーカー ``` -$ docker exec -it ishocon2_bench_1 /bin/bash +$ docker exec -it ishocon2-bench-1 /bin/bash $ ./benchmark --ip app:443 # docker-compose.yml で link しているので app で到達できます ``` diff --git a/docker-compose.yml b/docker-compose.yml index d113d6fe..63abc4d3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,7 +4,10 @@ services: build: context: . dockerfile: ./docker/app/python/Dockerfile - command: tail -f /dev/null + environment: + ISHOCON_APP_LANG: "${ISHOCON_APP_LANG-python}" + command: [/home/ishocon/run.sh] + tty: true volumes: - storage_app:/var/lib/mysql - ./webapp:/home/ishocon/webapp diff --git a/docker/app/crystal/Dockerfile b/docker/app/crystal/Dockerfile index 9c8eea49..2d9397b8 100644 --- a/docker/app/crystal/Dockerfile +++ b/docker/app/crystal/Dockerfile @@ -2,10 +2,10 @@ FROM showwin/ishocon2_app_base:latest ENV APP_LANG 'Crystal' # Crystal のインストール +RUN sudo apt-get update RUN sudo apt-get install -y gnupg2 RUN curl -sL "https://keybase.io/crystal/pgp_keys.asc" | sudo apt-key add - RUN echo "deb https://dist.crystal-lang.org/apt crystal main" | sudo tee /etc/apt/sources.list.d/crystal.list -RUN sudo apt-get update RUN sudo apt install -y libssl1.0-dev crystal # アプリケーション @@ -17,6 +17,8 @@ COPY admin/config/bashrc /home/ishocon/.bashrc WORKDIR /home/ishocon EXPOSE 443 +COPY run.sh /home/ishocon/run.sh + COPY docker/app/entrypoint.sh /home/ishocon/docker/app/entrypoint.sh ENTRYPOINT ["/home/ishocon/docker/app/entrypoint.sh"] diff --git a/docker/app/entrypoint.sh b/docker/app/entrypoint.sh index 550bb516..0de1fe52 100755 --- a/docker/app/entrypoint.sh +++ b/docker/app/entrypoint.sh @@ -1,4 +1,5 @@ -#!/bin/bash +#!/bin/bash -eux + sudo service nginx start sudo service mysql start sudo chown -R mysql:mysql /var/lib/mysql /var/run/mysqld diff --git a/docker/app/go/Dockerfile b/docker/app/go/Dockerfile index 0bf5fd3e..bf6fe443 100644 --- a/docker/app/go/Dockerfile +++ b/docker/app/go/Dockerfile @@ -19,6 +19,8 @@ COPY admin/config/bashrc /home/ishocon/.bashrc WORKDIR /home/ishocon EXPOSE 443 +COPY run.sh /home/ishocon/run.sh + COPY docker/app/entrypoint.sh /home/ishocon/docker/app/entrypoint.sh ENTRYPOINT ["/home/ishocon/docker/app/entrypoint.sh"] diff --git a/docker/app/nodejs/Dockerfile b/docker/app/nodejs/Dockerfile index 66894826..0d670920 100644 --- a/docker/app/nodejs/Dockerfile +++ b/docker/app/nodejs/Dockerfile @@ -18,6 +18,8 @@ RUN cd /home/ishocon/webapp/nodejs && \ WORKDIR /home/ishocon EXPOSE 443 +COPY run.sh /home/ishocon/run.sh + COPY docker/app/entrypoint.sh /home/ishocon/docker/app/entrypoint.sh ENTRYPOINT ["/home/ishocon/docker/app/entrypoint.sh"] diff --git a/docker/app/php/Dockerfile b/docker/app/php/Dockerfile index 09e0949a..93ac966c 100644 --- a/docker/app/php/Dockerfile +++ b/docker/app/php/Dockerfile @@ -21,6 +21,8 @@ RUN cd /home/ishocon/webapp/php && \ WORKDIR /home/ishocon EXPOSE 443 +COPY run.sh /home/ishocon/run.sh + COPY docker/app/entrypoint.sh /home/ishocon/docker/app/entrypoint.sh ENTRYPOINT ["/home/ishocon/docker/app/entrypoint.sh"] diff --git a/docker/app/python/Dockerfile b/docker/app/python/Dockerfile index 0479d368..de949065 100644 --- a/docker/app/python/Dockerfile +++ b/docker/app/python/Dockerfile @@ -2,12 +2,13 @@ FROM showwin/ishocon2_app_base:latest ENV APP_LANG 'Python' # Python のインストール +RUN sudo apt-get update RUN sudo apt-get install -y zlib1g-dev RUN git clone https://github.com/pyenv/pyenv.git ~/.pyenv && \ PYENV_ROOT="$HOME/.pyenv" && PATH="$PYENV_ROOT/bin:$PATH" && \ eval "$(pyenv init -)" && \ pyenv install 3.6.5 && pyenv global 3.6.5 && \ - cd && curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py && python get-pip.py && rm get-pip.py + cd && curl https://bootstrap.pypa.io/pip/3.6/get-pip.py -o get-pip.py && python get-pip.py && rm get-pip.py # アプリケーション RUN mkdir /home/ishocon/data /home/ishocon/webapp @@ -23,6 +24,8 @@ RUN LC_ALL=C.UTF-8 && LANG=C.UTF-8 && cd /home/ishocon/webapp/python && \ WORKDIR /home/ishocon EXPOSE 443 +COPY run.sh /home/ishocon/run.sh + COPY docker/app/entrypoint.sh /home/ishocon/docker/app/entrypoint.sh ENTRYPOINT ["/home/ishocon/docker/app/entrypoint.sh"] diff --git a/docker/app/ruby/Dockerfile b/docker/app/ruby/Dockerfile index 30ab2418..1ef34865 100644 --- a/docker/app/ruby/Dockerfile +++ b/docker/app/ruby/Dockerfile @@ -2,6 +2,7 @@ FROM showwin/ishocon2_app_base:latest ENV APP_LANG 'Ruby' # Ruby のインストール +RUN sudo apt-get update RUN sudo apt-get install -y ruby-dev libmysqlclient-dev && \ git clone https://github.com/sstephenson/rbenv.git ~/.rbenv RUN PATH="$HOME/.rbenv/bin:$PATH" && \ @@ -21,6 +22,8 @@ RUN cd /home/ishocon/webapp/ruby && sudo gem install bundler -v "1.16.1" && bund WORKDIR /home/ishocon EXPOSE 443 +COPY run.sh /home/ishocon/run.sh + COPY docker/app/entrypoint.sh /home/ishocon/docker/app/entrypoint.sh ENTRYPOINT ["/home/ishocon/docker/app/entrypoint.sh"] diff --git a/docker/benchmarker/Dockerfile b/docker/benchmarker/Dockerfile index cf9ef06b..d4ae10f1 100644 --- a/docker/benchmarker/Dockerfile +++ b/docker/benchmarker/Dockerfile @@ -1,6 +1,6 @@ FROM ubuntu:18.04 -RUN apt-get update +RUN sudo apt-get update RUN apt-get install -y wget # Go のインストール diff --git a/docker/benchmarker/entrypoint.sh b/docker/benchmarker/entrypoint.sh index dd93fcbc..36679d2d 100755 --- a/docker/benchmarker/entrypoint.sh +++ b/docker/benchmarker/entrypoint.sh @@ -1,4 +1,5 @@ -#!/bin/bash +#!/bin/bash -ux + service mysql start # なぜか失敗する(調査中) chown -R mysql:mysql /var/lib/mysql /var/run/mysqld service mysql start # 正しく起動 diff --git a/run.sh b/run.sh new file mode 100755 index 00000000..2bb0b68a --- /dev/null +++ b/run.sh @@ -0,0 +1,55 @@ +#!/bin/bash -eux + +app_lang="${ISHOCON_APP_LANG}" + +if [ -z "$app_lang" ] +then + echo "ISHOCON_APP_LANG is not set" + exit 1 +fi + +check_message="start application w/ ${app_lang}..." + +echo "app_lang: $app_lang" + +function run_ruby() { + bundle install + unicorn -c unicorn_config.rb + echo "$check_message" +} + +function run_python() { + /home/ishocon/.pyenv/shims/uwsgi --ini app.ini + echo "$check_message" +} + +function run_python_sanic() { + /home/ishocon/.pyenv/shims/uwsgi --ini app.ini + echo "$check_message" +} + + +function run_go() { + go get -t -d -v ./... + go build -o webapp *.go + ./webapp + echo "$check_message" +} + +function run_php() { + sudo mv -f /etc/nginx/nginx.conf /etc/nginx/nginx.conf.orig + sudo cp webapp/php/php-nginx.conf /etc/nginx/nginx.conf + sudo service nginx reload + echo "$check_message" +} + +function run_crystal() { + shards install + crystal app.cr + echo "$check_message" +} + +echo "run $app_lang app..." +cd "/home/ishocon/webapp/$app_lang" + +"run_$app_lang"