parallel-execution

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Parallel Execution

并行执行

Execute multiple independent tasks simultaneously to maximize throughput and minimize total execution time.
同时执行多个独立任务,以最大化吞吐量并缩短总执行时间。

When to Use

适用场景

  • Multiple independent tasks (no dependencies)
  • Tasks benefit from concurrent execution
  • Maximizing throughput is priority
  • Available agents for parallel work
  • Results can be aggregated after completion
  • 多个独立任务(无依赖关系)
  • 任务可从并发执行中获益
  • 以最大化吞吐量为优先目标
  • 有可用于并行工作的Agent
  • 任务完成后结果可汇总

Core Concepts

核心概念

Independence

独立性

Tasks are independent when:
  • ✓ No data dependencies
  • ✓ No resource conflicts
  • ✓ No ordering requirements
  • ✓ Failures are isolated
当满足以下条件时,任务为独立任务
  • ✓ 无数据依赖
  • ✓ 无资源冲突
  • ✓ 无顺序要求
  • ✓ 故障相互隔离

Concurrency

并发性

Critical: Use single message with multiple Task tool calls:
markdown
[Task tool] → Agent A
[Task tool] → Agent B
[Task tool] → Agent C

All start simultaneously.
关键要点:使用单条消息包含多个Task工具调用
markdown
[Task tool] → Agent A
[Task tool] → Agent B
[Task tool] → Agent C

所有任务同时启动。

Execution Patterns

执行模式

PatternDescriptionExample
HomogeneousSame agent, different inputsTest 3 modules
HeterogeneousDifferent agents, related taskReview + Test + Profile
Parallel + ConvergenceParallel → SynthesizeProfile + Analyze → Root cause
模式描述示例
同构模式同一Agent,不同输入测试3个模块
异构模式不同Agent,相关任务评审 + 测试 + 性能分析
并行+收敛并行执行→结果合成性能分析 + 数据分析→根因定位

Synchronization Strategies

同步策略

  • Wait for All: Proceed when ALL complete
  • Wait for Any: Early termination on first success
  • Threshold: Proceed when N of M complete
  • 等待全部完成:所有任务完成后再继续
  • 等待任意完成:首个任务成功后提前终止
  • 阈值触发:当M个任务中有N个完成时继续

Performance

性能

Sequential: T1 + T2 + T3
Parallel: max(T1, T2, T3)
Speedup = Sequential / Parallel
Example: 3 tasks (10+15+8 min) → Parallel (15 min) = 2.2x faster
串行执行:T1 + T2 + T3
并行执行:max(T1, T2, T3)
加速比 = 串行时间 / 并行时间
示例:3个任务(10+15+8分钟)→ 并行执行(15分钟)= 提速2.2倍

Best Practices

最佳实践

✓ Verify independence before parallelizing ✓ Use single message with multiple Task calls ✓ Balance workload across agents ✓ Handle failures gracefully
✗ Don't parallelize dependent tasks ✗ Don't send sequential messages
✓ 并行化前先验证任务独立性 ✓ 使用单条消息包含多个Task调用 ✓ 在Agent间平衡工作负载 ✓ 优雅处理故障
✗ 不要对有依赖的任务进行并行化 ✗ 不要发送顺序消息