mirror of
https://github.com/ruvnet/ruflo.git
synced 2026-11-23 21:59:14 +09:00
## 🔧 Critical Swarm System Fixes ### Fixed Task File Naming Bug - Tasks were being saved as '[object Object].json' due to TaskId object structure - Now properly extracts task ID string for file naming - Files save correctly as 'task_<id>.json' ### Added Task Timeout Protection - Implemented automatic timeout detection in task execution loop - Tasks that exceed timeout (default 5 minutes) are marked as failed - Prevents swarms from hanging indefinitely on stuck tasks - Agent state properly cleaned up on timeout ### Fixed Target Directory Propagation - Testing tasks were receiving null targetDir, preventing file access - Target directory now extracted from objective description - All tasks inherit targetDir through context - Enhanced extractTargetDirectory to check multiple sources ### Improved Task Dependencies - Fixed taskDependenciesMet to handle both string and TaskId objects - Added convertDependenciesToTaskDependencies for Map structure - Dependencies now properly resolve for sequential task execution ### Auto Strategy Integration - Added missing autoStrategy property and initialization - Proper AutoStrategy instantiation in coordinator constructor - Enables intelligent task decomposition for 'auto' strategy ## 📊 Added Comprehensive Benchmarks ### Benchmark Suite Integration - Added complete Python-based benchmarking tool - Tests 7 strategies across 5 coordination modes - 100% success rate across all test scenarios - Performance metrics: 0.10s - 0.20s execution times ### Real-World Performance Data - Calculator example: 4m 20s total (3 tasks) - Task breakdown: Analysis 29%, Implementation 22%, Testing 48% - Successfully created 6 files with proper directory structure ## 📝 Documentation Updates ### Updated README.md - Added v1.0.50 changelog with critical fixes - Integrated benchmark performance results table - Added real-world timing example - Removed old update notes for clarity - Added dedicated Benchmarks & Performance section ## 🧪 Test Results - Swarm now completes successfully with proper task coordination - All fixes validated in production environment - Task files save with correct names - Testing tasks find implementation files - Swarms exit cleanly after completion 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
368 lines
8.6 KiB
Markdown
368 lines
8.6 KiB
Markdown
# Performance Optimization Guide
|
|
|
|
This guide provides comprehensive strategies for optimizing swarm performance based on benchmark results.
|
|
|
|
## 🎯 Optimization Overview
|
|
|
|
Swarm optimization focuses on four key areas:
|
|
1. **Strategy Selection** - Choosing the right approach
|
|
2. **Coordination Efficiency** - Minimizing overhead
|
|
3. **Resource Utilization** - Optimizing CPU/memory usage
|
|
4. **Task Distribution** - Balancing workload
|
|
|
|
## 📊 Analyzing Benchmark Results
|
|
|
|
### Key Metrics to Monitor
|
|
|
|
```json
|
|
{
|
|
"performance_metrics": {
|
|
"execution_time": 0.25, // Target: < 1s for simple tasks
|
|
"coordination_overhead": 0.08, // Target: < 10% of execution time
|
|
"success_rate": 0.95 // Target: > 90%
|
|
},
|
|
"resource_usage": {
|
|
"cpu_percent": 25.0, // Target: < 80% to avoid throttling
|
|
"memory_mb": 256.0, // Target: < available memory
|
|
"peak_memory_mb": 300.0 // Monitor for memory spikes
|
|
},
|
|
"quality_metrics": {
|
|
"overall_quality": 0.87, // Target: > 0.85
|
|
"accuracy_score": 0.90, // Task-specific target
|
|
"completeness_score": 0.85 // Ensure comprehensive results
|
|
}
|
|
}
|
|
```
|
|
|
|
### Performance Analysis Commands
|
|
|
|
```bash
|
|
# Compare strategy performance
|
|
swarm-benchmark analyze --compare-strategies
|
|
|
|
# Identify bottlenecks
|
|
swarm-benchmark analyze --bottlenecks <benchmark-id>
|
|
|
|
# Generate performance report
|
|
swarm-benchmark report --performance <benchmark-id>
|
|
```
|
|
|
|
## 🚀 Strategy Optimization
|
|
|
|
### 1. Auto Strategy Optimization
|
|
|
|
The auto strategy uses pattern matching to select approaches. Optimize by:
|
|
|
|
```bash
|
|
# Test auto strategy effectiveness
|
|
swarm-benchmark run "Your task" --strategy auto --verbose
|
|
|
|
# Fine-tune with hints
|
|
swarm-benchmark run "Build API" --strategy auto --hint development
|
|
```
|
|
|
|
**Best Practices:**
|
|
- Use clear, descriptive objectives
|
|
- Include keywords that indicate task type
|
|
- Monitor which strategy auto selects
|
|
|
|
### 2. Research Strategy Optimization
|
|
|
|
Optimize research tasks for speed and accuracy:
|
|
|
|
```bash
|
|
# Parallel research with multiple agents
|
|
swarm-benchmark run "Research topic" \
|
|
--strategy research \
|
|
--mode distributed \
|
|
--max-agents 8 \
|
|
--parallel
|
|
```
|
|
|
|
**Optimization Tips:**
|
|
- Use distributed mode for broad research
|
|
- Increase agents for comprehensive coverage
|
|
- Set quality thresholds for accuracy
|
|
|
|
### 3. Development Strategy Optimization
|
|
|
|
Optimize code generation and development:
|
|
|
|
```bash
|
|
# Hierarchical development for complex projects
|
|
swarm-benchmark run "Build microservices" \
|
|
--strategy development \
|
|
--mode hierarchical \
|
|
--max-agents 6 \
|
|
--task-timeout 600
|
|
```
|
|
|
|
**Optimization Tips:**
|
|
- Use hierarchical mode for large projects
|
|
- Allocate more time for complex tasks
|
|
- Enable code review with quality checks
|
|
|
|
### 4. Analysis Strategy Optimization
|
|
|
|
Optimize data analysis tasks:
|
|
|
|
```bash
|
|
# Mesh coordination for collaborative analysis
|
|
swarm-benchmark run "Analyze dataset" \
|
|
--strategy analysis \
|
|
--mode mesh \
|
|
--parallel \
|
|
--quality-threshold 0.9
|
|
```
|
|
|
|
**Optimization Tips:**
|
|
- Use mesh mode for peer review
|
|
- Set high quality thresholds
|
|
- Enable parallel processing
|
|
|
|
### 5. Testing Strategy Optimization
|
|
|
|
Optimize test generation and execution:
|
|
|
|
```bash
|
|
# Distributed testing for speed
|
|
swarm-benchmark run "Create test suite" \
|
|
--strategy testing \
|
|
--mode distributed \
|
|
--max-retries 2
|
|
```
|
|
|
|
### 6. Optimization Strategy
|
|
|
|
For performance tuning tasks:
|
|
|
|
```bash
|
|
# Hybrid mode for adaptive optimization
|
|
swarm-benchmark run "Optimize performance" \
|
|
--strategy optimization \
|
|
--mode hybrid \
|
|
--monitor
|
|
```
|
|
|
|
### 7. Maintenance Strategy
|
|
|
|
For documentation and refactoring:
|
|
|
|
```bash
|
|
# Centralized for consistency
|
|
swarm-benchmark run "Update documentation" \
|
|
--strategy maintenance \
|
|
--mode centralized
|
|
```
|
|
|
|
## 🔗 Coordination Mode Optimization
|
|
|
|
### Centralized Mode
|
|
- **Best for**: Small teams (2-3 agents), simple tasks
|
|
- **Optimization**: Minimize coordinator selection time
|
|
- **Overhead**: ~50ms
|
|
|
|
```bash
|
|
swarm-benchmark run "Simple task" --mode centralized --max-agents 3
|
|
```
|
|
|
|
### Distributed Mode
|
|
- **Best for**: Research, parallel tasks
|
|
- **Optimization**: Balance coordinator count
|
|
- **Overhead**: ~100ms + network latency
|
|
|
|
```bash
|
|
swarm-benchmark run "Research task" --mode distributed --max-agents 8
|
|
```
|
|
|
|
### Hierarchical Mode
|
|
- **Best for**: Complex projects, large teams
|
|
- **Optimization**: Optimize tree depth
|
|
- **Overhead**: ~80ms per level
|
|
|
|
```bash
|
|
swarm-benchmark run "Complex project" --mode hierarchical --max-agents 10
|
|
```
|
|
|
|
### Mesh Mode
|
|
- **Best for**: Collaborative tasks, peer review
|
|
- **Optimization**: Limit peer connections
|
|
- **Overhead**: ~150ms + negotiation time
|
|
|
|
```bash
|
|
swarm-benchmark run "Collaborative task" --mode mesh --max-agents 6
|
|
```
|
|
|
|
### Hybrid Mode
|
|
- **Best for**: Mixed workloads, adaptive scenarios
|
|
- **Optimization**: Monitor strategy switching
|
|
- **Overhead**: Variable, typically 100-200ms
|
|
|
|
```bash
|
|
swarm-benchmark run "Mixed workload" --mode hybrid --max-agents 8
|
|
```
|
|
|
|
## 💡 Optimization Techniques
|
|
|
|
### 1. Agent Pool Sizing
|
|
|
|
```python
|
|
# Optimal agent count formula
|
|
optimal_agents = min(
|
|
task_complexity * 2, # Scale with complexity
|
|
available_resources, # Resource constraints
|
|
10 # Practical upper limit
|
|
)
|
|
```
|
|
|
|
### 2. Task Decomposition
|
|
|
|
Break large tasks into smaller sub-tasks:
|
|
|
|
```bash
|
|
# Instead of:
|
|
swarm-benchmark run "Build complete e-commerce platform"
|
|
|
|
# Use:
|
|
swarm-benchmark run "Build user authentication module"
|
|
swarm-benchmark run "Build product catalog service"
|
|
swarm-benchmark run "Build payment processing"
|
|
```
|
|
|
|
### 3. Resource Limits
|
|
|
|
Set appropriate resource constraints:
|
|
|
|
```bash
|
|
swarm-benchmark run "Task" \
|
|
--max-memory 512 \
|
|
--max-cpu 80 \
|
|
--timeout 300
|
|
```
|
|
|
|
### 4. Parallel Execution
|
|
|
|
Enable parallel processing when possible:
|
|
|
|
```bash
|
|
swarm-benchmark run "Independent tasks" \
|
|
--parallel \
|
|
--max-agents 8 \
|
|
--mode distributed
|
|
```
|
|
|
|
### 5. Quality vs Speed Trade-off
|
|
|
|
```bash
|
|
# Fast execution, lower quality
|
|
swarm-benchmark run "Task" --quality-threshold 0.7 --task-timeout 60
|
|
|
|
# High quality, slower execution
|
|
swarm-benchmark run "Task" --quality-threshold 0.95 --task-timeout 300
|
|
```
|
|
|
|
## 📈 Performance Monitoring
|
|
|
|
### Real-time Monitoring
|
|
|
|
```bash
|
|
# Enable monitoring
|
|
swarm-benchmark run "Task" --monitor
|
|
|
|
# Detailed metrics
|
|
swarm-benchmark run "Task" --monitor --metrics-interval 1
|
|
```
|
|
|
|
### Post-execution Analysis
|
|
|
|
```bash
|
|
# Generate performance report
|
|
swarm-benchmark analyze <benchmark-id> --report performance
|
|
|
|
# Compare multiple benchmarks
|
|
swarm-benchmark compare <id1> <id2> --metrics execution_time,quality
|
|
```
|
|
|
|
## 🎯 Optimization Checklist
|
|
|
|
- [ ] **Choose appropriate strategy** based on task type
|
|
- [ ] **Select optimal coordination mode** for team size
|
|
- [ ] **Set realistic resource limits** to prevent waste
|
|
- [ ] **Enable parallel execution** when tasks are independent
|
|
- [ ] **Monitor coordination overhead** and adjust if > 15%
|
|
- [ ] **Balance quality threshold** with execution time
|
|
- [ ] **Use task decomposition** for complex objectives
|
|
- [ ] **Review benchmark results** and iterate
|
|
- [ ] **Cache results** when tasks are repetitive
|
|
- [ ] **Profile resource usage** to identify bottlenecks
|
|
|
|
## 🔍 Troubleshooting Performance Issues
|
|
|
|
### High Execution Time
|
|
1. Check task complexity - decompose if needed
|
|
2. Increase agent count for parallel work
|
|
3. Switch to distributed/mesh mode
|
|
4. Extend timeout limits
|
|
|
|
### Low Success Rate
|
|
1. Review task objectives for clarity
|
|
2. Increase quality threshold
|
|
3. Add retry logic
|
|
4. Use more specialized strategies
|
|
|
|
### High Resource Usage
|
|
1. Limit agent pool size
|
|
2. Set memory/CPU constraints
|
|
3. Use centralized mode for efficiency
|
|
4. Enable resource monitoring
|
|
|
|
### Coordination Overhead
|
|
1. Simplify coordination mode
|
|
2. Reduce agent communication
|
|
3. Use hierarchical for large teams
|
|
4. Cache coordination decisions
|
|
|
|
## 📚 Advanced Optimization
|
|
|
|
### Custom Strategy Parameters
|
|
|
|
```python
|
|
# In your benchmark config
|
|
{
|
|
"strategy_params": {
|
|
"search_depth": 3,
|
|
"quality_iterations": 2,
|
|
"parallel_factor": 0.8
|
|
}
|
|
}
|
|
```
|
|
|
|
### Adaptive Optimization
|
|
|
|
```bash
|
|
# Let the system adapt
|
|
swarm-benchmark run "Complex task" \
|
|
--mode hybrid \
|
|
--adaptive \
|
|
--learning-rate 0.1
|
|
```
|
|
|
|
### Performance Profiling
|
|
|
|
```bash
|
|
# Enable detailed profiling
|
|
swarm-benchmark run "Task" \
|
|
--profile \
|
|
--profile-output profile.json
|
|
```
|
|
|
|
## 🎉 Best Practices Summary
|
|
|
|
1. **Start simple** - Use auto strategy and centralized mode
|
|
2. **Measure baseline** - Run initial benchmarks
|
|
3. **Optimize incrementally** - Change one parameter at a time
|
|
4. **Monitor metrics** - Track performance over time
|
|
5. **Document findings** - Record what works best
|
|
6. **Share results** - Help others optimize
|
|
|
|
Remember: The best optimization strategy depends on your specific use case. Always benchmark and measure! |