v2/benchmark/docs/PARALLEL_EXECUTION.md
The parallel execution system provides efficient, scalable execution of multiple benchmark tasks with comprehensive resource management, task scheduling, and progress monitoring.
parallel_executor.py)The core execution engine that manages concurrent task execution with multiple execution modes:
task_scheduler.py)Advanced task scheduling with multiple algorithms:
orchestration_manager.py)High-level orchestration for managing complex benchmark suites:
from swarm_benchmark.core import ParallelExecutor, ExecutionMode, ResourceLimits
# Configure resource limits
limits = ResourceLimits(
max_cpu_percent=80.0,
max_memory_mb=1024.0,
max_concurrent_tasks=10
)
# Create executor
executor = ParallelExecutor(
mode=ExecutionMode.HYBRID,
limits=limits
)
# Start executor
await executor.start()
# Submit tasks
task_ids = []
for task in tasks:
task_id = await executor.submit_task(task, priority=1)
task_ids.append(task_id)
# Wait for completion
await executor.wait_for_completion(timeout=300)
# Get results
results = await executor.get_all_results()
# Shutdown
await executor.stop()
from swarm_benchmark.core import (
OrchestrationManager,
OrchestrationConfig,
SchedulingAlgorithm
)
# Configure orchestration
config = OrchestrationConfig(
execution_mode=ExecutionMode.HYBRID,
scheduling_algorithm=SchedulingAlgorithm.DYNAMIC,
enable_work_stealing=True,
auto_scaling=True,
max_parallel_benchmarks=10
)
# Create manager
orchestrator = OrchestrationManager(config)
# Run benchmark suite
results = await orchestrator.run_benchmark_suite(
objectives=["objective1", "objective2", "objective3"],
config=benchmark_config
)
# Get comprehensive metrics
metrics = orchestrator.get_orchestration_metrics()
ResourceLimits(
max_cpu_percent=80.0, # Maximum CPU usage percentage
max_memory_mb=1024.0, # Maximum memory in MB
max_concurrent_tasks=10, # Maximum parallel tasks
max_queue_size=1000, # Maximum queued tasks
task_timeout=300, # Task timeout in seconds
monitoring_interval=1.0 # Resource check interval
)
Tasks can be assigned priorities (higher number = higher priority):
Agents have capabilities that are matched to task requirements:
research, analysis, web_searchdevelopment, coding, architectureanalysis, data_processing, statisticstesting, validation, quality_assuranceoptimization, performance, profilingExecutionMetrics(
tasks_queued=0, # Number of tasks waiting
tasks_running=0, # Currently executing tasks
tasks_completed=0, # Successfully completed tasks
tasks_failed=0, # Failed tasks
total_execution_time=0.0, # Total execution time
average_execution_time=0.0,# Average per task
peak_cpu_usage=0.0, # Peak CPU percentage
peak_memory_usage=0.0, # Peak memory in MB
throughput=0.0 # Tasks per second
)
SchedulingMetrics(
total_scheduled=0, # Total tasks scheduled
scheduling_time=0.0, # Time spent scheduling
load_balance_score=0.0, # Load distribution quality (0-1)
capability_match_score=0.0,# Capability matching quality (0-1)
max_agent_load=0, # Maximum tasks per agent
min_agent_load=0 # Minimum tasks per agent
)
Choose the appropriate execution mode based on your workload:
The system provides comprehensive error handling:
The parallel execution system integrates seamlessly with the benchmark engine:
# Using OptimizedBenchmarkEngine with parallel execution
engine = OptimizedBenchmarkEngine(
config=benchmark_config,
enable_optimizations=True
)
# The engine automatically uses parallel execution
result = await engine.run_benchmark(objective)
max_concurrent_tasksmax_cpu_percent limitmax_memory_mb limitmax_queue_sizetask_timeout for long-running tasks