Skip to content

Benchmark API Implementation #78

Benchmark API Implementation

Benchmark API Implementation #78

name: Benchmark API Implementation
on:
push:
branches:
- '*'
schedule:
- cron: '30 5 * * 2,4'
jobs:
benchmark:
name: Benchmark Implementation
strategy:
fail-fast: false
matrix:
node: ['16', '18', '20']
implementation: ['restify', 'plain', 'express', 'koa', 'fastify']
runson: ['ubuntu-20.04', 'ubuntu-22.04']
postgresversion: ['14.2-alpine']
# nodeImage: ['node:14-alpine', 'node:16-alpine', 'node:17-alpine']
runs-on: ${{ matrix.runson }}
services:
# label for service - since this job doesn't run in a container, this service is accessible at localhost
database:
image: postgres:${{ matrix.postgresversion }}
ports:
- 5432:5432
env:
POSTGRES_USER: acronymapi
POSTGRES_PASSWORD: password
POSTGRES_DB: defaultdb
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
# # Note - no docker backend needed, we can just run against the container
# backend:
# image: ${{ matrix.nodeImage }}
# ports:
# - 8080:8080
# options: >-
# --tty
# --workdir /app
# --name backend
# --entrypoint /bin/sh
# --volume "${{ github.workspace }}:/app"
steps:
# https://github.com/actions/checkout
- name: Checkout the commit triggering this job
uses: actions/checkout@v4
#
- name: Install Postgres Client
run: |
sudo apt-get update
sudo apt-get install --yes --no-install-recommends postgresql-client
#
- name: Initialize database with initdb
run: |
PGPASSWORD=password psql -h localhost -U acronymapi --dbname=defaultdb --file=initdb.sql
#
- name: Setup Node with npm cache
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
cache: 'npm'
#
- name: Install dependencies from package.json
run: npm install
# - name: Start backend in Docker
# uses: docker://docker
# with:
# args: >-
# docker exec --tty --detach backend sh -c "npm install && nohup npm run start:${{matrix.implementation}} >server.log 2>&1"
- name: Start backend ${{matrix.implementation}}
run: nohup npm run start:${{matrix.implementation}} >myscript.log 2>&1 &
env:
NODE_ENV: production
- name: Run benchmarks with live Postgres server
run: npm run benchmark
env:
PGUSER: acronymapi
PGPASSWORD: password
PGDATABASE: defaultdb
PGHOST: localhost
PGPORT: 5432
- name: Read out log
run: cat myscript.log