diff --git a/.github/workflows/bench_logs.py b/.github/workflows/bench_logs.py new file mode 100644 index 000000000..82aea7fec --- /dev/null +++ b/.github/workflows/bench_logs.py @@ -0,0 +1,42 @@ +import subprocess +import logging +import time + +def bench_logs(color: bool, target: str, iterations: int, level: str): + logging.info("🎯 Initalize environnment") + + start = time.time() + + try: + sozu = subprocess.Popen( + [ + "BENCH_LOG_COLOR={color}", + "BENCH_LOG_TARGET={target}", + "BENCH_LOG_ITERS={iterations}", + "BENCH_LOG_FILTER={level}", + "./bench-logger", "start", "-c", "bench.toml", "> /dev/null" + ], + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL, + ) + except subprocess.CalledProcessError as e: + logging.error(f"🚨 Command failed with return code {e.returncode}") + + elapsed_time = time.time() - start + + logging.info("🪓 Destroy environment") + + try: + subprocess.run(["kill", str(sozu.pid)]) + except subprocess.CalledProcessError as e: + logging.error(f"🚨 Failed to destroy environnement {e.returncode}") + + logging.info("benching logs, with color: {color}, to {target}, level {level}, {iterations} iterations. Time: {elapsed}") + +logging.basicConfig(encoding='utf-8', level=logging.INFO) +logging.info("💣 Launching benchmark") + +bench_logs(true, "stdout", 1000000, "debug") +bench_logs(true, "stdout", 1000000, "trace") +bench_logs(true, "udp", 1000000, "debug") +bench_logs(true, "udp", 1000000, "trace") \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index e3a376fa1..23fdda304 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -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 @@ -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: | @@ -158,4 +173,9 @@ jobs: - name: ⚡ Launch bench working-directory: .github/workflows run: - python bench.py \ No newline at end of file + python bench.py + + - name: Bench the logs + working-directory: .github/workflows + run: + python bench_logs.py \ No newline at end of file