Skip to content

Commit

Permalink
benchmark info logs in the CI
Browse files Browse the repository at this point in the history
  • Loading branch information
Keksoj committed Feb 14, 2024
1 parent e451177 commit d8c33f9
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 4 deletions.
69 changes: 69 additions & 0 deletions .github/workflows/bench_logs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import subprocess
import logging
import time
import os

class Row(object):
def __init__(self, color, target, iterations, level, time):
self.color = color
self.target = target
self.iterations = iterations
self.level = level
self.time = time

def __repr__(self):
return f"| {self.color!s: <6} | {self.target: <8} | {self.iterations: <10} | {self.level: <8}| {self.time: <8.4f}"

def print_results(result_rows):
print(f"| color | target | iterations | level | time (s)")

for row in result_rows:
print(row)

def bench_logs(color: bool, target: str, iterations: int, level: str) -> Row:
logging.info("🎯 Initalize environnment")

start = time.time()

env = {}
env['BENCH_LOG_COLOR'] = str(color)
env['BENCH_LOG_TARGET'] = target
env['BENCH_LOG_ITERS'] = str(iterations)
env['BENCH_LOG_FILTER'] = level

try:
bench_process = subprocess.Popen(
["./bench_logger"],
stdout=subprocess.DEVNULL,
env=env
)

stdout, stderr = bench_process.communicate()

if stderr:
logging.error(stderr.decode())

except subprocess.CalledProcessError as e:
logging.error(f"🚨 Command failed with return code {e.returncode}")

elapsed_time = time.time() - start

try:
subprocess.run(["kill", str(bench_process.pid)])
except subprocess.CalledProcessError as e:
logging.error(f"🚨 Failed to destroy environnement {e.returncode}")

return Row(color, target, iterations, level, elapsed_time)


logging.basicConfig(encoding='utf-8', level=logging.INFO)
logging.info("💣 Launching benchmark")

result_rows = [
bench_logs(True, "stdout", 1000000, "debug"),
bench_logs(True, "stdout", 1000000, "trace"),
bench_logs(True, "udp", 1000000, "debug"),
bench_logs(True, "udp", 1000000, "trace")
]

print_results(result_rows)
29 changes: 25 additions & 4 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
path: target/release/lagging_server

build-sozu:
name: Build Sozu 🦀
name: Build Sozu and bench_logger 🦀
runs-on: ubuntu-latest
steps:
- name: Install protobuf compiler
Expand All @@ -82,12 +82,22 @@ jobs:
- name: Build Sozu
run: cargo build --release

- name: Build Sozu bench logger (for benchmarking)
run: cargo build --release --example bench_logger

- name: 📤 Upload sozu
uses: actions/upload-artifact@v4
with:
name: sozu
path: target/release/sozu


- name: 📤 Upload sozu bench logger
uses: actions/upload-artifact@v4
with:
name: bench_logger
path: target/release/examples/bench_logger


bench:
name: Benchmark 🎯
runs-on: ubuntu-latest
Expand All @@ -110,6 +120,11 @@ jobs:
with:
name: sozu
path: .github/workflows
- name: 📥 Download sozu bench logger
uses: actions/download-artifact@v4
with:
name: bench_logger
path: .github/workflows

- name: Host mapping sozu.io domains
run: |
Expand Down Expand Up @@ -150,12 +165,18 @@ jobs:

- name: Fix rights
working-directory: .github/workflows
run: |
chmod +x bombardier
chmod +x lagging_server
chmod +x sozu
run: |
chmod +x bench_logger
- name: ⚡ Launch bench
working-directory: .github/workflows
run:
python bench.py
python bench.py

- name: Bench the logs
working-directory: .github/workflows
run:
python bench_logs.py

0 comments on commit d8c33f9

Please sign in to comment.