自托管并发控制#
¥Self-hosted concurrency control
Only for self-hosted n8n
本文档适用于自托管并发控制。阅读 云端并发性 了解 n8n Cloud 账户的并发性。
¥This document is for self-hosted concurrency control. Read Cloud concurrency to learn how concurrency works with n8n Cloud accounts.
在常规模式下,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 或 trigger 节点启动的操作。它不适用于其他类型的操作,例如手动执行、子工作流执行、错误执行或通过 CLI 启动的操作。
¥Concurrency control applies only to production executions: those started from a webhook or trigger node. It doesn't apply to any other kinds, such as manual executions, sub-workflow executions, error executions, or started from CLI.
- 无法重试已排队的执行。取消或删除已排队的执行也会将其从队列中移除。
¥You can't retry queued executions. Cancelling or deleting a queued execution also removes it from the queue.
- 实例启动时,n8n 会恢复已排队的执行任务,直至达到并发限制,并将剩余任务重新排队。
¥On instance startup, n8n resumes queued executions up to the concurrency limit and re-enqueues the rest.
- 要监控并发控制,请查看日志,了解任务被添加到队列和被释放的情况。在未来的版本中,n8n 将在用户界面中显示并发控制。
¥To monitor concurrency control, watch logs for executions being added to the queue and released. In a future version, n8n will show concurrency control in the UI.
启用并发控制后,你可以在项目或工作流的“执行”选项卡顶部查看活动执行次数和配置的限制。
¥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.