Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(core): Introduce concurrency control for main mode #9453

Open
wants to merge 69 commits into
base: master
Choose a base branch
from

Conversation

ivov
Copy link
Contributor

@ivov ivov commented May 17, 2024

This PR introduces concurrency control for main mode. This limits how many production executions are allowed to run at the same time in main mode, preventing event loop overload and so improving reliability.

Concurrency control applies only in main mode and only to production executions (i.e. in webhook and trigger modes), not to executions in manual, retry, error, integrated, cli or internal modes.

Summary of changes

Queuing

  • Implement ConcurrencyControlService.
  • Reuse Adi's work in ConcurrencyQueue.
  • Block or let through executions at ActiveExecutions.
  • On releasing an enqueued execution, reset startedAt timestamp.
  • On cancelling an enqueued execution, remove from queue.
  • On retrying an enqueued execution, block retry attempt.
  • On deleting an enqueued execution via Public API, remove from queue.
  • On deleting an enqueued execution via Internal API, remove from queue.
  • On instance startup post crash, exclude enqueued executions from crash recovery.
  • On instance startup post crash, run all enqueued executions.
  • Serve executions prioritizing running over new
  • Ensure queue mode is unaffected by concurrency control.

Envs, logs, tests

  • Add new env var N8N_CONCURRENCY_PRODUCTION_LIMIT.
  • Add logs on throttling and releasing executions.
  • Add tests for ConcurrencyControlService and ConcurrencyQueue.
  • Add telemetry to monitor throttling frequency.

Discussion: https://www.notion.so/n8n/Concurrency-limits-for-main-mode-8b642df5e98a479cadd1cfc4950d27a1

Follow-up to: #8458

@n8n-assistant n8n-assistant bot added core Enhancement outside /nodes-base and /editor-ui n8n team Authored by the n8n team labels May 17, 2024
@luizeof
Copy link
Contributor

luizeof commented Jun 6, 2024

@ivov It would be great if we could configure a worker to only run workflows that have certain tags.

This way we can configure a service for the "critical" tag, another for the "mailing" tag, etc...

@ivov
Copy link
Contributor Author

ivov commented Jun 7, 2024

@ivov It would be great if we could configure a worker to only run workflows that have certain tags.

This way we can configure a service for the "critical" tag, another for the "mailing" tag, etc...

Thanks for your feedback! fyi @jcn8n

packages/cli/src/ActiveExecutions.ts Outdated Show resolved Hide resolved
packages/cli/src/ActiveExecutions.ts Outdated Show resolved Hide resolved
packages/cli/src/License.ts Outdated Show resolved Hide resolved
krynble
krynble previously approved these changes Jun 10, 2024
Copy link
Contributor

@krynble krynble left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

⚠️ Some Cypress E2E specs are failing, please fix them before merging

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Enhancement outside /nodes-base and /editor-ui n8n team Authored by the n8n team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants