Skip to content

Commit

Permalink
Merge pull request #3393 from opsmill/fac-bench-tool
Browse files Browse the repository at this point in the history
feat(utilities): add benchmark tool
  • Loading branch information
fatih-acar authored May 22, 2024
2 parents 6125fd0 + d7f4d8a commit d378576
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 0 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/push-bench-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
# yamllint disable rule:truthy
name: Build And Push Bench image

on:
workflow_dispatch:

env:
DOCKERFILE: "utilities/benchmark/Dockerfile"

jobs:
build:
runs-on:
group: huge-runners
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Docker Hub
uses: docker/login-action@v3
id: login
with:
registry: ${{ vars.HARBOR_HOST }}
username: ${{ secrets.HARBOR_USERNAME }}
password: ${{ secrets.HARBOR_PASSWORD }}

- name: Set docker image meta data
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ vars.HARBOR_HOST }}/opsmill/bench
tags: |
type=raw,value=latest
labels: |
org.opencontainers.image.source=opsmill/bench
flavor: |
latest=true
- name: Build and push
uses: docker/build-push-action@v5
id: push
with:
context: utilities/benchmark
file: ${{ env.DOCKERFILE }}
provenance: false # To avoid cross platform "unknown"
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
18 changes: 18 additions & 0 deletions utilities/benchmark/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM debian:bookworm-slim
ARG TARGETPLATFORM

RUN apt-get update && \
apt-get install -y curl libncurses5 unzip yq jq fio

COPY entrypoint.sh /entrypoint.sh

RUN bash -c 'curl -o pt_linux.zip https://www.passmark.com/downloads/pt_linux_$([ "$TARGETPLATFORM" == "linux/amd64" ] && echo "x64" || echo "arm64").zip' && \
unzip pt_linux.zip && \
mv PerformanceTest/pt_linux_* /usr/local/bin/pt_linux && \
rm -rf PerformanceTest pt_linux.zip && \
chmod +x /entrypoint.sh && \
apt-get autoremove -y && \
apt-get clean all && \
rm -rf /var/lib/apt/lists/*

CMD /entrypoint.sh
47 changes: 47 additions & 0 deletions utilities/benchmark/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/sh

READ_IOPS_LIMIT=5000 # neo4j requirements
WRITE_IOPS_LIMIT=5000
RAM_LIMIT=7000 # 8 GB
SINGLETHREAD_PERF_LIMIT=2000 # around 4000 on M2 Pro and CI runners https://www.cpubenchmark.net/singleThread.html

echo "Running Disk IOPS benchmark... hold on"

fio --randrepeat=1 --ioengine=libaio --direct=1 --gtod_reduce=1 --name=test --filename=randomrw.fio --bs=4k --iodepth=64 --size=128M --readwrite=randrw --rwmixread=75 --output=fio_results.json --output-format=json

READ_IOPS=$(printf "%.0f" $(jq '.jobs[0].read.iops' fio_results.json))
WRITE_IOPS=$(printf "%.0f" $(jq '.jobs[0].write.iops' fio_results.json))

echo "Running CPU/Memory benchmark... hold on"

TERM=dumb pt_linux -d 1 -r 1 -i 1 >/dev/null 2>/dev/null

TOTAL_RAM=$(yq .SystemInformation.Memory results_cpu.yml)
SINGLETHREAD_PERF=$(printf "%.0f" $(yq .Results.CPU_SINGLETHREAD results_cpu.yml))

NC='\033[0m'
RED='\033[0;31m'
GREEN='\033[0;32m'

echo ""
echo "Benchmark results:"
echo ""

[ $TOTAL_RAM -lt $RAM_LIMIT ] && echo -n $RED || echo -n $GREEN
echo -n "Memory: ${TOTAL_RAM} MB - Required: ${RAM_LIMIT} MB "
[ $TOTAL_RAM -lt $RAM_LIMIT ] && echo ": KO" || echo ": OK"

[ $SINGLETHREAD_PERF -lt $SINGLETHREAD_PERF_LIMIT ] && echo -n $RED || echo -n $GREEN
echo -n "CPU Perf: ${SINGLETHREAD_PERF} - Required: ${SINGLETHREAD_PERF_LIMIT} "
[ $SINGLETHREAD_PERF -lt $SINGLETHREAD_PERF_LIMIT ] && echo ": KO" || echo ": OK"

[ $READ_IOPS -lt $READ_IOPS_LIMIT ] && echo -n $RED || echo -n $GREEN
echo -n "Disk Read IOPS: ${READ_IOPS} - Required: ${READ_IOPS_LIMIT} "
[ $READ_IOPS -lt $READ_IOPS_LIMIT ] && echo ": KO" || echo ": OK"

[ $WRITE_IOPS -lt $WRITE_IOPS_LIMIT ] && echo -n $RED || echo -n $GREEN
echo -n "Disk Write IOPS: ${WRITE_IOPS} - Required: ${WRITE_IOPS_LIMIT} "
[ $WRITE_IOPS -lt $WRITE_IOPS_LIMIT ] && echo ": KO" || echo ": OK"

echo $NC
echo "Benchmark completed..."

0 comments on commit d378576

Please sign in to comment.