自托管并发控制(Self-hosted concurrency control)#
仅适用于自托管的 n8n
本文档适用于自托管的并发控制。请阅读云并发以了解并发在 n8n 云账户中的工作原理。
在常规模式下,n8n 不会限制可以同时运行的生产执行数量。这可能导致并发执行过多,从而扰乱事件循环,导致性能下降和无响应。
🌐 In regular mode, n8n doesn't limit how many production executions may run at the same time. This can lead to a scenario where too many concurrent executions thrash the event loop, causing performance degradation and unresponsiveness.
为防止这种情况,你可以在常规模式下为生产执行设置并发限制。使用此方法可以控制同时运行的生产执行数量,并将超出限制的并发生产执行排入队列。这些执行将保持在队列中,直到有并发容量可用,然后按先进先出(FIFO)的顺序处理。
🌐 To prevent this, you can set a concurrency limit for production executions in regular mode. Use this to control how many production executions run concurrently, and queue up any concurrent production executions over the limit. These executions remain in the queue until concurrency capacity frees up, and are then processed in FIFO order.
并发控制默认情况下是禁用的。要启用它,请执行以下操作:
🌐 Concurrency control is disabled by default. To enable it:
1 | |
请注意:
🌐 Keep in mind:
- 并发控制仅适用于生产执行:即通过 webhook 或 触发器 节点启动的执行。它不适用于其他类型的执行,例如手动执行、子工作流执行、错误执行或通过 CLI 启动的执行。
- 你无法重新尝试排队的执行。取消或删除排队的执行也会将其从队列中移除。
- 在实例启动时,n8n 会恢复排队的执行任务,直到达到并发限制,其余的任务会重新加入队列。
- 要监控并发控制,请查看日志中被添加到队列和被释放的执行情况。在未来的版本中,n8n 将在用户界面中显示并发控制。
启用并发控制后,你可以在项目或工作流的“执行”选项卡顶部查看活动执行次数和配置的限制。
🌐 When you enable concurrency control, you can view the number of active executions and the configured limit at the top of a project's or workflow's executions tab.
与队列模式比较(Comparison to queue mode)#
在队列模式下,你可以使用--concurrency标志来控制一个工作者可以同时运行多少个作业。
🌐 In queue mode, you can control how many jobs a worker may run concurrently using the --concurrency flag.
队列模式下的并发控制与常规模式下的并发控制是独立的机制,但环境变量 N8N_CONCURRENCY_PRODUCTION_LIMIT 控制它们两者。在队列模式下,如果该变量设置为除 -1 之外的值,n8n 会从该变量中获取限制;如果未设置,则回退到 --concurrency 标志或其默认值。
🌐 Concurrency control in queue mode is a separate mechanism from concurrency control in regular mode, but the environment variable N8N_CONCURRENCY_PRODUCTION_LIMIT controls both of them. In queue mode, n8n takes the limit from this variable if set to a value other than -1, falling back to the --concurrency flag or its default.