From 1b6ccd61806ee8b5c05c622db769b35c003ade8e Mon Sep 17 00:00:00 2001 From: Emily Oram Date: Wed, 2 Dec 2026 11:28:25 +1300 Subject: [PATCH 1/2] chore: remove demo/ directory (backport from #147 to stable/9) The demo/ directory holds scratch material (week_1/week_2 benchmark scripts, v2 backpressure analysis) that is not part of the published SDK. main removed it as part of #147; stable/9 still carried it, and once code scanning started covering stable/9, its demo workers raised high-severity py/clear-text-logging-sensitive-data alerts (#26-#29) for printing simulated credit scores. Also drops the now-redundant 'demo' entries from the pyright and ruff excludes. This backports only the demo removal from #147, not its pyright-to-ty migration. (cherry picked from commit 0606bc12) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- demo/v2/BENCHMARK_GUIDE.md | 273 -- demo/v2/QUICK_START.md | 150 - demo/v2/README.md | 187 - demo/v2/backpressure/README.md | 149 - demo/v2/backpressure/analyze_completions.py | 164 - demo/v2/backpressure/analyze_floor.py | 82 - demo/v2/backpressure/analyze_full_matrix.py | 164 - demo/v2/backpressure/analyze_results.py | 54 - demo/v2/backpressure/client_worker.py | 523 --- demo/v2/backpressure/compare_50c.py | 61 - demo/v2/backpressure/compare_errors.py | 42 - demo/v2/backpressure/compare_results.py | 74 - demo/v2/backpressure/compare_throughput.py | 72 - demo/v2/backpressure/evaluate.py | 64 - demo/v2/backpressure/multi_client.py | 1222 ------ demo/v2/backpressure/recompute_jain.py | 87 - .../resources/bp-test-process.bpmn | 41 - demo/v2/backpressure/run_matrix.py | 754 ---- demo/v2/backpressure/server_probe.py | 326 -- demo/v2/backpressure/single_client.py | 610 --- demo/v2/generate_benchmark_scenarios.py | 383 -- demo/v2/job_worker_benchmark.py | 1432 ------- demo/v2/job_worker_original.py | 90 - .../job_worker_load_test_process_1.bpmn | 45 - demo/v2/results/README.md | 41 - demo/v2/results/baseline_20251212_183413.json | 309 -- demo/v2/results/benchmark_full_results.json | 3809 ----------------- demo/v2/results/fast_20251212_144822.json | 393 -- demo/v2/results/fast_20251212_161858.json | 393 -- demo/v2/results/fast_20251212_165730.json | 393 -- demo/v2/run_benchmark_scenarios.py | 355 -- demo/v2/run_fast_validation.sh | 40 - demo/v2/scenarios/.gitignore | 3 - demo/v2/scenarios/README.md | 43 - demo/v2/scenarios/baseline.json | 41 - demo/v2/scenarios/fast.json | 210 - demo/v2/scenarios/full.json | 873 ---- demo/v2/scenarios/minimal.json | 28 - demo/v2/scenarios/quick.json | 132 - demo/v2/scenarios/safety.json | 54 - demo/week_1/__init.py__ | 0 demo/week_1/cancel_processes.py | 46 - demo/week_1/cpu_bound_workload.py | 16 - demo/week_1/demo.py | 74 - demo/week_1/io_bound_workload.py | 25 - demo/week_1/multicore_workload.py | 47 - demo/week_1/subprocess_workload.py | 50 - demo/week_2/.env | 1 - demo/week_2/README.md | 130 - demo/week_2/__init__.py | 1 - .../camunda_demo_week2.egg-info/PKG-INFO | 7 - .../camunda_demo_week2.egg-info/SOURCES.txt | 8 - .../dependency_links.txt | 1 - .../camunda_demo_week2.egg-info/requires.txt | 2 - .../camunda_demo_week2.egg-info/top_level.txt | 1 - demo/week_2/deploy_loan_process.py | 43 - demo/week_2/frontend/QUICKSTART.md | 145 - demo/week_2/frontend/README.md | 184 - demo/week_2/frontend/SETUP.md | 273 -- demo/week_2/frontend/app.js | 267 -- demo/week_2/frontend/index.html | 205 - demo/week_2/frontend/styles.css | 535 --- demo/week_2/loan-application-process.bpmn | 201 - demo/week_2/loan_workers.py | 396 -- demo/week_2/main.py | 253 -- demo/week_2/pyproject.toml | 13 - demo/week_2/test_api.py | 68 - pyproject.toml | 2 - 68 files changed, 17160 deletions(-) delete mode 100644 demo/v2/BENCHMARK_GUIDE.md delete mode 100644 demo/v2/QUICK_START.md delete mode 100644 demo/v2/README.md delete mode 100644 demo/v2/backpressure/README.md delete mode 100644 demo/v2/backpressure/analyze_completions.py delete mode 100644 demo/v2/backpressure/analyze_floor.py delete mode 100644 demo/v2/backpressure/analyze_full_matrix.py delete mode 100644 demo/v2/backpressure/analyze_results.py delete mode 100644 demo/v2/backpressure/client_worker.py delete mode 100644 demo/v2/backpressure/compare_50c.py delete mode 100644 demo/v2/backpressure/compare_errors.py delete mode 100644 demo/v2/backpressure/compare_results.py delete mode 100644 demo/v2/backpressure/compare_throughput.py delete mode 100644 demo/v2/backpressure/evaluate.py delete mode 100644 demo/v2/backpressure/multi_client.py delete mode 100644 demo/v2/backpressure/recompute_jain.py delete mode 100644 demo/v2/backpressure/resources/bp-test-process.bpmn delete mode 100644 demo/v2/backpressure/run_matrix.py delete mode 100644 demo/v2/backpressure/server_probe.py delete mode 100644 demo/v2/backpressure/single_client.py delete mode 100644 demo/v2/generate_benchmark_scenarios.py delete mode 100644 demo/v2/job_worker_benchmark.py delete mode 100644 demo/v2/job_worker_original.py delete mode 100644 demo/v2/resources/job_worker_load_test_process_1.bpmn delete mode 100644 demo/v2/results/README.md delete mode 100644 demo/v2/results/baseline_20251212_183413.json delete mode 100644 demo/v2/results/benchmark_full_results.json delete mode 100644 demo/v2/results/fast_20251212_144822.json delete mode 100644 demo/v2/results/fast_20251212_161858.json delete mode 100644 demo/v2/results/fast_20251212_165730.json delete mode 100644 demo/v2/run_benchmark_scenarios.py delete mode 100644 demo/v2/run_fast_validation.sh delete mode 100644 demo/v2/scenarios/.gitignore delete mode 100644 demo/v2/scenarios/README.md delete mode 100644 demo/v2/scenarios/baseline.json delete mode 100644 demo/v2/scenarios/fast.json delete mode 100644 demo/v2/scenarios/full.json delete mode 100644 demo/v2/scenarios/minimal.json delete mode 100644 demo/v2/scenarios/quick.json delete mode 100644 demo/v2/scenarios/safety.json delete mode 100644 demo/week_1/__init.py__ delete mode 100644 demo/week_1/cancel_processes.py delete mode 100644 demo/week_1/cpu_bound_workload.py delete mode 100644 demo/week_1/demo.py delete mode 100644 demo/week_1/io_bound_workload.py delete mode 100644 demo/week_1/multicore_workload.py delete mode 100644 demo/week_1/subprocess_workload.py delete mode 100644 demo/week_2/.env delete mode 100644 demo/week_2/README.md delete mode 100644 demo/week_2/__init__.py delete mode 100644 demo/week_2/camunda_demo_week2.egg-info/PKG-INFO delete mode 100644 demo/week_2/camunda_demo_week2.egg-info/SOURCES.txt delete mode 100644 demo/week_2/camunda_demo_week2.egg-info/dependency_links.txt delete mode 100644 demo/week_2/camunda_demo_week2.egg-info/requires.txt delete mode 100644 demo/week_2/camunda_demo_week2.egg-info/top_level.txt delete mode 100755 demo/week_2/deploy_loan_process.py delete mode 100644 demo/week_2/frontend/QUICKSTART.md delete mode 100644 demo/week_2/frontend/README.md delete mode 100644 demo/week_2/frontend/SETUP.md delete mode 100644 demo/week_2/frontend/app.js delete mode 100644 demo/week_2/frontend/index.html delete mode 100644 demo/week_2/frontend/styles.css delete mode 100644 demo/week_2/loan-application-process.bpmn delete mode 100755 demo/week_2/loan_workers.py delete mode 100644 demo/week_2/main.py delete mode 100644 demo/week_2/pyproject.toml delete mode 100644 demo/week_2/test_api.py diff --git a/demo/v2/BENCHMARK_GUIDE.md b/demo/v2/BENCHMARK_GUIDE.md deleted file mode 100644 index e5fb57f7c..000000000 --- a/demo/v2/BENCHMARK_GUIDE.md +++ /dev/null @@ -1,273 +0,0 @@ -# Job Worker Benchmark Guide - -Comprehensive benchmarking system for testing Camunda job worker performance across different execution strategies, workload types, and configurations. - -## Quick Start - -### 1. Generate Scenarios - -```bash -# Minimal suite (3 scenarios, ~1 minute) -python demo/v2/generate_benchmark_scenarios.py --suite minimal --output scenarios_minimal.json - -# Quick suite (11 scenarios, ~5 minutes) -python demo/v2/generate_benchmark_scenarios.py --suite quick --output scenarios_quick.json - -# Full suite (71 scenarios, ~2-3 hours) -python demo/v2/generate_benchmark_scenarios.py --suite full --output scenarios_full.json - -# Full suite with CSV export -python demo/v2/generate_benchmark_scenarios.py --suite full --output scenarios.json --csv scenarios.csv -``` - -### 2. Run Benchmarks - -```bash -# Run all scenarios -python demo/v2/run_benchmark_scenarios.py scenarios.json --output results.json - -# Run only first 5 scenarios (for testing) -python demo/v2/run_benchmark_scenarios.py scenarios.json --limit 5 - -# Run only specific phase -python demo/v2/run_benchmark_scenarios.py scenarios.json --phase 1_baseline - -# Continue on errors -python demo/v2/run_benchmark_scenarios.py scenarios.json --continue-on-error -``` - -### 3. Run Individual Tests - -You can also run individual tests directly: - -```bash -# Run a single test -uv run demo/v2/job_worker_benchmark.py test \ - --process_instances 20 \ - --worker_strategy async \ - --workload_type cpu \ - --work_duration_seconds 1.0 \ - --max_concurrent_jobs 10 - -# Run pre-defined benchmark suites -uv run demo/v2/job_worker_benchmark.py benchmark-workloads --process_instances 20 -uv run demo/v2/job_worker_benchmark.py benchmark --process_instances 20 -``` - -## Benchmark Suite Structure - -The full benchmark suite is organized into 8 phases: - -### Phase 1: Baseline (3 scenarios) -- Tests all strategies (async, thread, auto) with standard CPU workload -- **Purpose**: Establish baseline performance for each strategy - -### Phase 2: Workload Types (6 scenarios) -- Tests CPU, I/O, and subprocess workloads with async and thread strategies -- **Purpose**: Identify which strategy handles which workload type best - -### Phase 3: Concurrency Scaling (15 scenarios) -- Tests all strategies with 1, 5, 10, 20, 50 concurrent jobs -- **Purpose**: Understand how strategies scale with concurrency - -### Phase 4: Load Scaling (15 scenarios) -- Tests all strategies with 10, 20, 50, 100, 200 process instances -- **Purpose**: Find breaking points and optimal load handling - -### Phase 5: Work Duration (10 scenarios) -- Tests async and thread with work durations: 0.1s, 0.5s, 1.0s, 2.0s, 5.0s -- **Purpose**: Determine if work duration affects strategy performance - -### Phase 6: Interaction Effects (12 scenarios) -- Tests combinations of: workload type × concurrency × strategy -- **Purpose**: Identify important interaction effects - -### Phase 7: Edge Cases (6 scenarios) -- Single job, massive load (500 jobs), bottleneck, long duration, subprocess stress, high async concurrency -- **Purpose**: Test extreme conditions and edge cases - -### Phase 8: Subprocess Threading (4 scenarios) -- Tests the problematic subprocess_threaded workload -- **Purpose**: Expose fork-safety issues with subprocess + threading - -## Key Parameters - -### Execution Strategies -- **`async`**: Pure async/await, best for I/O-bound work -- **`thread`**: ThreadPoolExecutor, good for mixed workloads -- **`auto`**: Automatic strategy selection based on hints -- **`process`**: ProcessPoolExecutor (currently broken due to pickling issues) - -### Workload Types -- **`cpu`**: CPU-intensive busy loop -- **`io`**: I/O-bound file operations -- **`subprocess`**: External subprocess calls (sleep command) -- **`subprocess_threaded`**: Subprocess with internal threading (tests fork safety) - -### Configuration Parameters -- **`num_instances`**: Number of process instances to create (= number of jobs) -- **`max_concurrent_jobs`**: Maximum number of jobs executing concurrently -- **`work_duration`**: Duration of simulated work in seconds -- **`repeats`**: Number of times to repeat test (for statistical significance) -- **`timeout`**: Maximum time to wait for all jobs to complete - -## Performance Metrics - -Each benchmark scenario captures: - -- **`jobs_per_second`**: Throughput (jobs completed per second) -- **`total_time`**: Total time to complete all jobs -- **`jobs_completed`**: Number of jobs successfully completed -- **`memory_peak_mb`**: Peak Python memory usage -- **`max_rss_mb`**: Maximum resident set size (total process memory) -- **`rss_delta_mb`**: Change in RSS memory during test - -## Analyzing Results - -### View Summary Report - -The runner automatically generates a summary report showing: -- Results grouped by phase -- Top performers by throughput -- Best strategy for each workload type - -### Manual Analysis - -Results are saved in JSON format: - -```python -import json -import pandas as pd - -# Load results -with open('results.json') as f: - data = json.load(f) - -# Convert to DataFrame -df = pd.DataFrame(data['results']) - -# Filter successful runs -success = df[df['status'] == 'success'] - -# Compare strategies -success.pivot_table( - values='jobs_per_second_avg', - index='workload_type', - columns='strategy', - aggfunc='mean' -) - -# Find best configuration for high load -high_load = success[success['num_instances'] >= 100] -high_load.nlargest(5, 'jobs_per_second_avg')[['name', 'strategy', 'jobs_per_second_avg']] -``` - -## Key Questions Answered - -The benchmark suite helps answer: - -1. **Which strategy is fastest for CPU-bound work?** - - Look at Phase 1 baseline + Phase 2 CPU workload results - -2. **How does concurrency affect throughput?** - - Analyze Phase 3 concurrency scaling results - -3. **What's the optimal max_concurrent_jobs setting?** - - Find the "knee" in the concurrency curve (diminishing returns) - -4. **Does async or thread handle I/O better?** - - Compare Phase 2 results for I/O workload - -5. **What happens under extreme load?** - - Check Phase 7 edge cases (especially massive_load scenario) - -6. **Are there subprocess threading issues?** - - Review Phase 8 subprocess_threaded results for errors/warnings - -## Custom Scenarios - -You can create custom scenario files: - -```json -[ - { - "name": "custom_test", - "num_instances": 50, - "strategy": "async", - "workload_type": "cpu", - "work_duration": 2.0, - "max_concurrent_jobs": 25, - "repeats": 3, - "timeout": 120, - "job_timeout_ms": 30000, - "description": "Custom scenario for testing X", - "phase": "custom" - } -] -``` - -Then run: -```bash -python demo/v2/run_benchmark_scenarios.py custom_scenarios.json -``` - -## Performance Tips - -1. **Use `--limit` for quick testing**: Test your setup with `--limit 3` before running full suite -2. **Run overnight**: Full suite takes 2-3 hours -3. **Use `--continue-on-error`**: Don't let one failure stop the entire suite -4. **Save intermediate results**: Runner saves after each scenario -5. **Filter by phase**: Use `--phase` to run specific sections - -## Troubleshooting - -### Camunda Connection Issues -```bash -# Set Camunda URL -export CAMUNDA_REST_ADDRESS="http://localhost:8080/v2" -``` - -### Timeouts -- Increase `timeout` in scenario files for slow environments -- Check Camunda broker health - -### Memory Issues -- Reduce `num_instances` or `max_concurrent_jobs` -- Monitor with `top` or `htop` during runs - -### Process Strategy Errors -The `process` strategy currently doesn't work due to pickling issues with the `ActivatedJob` containing an unpicklable client (`CamundaAsyncClient`). Stick with `async`, `thread`, or `auto`. - -## Example Workflow - -```bash -# 1. Generate scenarios -python demo/v2/generate_benchmark_scenarios.py --suite full --output scenarios.json --csv scenarios.csv - -# 2. Test with first 5 scenarios -python demo/v2/run_benchmark_scenarios.py scenarios.json --limit 5 --output test_results.json - -# 3. If successful, run full suite -python demo/v2/run_benchmark_scenarios.py scenarios.json --output full_results.json --continue-on-error - -# 4. Analyze specific phase -python demo/v2/run_benchmark_scenarios.py scenarios.json --phase 3_concurrency_scaling --output concurrency_results.json - -# 5. Review results -cat full_results.json | jq '.results[] | select(.status == "success") | {name, strategy, jobs_per_second_avg}' -``` - -## Contributing - -To add new phases or scenarios: - -1. Edit `generate_benchmark_scenarios.py` -2. Add a new `generate_phaseX_xxx()` method -3. Call it from `generate_full_suite()` -4. Test with `--suite full` - -## References - -- Main benchmark script: [`job_worker_benchmark.py`](job_worker_benchmark.py) -- Scenario generator: [`generate_benchmark_scenarios.py`](generate_benchmark_scenarios.py) -- Scenario runner: [`run_benchmark_scenarios.py`](run_benchmark_scenarios.py) diff --git a/demo/v2/QUICK_START.md b/demo/v2/QUICK_START.md deleted file mode 100644 index ad5804b09..000000000 --- a/demo/v2/QUICK_START.md +++ /dev/null @@ -1,150 +0,0 @@ -# Quick Start: Fast Validation Run - -To validate that everything is working before running longer benchmarks: - -## 1. Generate Fast Suite (15 scenarios) - -```bash -python demo/v2/generate_benchmark_scenarios.py --suite fast --output scenarios_fast.json -``` - -**What it includes:** -- ✅ Baseline tests (3 strategies) -- ✅ Workload types (cpu, io, subprocess) -- ✅ Concurrency scaling (3 levels) -- ✅ Load scaling (3 levels) -- ✅ One interaction test -- ✅ One edge case -- ✅ One subprocess threading test - -**Expected runtime: ~10-15 minutes** - -## 2. Run Fast Suite - -```bash -uv run demo/v2/run_benchmark_scenarios.py scenarios_fast.json \ - --output results_fast.json \ - --continue-on-error -``` - -## 3. Check Results - -The runner will automatically show a summary. Look for: - -``` -✓ Completed: fast_baseline_async - Duration: 15.2s - Throughput: 0.33 jobs/sec - -✓ Completed: fast_baseline_thread - Duration: 14.8s - Throughput: 0.34 jobs/sec -... - -====================================================================== -ALL SCENARIOS COMPLETE -====================================================================== -Total scenarios: 15 -Successful: 15 -Failed: 0 -``` - -## Suite Comparison - -| Suite | Scenarios | Time | Use Case | -|-------|-----------|------|----------| -| **minimal** | 3 | ~1-2 min | Smoke test | -| **fast** | 15 | ~10-15 min | **Validation before long runs** | -| **quick** | 11 | ~5-10 min | Rapid iteration | -| **full** | 71 | ~2-4 hrs | Comprehensive analysis | - -## Fast Suite Details - -### Phase Breakdown - -``` -fast_baseline (3): All strategies with CPU workload -fast_workload (3): CPU, IO, subprocess with async -fast_concurrency (3): 1, 5, 20 concurrent jobs -fast_load (3): 5, 20, 50 instances -fast_interaction (1): async + io + high concurrency -fast_edge (1): 100 instances stress test -fast_subprocess (1): Threading safety test -``` - -### Key Parameters - -All scenarios use: -- **Short work duration**: 0.2-0.5 seconds -- **No repeats**: `repeats=1` (single run) -- **Small instance counts**: 5-100 instances -- **Quick timeouts**: 30-60 seconds - -## Troubleshooting - -### If it fails immediately: -```bash -# Check Camunda connection -export CAMUNDA_REST_ADDRESS="http://localhost:8080/v2" - -# Test with just one scenario -uv run demo/v2/run_benchmark_scenarios.py scenarios_fast.json --limit 1 -``` - -### If some scenarios fail: -```bash -# Continue running despite errors -uv run demo/v2/run_benchmark_scenarios.py scenarios_fast.json --continue-on-error -``` - -### If you want to test specific parts: -```bash -# Just baseline tests (~3 min) -uv run demo/v2/run_benchmark_scenarios.py scenarios_fast.json --phase fast_baseline - -# Just workload tests (~3 min) -uv run demo/v2/run_benchmark_scenarios.py scenarios_fast.json --phase fast_workload -``` - -## Next Steps - -Once the fast suite passes: - -### Option 1: Run full suite -```bash -python demo/v2/generate_benchmark_scenarios.py --suite full --output scenarios.json -uv run demo/v2/run_benchmark_scenarios.py scenarios.json --continue-on-error -``` - -### Option 2: Target specific insights -```bash -# Deep dive into concurrency -uv run demo/v2/run_benchmark_scenarios.py scenarios.json --phase 3_concurrency_scaling - -# Test edge cases -uv run demo/v2/run_benchmark_scenarios.py scenarios.json --phase 7_edge_cases -``` - -### Option 3: Create custom scenarios -Edit `scenarios_fast.json` to adjust parameters and re-run. - -## Expected Output - -Successful fast suite run shows: -- All 15 scenarios completed -- Mix of throughput values (0.1 - 5.0 jobs/sec depending on config) -- Memory usage tracked -- No errors or timeouts -- Results saved to JSON - -This validates: -- ✅ Camunda connection works -- ✅ All strategies can execute jobs -- ✅ All workload types function -- ✅ Concurrency scaling works -- ✅ High load handling works -- ✅ Subprocess calls succeed -- ✅ No pickling errors -- ✅ Results collection works - -You're now ready for longer benchmark runs! diff --git a/demo/v2/README.md b/demo/v2/README.md deleted file mode 100644 index 31a949649..000000000 --- a/demo/v2/README.md +++ /dev/null @@ -1,187 +0,0 @@ -# Job Worker Demo & Benchmark - -This directory contains a comprehensive demonstration and benchmarking tool for the Camunda Python SDK's `JobWorker`. The `job_worker_benchmark.py` script allows you to test different execution strategies (`async`, `thread`, `process`) under various simulated workloads (`cpu`, `io`, `subprocess`). - -## Prerequisites - -* Python 3.10+ -* A running Camunda 8 instance (Self-Managed or SaaS). -* The `camunda-orchestration-sdk` package installed. -* Environment variables configured for Camunda connection (e.g., `CAMUNDA_REST_ADDRESS` or `ZEEBE_REST_ADDRESS`, plus any auth-related variables if needed). - -## Usage - -The script is a command-line tool that supports several modes of operation. We recommend using `uv` to run the script. - -### Default Run - -Runs a simple scenario with 1 process instance and the `auto` execution strategy. - -```bash -uv run demo/v2/job_worker_benchmark.py -``` - -### Quick Test - -Runs a quick test with 5 instances. - -```bash -uv run demo/v2/job_worker_benchmark.py quick -``` - -### Benchmarking Strategies - -Compares all execution strategies (`async`, `thread`, `process`, `auto`) using a CPU-bound workload. - -```bash -uv run demo/v2/job_worker_benchmark.py benchmark --process_instances 50 --work_duration_seconds 3.0 --job_timeout_milliseconds 30000 -``` - -* `--process_instances`: Number of process instances to start (default: 20). -* `--work_duration_seconds`: Duration of simulated work in seconds (default: 3.0). -* `--job_timeout_milliseconds`: Job timeout in milliseconds (default: 30000). - -### Benchmarking Workloads - -Compares strategies across both CPU-bound and I/O-bound workloads. - -```bash -uv run demo/v2/job_worker_benchmark.py benchmark-workloads --process_instances 20 --work_duration_seconds 3.0 --job_timeout_milliseconds 30000 -``` - -* `--process_instances`: Number of process instances to start (default: 20). -* `--work_duration_seconds`: Duration of simulated work in seconds (default: 3.0). -* `--job_timeout_milliseconds`: Job timeout in milliseconds (default: 30000). - -### Benchmarking Subprocess Calls - -Specifically tests `subprocess.call()` behavior across strategies to check for deadlocks or issues. - -```bash -uv run demo/v2/job_worker_benchmark.py benchmark-subprocess --process_instances 20 --work_duration_seconds 3.0 --job_timeout_milliseconds 30000 -``` - -* `--process_instances`: Number of process instances to start (default: 20). -* `--work_duration_seconds`: Duration of simulated work in seconds (default: 3.0). -* `--job_timeout_milliseconds`: Job timeout in milliseconds (default: 30000). - -### Custom Test Run - -Run a fully customizable test with specific parameters. - -```bash -uv run demo/v2/job_worker_benchmark.py test --process_instances 20 --worker_strategy process --workload_type cpu --repeat_runs 3 --max_concurrent_jobs 10 --work_duration_seconds 3.0 --job_timeout_milliseconds 30000 -``` - -* `--process_instances`: Number of process instances to start (default: 10). -* `--worker_strategy`: `auto`, `async`, `thread`, or `process` (default: auto). -* `--workload_type`: `cpu`, `io`, or `subprocess` (default: cpu). -* `--repeat_runs`: Number of times to repeat the test (results are averaged) (default: 1). -* `--max_concurrent_jobs`: Maximum concurrent jobs for the worker (default: 10). -* `--work_duration_seconds`: Duration of simulated work in seconds (default: 3.0). -* `--job_timeout_milliseconds`: Job timeout in milliseconds (default: 30000). - -### Other Scenarios - -* `stress`: Runs a heavy load test (100 instances, 50 concurrent jobs). -* `load`: Similar to stress but with different defaults. -* `multi`: Runs a comparison of all strategies with a single run each. - -```bash -uv run demo/v2/job_worker_benchmark.py stress -``` - -## Key Concepts Demonstrated - -* **`JobWorker`**: The core class for processing jobs. -* **Execution Strategies**: - * `async`: Uses Python's `asyncio` event loop. Best for I/O-bound tasks that use `async/await`. - * `thread`: Uses a `ThreadPoolExecutor`. Good for blocking I/O operations. **Note**: Subject to the Global Interpreter Lock (GIL), so not suitable for heavy CPU tasks. - * **`process`**: Uses a `ProcessPoolExecutor`. Essential for CPU-bound tasks to bypass the GIL. This benchmark demonstrates the "detached execution" pattern where the subprocess returns a result tuple instead of calling the client directly (which isn't picklable). - * `auto`: Automatically selects the best strategy based on the callback signature and hints. -* **`ExecutionHint`**: Decorators (`@ExecutionHint.cpu_bound`, `@ExecutionHint.io_bound`) to guide the `auto` strategy. -* **Workload Simulation**: - * `cpu`: Performs heavy arithmetic operations (list comprehensions) to hold the GIL and simulate real CPU-bound work. - * `io`: Simulates blocking file I/O. - * `subprocess`: Simulates calling external commands. -* **Memory Tracking**: Monitoring memory usage during worker execution. - -## Advanced: Systematic Benchmarking - -For comprehensive performance analysis, use the scenario generator and runner: - -### 1. Generate Benchmark Scenarios - -```bash -# Minimal suite (2 scenarios, ~1 minute) - smoke test -python demo/v2/generate_benchmark_scenarios.py --suite minimal - -# Fast suite (16 scenarios, ~15-20 minutes) - RECOMMENDED for validation -python demo/v2/generate_benchmark_scenarios.py --suite fast - -# Quick suite (10 scenarios, ~5-10 minutes) - rapid iteration -python demo/v2/generate_benchmark_scenarios.py --suite quick - -# Full suite (60 scenarios, ~2-4 hours) - comprehensive analysis -python demo/v2/generate_benchmark_scenarios.py --suite full - -# Custom output location -python demo/v2/generate_benchmark_scenarios.py --suite fast --output custom_path.json -``` - -Scenarios are saved to `demo/v2/scenarios/.json` by default. - -**First time?** Use the **fast** suite to validate everything works! See [QUICK_START.md](QUICK_START.md). - -### 2. Run Benchmark Suite - -```bash -# Run scenarios (results saved to demo/v2/results/_.json) -uv run demo/v2/run_benchmark_scenarios.py demo/v2/scenarios/fast.json - -# Custom output location -uv run demo/v2/run_benchmark_scenarios.py demo/v2/scenarios/fast.json --output custom_results.json - -# Continue on errors (recommended for full suite) -uv run demo/v2/run_benchmark_scenarios.py demo/v2/scenarios/fast.json --continue-on-error - -# Prevent sleep during long runs -# macOS: -caffeinate -i uv run demo/v2/run_benchmark_scenarios.py demo/v2/scenarios/full.json - -# Linux: -systemd-inhibit uv run demo/v2/run_benchmark_scenarios.py demo/v2/scenarios/full.json -``` - -See [BENCHMARK_GUIDE.md](BENCHMARK_GUIDE.md) for complete documentation on systematic benchmarking. - -### Benchmark Suite Structure - -The scenario generator creates 8 phases of tests: - -| Phase | Scenarios | Purpose | -|-------|-----------|---------| -| Baseline | 3 | Establish baseline performance | -| Workload Types | 6 | Best strategy for each workload | -| Concurrency Scaling | 15 | How strategies scale | -| Load Scaling | 15 | Breaking points under load | -| Work Duration | 10 | Duration sensitivity | -| Interactions | 12 | Combined effects | -| Edge Cases | 6 | Extreme conditions | -| Subprocess Threading | 4 | Fork-safety testing | - -### Files - -- `job_worker_benchmark.py` - Core benchmark tool -- `generate_benchmark_scenarios.py` - Scenario generator (**Strategy 4: Hybrid Approach**) -- `run_benchmark_scenarios.py` - Scenario execution runner -- `BENCHMARK_GUIDE.md` - Detailed benchmarking documentation - -## Performance Notes - -Recent benchmarks (Python 3.11 on macOS) comparing `process` vs `thread` strategies for CPU-bound workloads (3s duration, 50 instances) showed: - -* **Process Strategy**: ~30% faster throughput (2.35 jobs/s) and significantly lower memory usage (~96 MB). It successfully bypasses the GIL, allowing true parallelism across cores. -* **Thread Strategy**: Slower throughput (1.79 jobs/s) and much higher memory usage (~1.3 GB). The GIL forces threads to execute sequentially for CPU tasks, and high object churn on a shared heap can lead to memory fragmentation. - -**Recommendation**: Use `execution_strategy="process"` for any CPU-intensive job workers in Python. diff --git a/demo/v2/backpressure/README.md b/demo/v2/backpressure/README.md deleted file mode 100644 index c0057bb68..000000000 --- a/demo/v2/backpressure/README.md +++ /dev/null @@ -1,149 +0,0 @@ -# Backpressure Benchmarks - -Stress-tests the Python SDK's adaptive backpressure system under realistic -multi-client deployments (25 and 50 independent clients hitting the same -Camunda cluster). - -## Prerequisites - -- Python 3.10+ with `uv` -- Docker (the Camunda container is managed automatically) -- The SDK must be generated first: `make generate` (from repo root) - -## Quick Start - -```bash -# Run the full 72-configuration matrix (container restarted between each run) -uv run demo/v2/backpressure/run_matrix.py - -# Preview what would run -uv run demo/v2/backpressure/run_matrix.py --dry-run -``` - -## Matrix Dimensions - -| Dimension | Values | Purpose | -|-----------|--------|---------| -| **Clients** | 25, 50 | Simulates real customer deployment scale | -| **Mode** | `sync`, `async`, `thread` | SDK execution strategy | -| **Workload** | `instant`, `sleep`, `http` | Simulated handler cost (no-op, 0.2s sleep, 0.2s HTTP call to local server) | -| **Profile** | `BALANCED`, `LEGACY` | Backpressure configuration (adaptive vs retry-only) | -| **Isolation** | `subprocess`, `inprocess` | `subprocess` = separate OS process per client (no GIL); `inprocess` = threading.Thread per client (shared GIL) | - -Total: 2 × 3 × 3 × 2 × 2 = **72 configurations**. - -## What It Measures - -For each configuration the runner collects: - -- **Throughput** (ops/s) — aggregate completions per second -- **Errors** — failed API calls (429s, timeouts, etc.) -- **Queue-full** — subset of errors caused by full backpressure queue -- **Wall-clock time** — total run duration -- **Jain's fairness index** — distribution of work across clients (1.0 = perfectly fair) - -## Container Restart - -Between every run the Camunda Docker container is **stopped and restarted** -so each configuration starts from an identical clean baseline. This eliminates -carry-over effects like warmed caches, lingering backpressure state, or -accumulated process instances. - -You can skip restarts for faster (but less reliable) runs: - -```bash -uv run demo/v2/backpressure/run_matrix.py --no-restart -``` - -## Running Subsets - -```bash -# Only 25 clients -uv run demo/v2/backpressure/run_matrix.py --clients 25 - -# Only async and thread modes -uv run demo/v2/backpressure/run_matrix.py --modes async thread - -# Only BALANCED profile -uv run demo/v2/backpressure/run_matrix.py --profiles BALANCED - -# Only subprocess isolation (skip in-process/GIL runs) -uv run demo/v2/backpressure/run_matrix.py --isolations subprocess - -# Only instant and http workloads -uv run demo/v2/backpressure/run_matrix.py --workloads instant http - -# Custom target per client (default: 20) -uv run demo/v2/backpressure/run_matrix.py --target 50 - -# Custom max inflight per client (default: 10) -uv run demo/v2/backpressure/run_matrix.py --concurrency 20 -``` - -## Output - -Results are written to `demo/v2/backpressure/results/`: - -| File | Contents | -|------|----------| -| `report.md` | Markdown report with tables, analysis, and recommendations | -| `results.json` | Raw metrics for all runs (machine-readable) | -| `