From 90ee05c2f347a0ccb90d65e2cbae5c5e8a2192b6 Mon Sep 17 00:00:00 2001 From: Emmanuel Bosquet Date: Thu, 8 Feb 2024 16:44:23 +0100 Subject: [PATCH] benchmark info logs in the CI --- .github/workflows/bench_logs.py | 69 +++++++++++++++++++++++++++++++++ .github/workflows/benchmark.yml | 64 ++++++++++++++++++++++++++++-- 2 files changed, 129 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/bench_logs.py diff --git a/.github/workflows/bench_logs.py b/.github/workflows/bench_logs.py new file mode 100644 index 000000000..223071822 --- /dev/null +++ b/.github/workflows/bench_logs.py @@ -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) \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index e3a376fa1..ad121c25a 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -87,7 +87,35 @@ jobs: with: name: sozu path: target/release/sozu - + + build-bench-logger: + name: Build bench_logger 🦀 + runs-on: ubuntu-latest + steps: + - name: Install protobuf compiler + run: sudo apt-get install -y protobuf-compiler + + - name: Install rust toolchain + uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + rustflags: "" + + - uses: actions/checkout@v4 + + - uses: Swatinem/rust-cache@v2 + with: + cache-all-crates: true + prefix-key: "sozu" + + - name: Build Sozu bench logger (for benchmarking) + run: cargo build --release --example bench_logger + + - 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 @@ -154,8 +182,36 @@ jobs: chmod +x bombardier chmod +x lagging_server chmod +x sozu - + - name: ⚡ Launch bench working-directory: .github/workflows - run: - python bench.py \ No newline at end of file + run: python bench.py + + bench-logs: + name: benchmark the logger + runs-on: ubuntu-latest + needs: [build-sozu, build-bench-logger] + steps: + - uses: actions/checkout@v4 + + - name: 📥 Download sozu + uses: actions/download-artifact@v4 + with: + name: sozu + path: .github/workflows + + - name: 📥 Download sozu bench logger + uses: actions/download-artifact@v4 + with: + name: bench_logger + path: .github/workflows + + - name: Fix rights + working-directory: .github/workflows + run: | + chmod +x sozu + chmod +x bench_logger + + - name: Bench the logs + working-directory: .github/workflows + run: python bench_logs.py \ No newline at end of file