Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

feat(workers): split cloud concurrency limits per plan tier (#17007)

Chaker Atallah616f63c3b067
diff --git a/docs/install/reference/limits.mdx b/docs/install/reference/limits.mdx
index 81f6a16c8ef..47329f19474 100644
--- a/docs/install/reference/limits.mdx
+++ b/docs/install/reference/limits.mdx
@@ -16,6 +16,9 @@ when the variable is unset.
<Card title="Execution" icon="bolt" href="#execution">
Run timeout, worker memory, retention.
</Card>
+ <Card title="Concurrent runs" icon="layer-group" href="#concurrent-runs">
+ How many flow runs a project can execute at once.
+ </Card>
<Card title="Files & flow run logs" icon="file" href="#files-&-flow-run-logs">
File sizes, log size, slicing thresholds.
</Card>
@@ -73,6 +76,45 @@ processes a smaller batch of items.
---
+### Concurrent runs
+
+A project can only execute a certain number of flow runs at the same time. On
+Cloud, that number depends on your plan:
+
+| Plan | Concurrent runs per project |
+|---|---|
+| Free | 5 |
+| Plus | 10 |
+| Team | 20 |
+| Enterprise | 30 |
+
+These limits exist because Cloud runs everyone's flows on shared machines. If
+one project could start thousands of runs at once, it would take over the
+capacity that other customers' runs need, and their flows would slow down or
+stall. Capping how many runs each project executes at a time keeps start times
+predictable for everyone.
+
+A run that arrives while the project is at its limit is not lost or failed. It
+waits in a queue and starts automatically as soon as one of the running flows
+finishes. For most workloads this queuing is invisible; it only becomes
+noticeable when a flow receives a large burst of triggers at once, in which
+case the burst is worked through a few runs at a time.
+
+Platform admins can give a specific project a different limit in its settings;
+see [Manage Concurrency](/admin-guide/guides/manage-concurrency). On Cloud a
+per-project value can lower the limit but never raise it above what the plan
+allows.
+
+On self-hosted installations plans don't apply. Enforcement is off by default
+and uses a single limit for every project when enabled:
+
+| Limit | Env var | Self-hosted default |
+|---|---|---|
+| Per-project concurrency enforcement | `AP_PROJECT_RATE_LIMITER_ENABLED` | `false` |
+| Concurrent runs per project | `AP_DEFAULT_CONCURRENT_JOBS_LIMIT` | `5` |
+
+---
+
### Files & flow run logs
Files emitted by actions or triggers are persisted to the database or S3 so a
diff --git a/packages/core/shared/src/lib/management/platform/platform.model.ts b/packages/core/shared/src/lib/management/platform/platform.model.ts
index ba14a0ff286..737968f423b 100644
--- a/packages/core/shared/src/lib/management/platform/platform.model.ts
+++ b/packages/core/shared/src/lib/management/platform/platform.model.ts
@@ -77,6 +77,29 @@ export function isConsumableFeatureId(value: string): value is ConsumableFeature
return Object.values<string>(ConsumableFeatureId).includes(value)
}
+const FREE_PLAN_CONCURRENT_JOBS_LIMIT = 5
+const PLUS_PLAN_CONCURRENT_JOBS_LIMIT = 10
+const TEAM_PLAN_CONCURRENT_JOBS_LIMIT = 20
+const ENTERPRISE_PLAN_CONCURRENT_JOBS_LIMIT = 30
+
+export function getConcurrentJobsLimitForCloudPlan(planName: string | null | undefined): number {
+ switch (planName ?? PlanName.FREE) {
+ case PlanName.FREE:
+ return FREE_PLAN_CONCURRENT_JOBS_LIMIT
+ case PlanName.APPSUMO:
+ case PlanName.FREE_LEGACY:
+ case PlanName.PLUS:
+ case PlanName.PLUS_ANNUAL:
+ case PlanName.PLUS_CHAT:
+ return PLUS_PLAN_CONCURRENT_JOBS_LIMIT
+ case PlanName.TEAM:
+ case PlanName.TEAM_ANNUAL:
+ return TEAM_PLAN_CONCURRENT_JOBS_LIMIT
+ default:
+ return ENTERPRISE_PLAN_CONCURRENT_JOBS_LIMIT
+ }
+}
+
export const PlatformPlan = z.object({
...BaseModelSchema,
diff --git a/packages/server/api/src/app/workers/job-queue/interceptors/rate-limiter-interceptor.ts b/packages/server/api/src/app/workers/job-queue/interceptors/rate-limiter-interceptor.ts
index 0213dd8d186..042da027a1a 100644
--- a/packages/server/api/src/app/workers/job-queue/interceptors/rate-limiter-interceptor.ts
+++ b/packages/server/api/src/app/workers/job-queue/interceptors/rate-limiter-interceptor.ts
@@ -1,6 +1,6 @@
import { isNil, PlatformId, tryCatch, tryCatchSync } from '@activepieces/core-utils'
import { apDayjsDuration } from '@activepieces/server-utils'
-import { ApEdition, ExecuteFlowJobData, getDefaultJobPriority, JOB_PRIORITY, JobData, PlanName, RATE_LIMIT_PRIORITY, RunEnvironment, WorkerJobType } from '@activepieces/shared'
+import { ApEdition, ExecuteFlowJobData, getConcurrentJobsLimitForCloudPlan, getDefaultJobPriority, JOB_PRIORITY, JobData, RATE_LIMIT_PRIORITY, RunEnvironment, WorkerJobType } from '@activepieces/shared'
import { Job } from 'bullmq'
import { FastifyBaseLogger } from 'fastify'
import { z } from 'zod'
@@ -20,10 +20,6 @@ import { jobQueue } from '../job-queue'
const RATE_LIMIT_WORKER_JOB_TYPES = [WorkerJobType.EXECUTE_FLOW]
const ParkedMember = z.tuple([z.string(), z.string(), z.number()])
-const FREE_CONCURRENT_JOBS_LIMIT = 5
-const SELF_SERVE_CONCURRENT_JOBS_LIMIT = 15
-const ENTERPRISE_CONCURRENT_JOBS_LIMIT = 30
-
async function resolveFlowGroupId(jobData: ExecuteFlowJobData, log: FastifyBaseLogger): Promise<string | null> {
const { data: workerGroupsEnabled } = await tryCatch(() => platformWorkerGroupService(log).isWorkerGroupsEnabled({ platformId: jobData.platformId }))
if (workerGroupsEnabled !== true) {
@@ -54,39 +50,27 @@ async function getMaxConcurrentJobsForPlatformPlan({ platformId, log }: { platfo
}
const cachedPlanName = await distributedStore.get<string>(getPlatformPlanNameKey(platformId))
if (!isNil(cachedPlanName)) {
- return concurrencyLimitForCloudPlan(cachedPlanName)
+ return getConcurrentJobsLimitForCloudPlan(cachedPlanName)
}
const { data: platform } = await tryCatch(() => platformService(log).getOneWithPlan(platformId))
const planName = platform?.plan.plan ?? null
if (!isNil(planName)) {
await distributedStore.put(getPlatformPlanNameKey(platformId), planName, PLATFORM_PLAN_NAME_TTL_SECONDS)
}
- return concurrencyLimitForCloudPlan(planName)
-}
-
-function concurrencyLimitForCloudPlan(planName: string | null): number {
- switch (planName ?? PlanName.FREE) {
- case PlanName.FREE:
- return FREE_CONCURRENT_JOBS_LIMIT
- case PlanName.APPSUMO:
- case PlanName.FREE_LEGACY:
- case PlanName.PLUS:
- case PlanName.PLUS_ANNUAL:
- case PlanName.PLUS_CHAT:
- case PlanName.TEAM:
- case PlanName.TEAM_ANNUAL:
- return SELF_SERVE_CONCURRENT_JOBS_LIMIT
- default:
- return ENTERPRISE_CONCURRENT_JOBS_LIMIT
- }
+ return getConcurrentJobsLimitForCloudPlan(planName)
}
async function getMaxConcurrentJobs({ poolId, platformId, projectId, log }: { poolId: string | null, platformId: PlatformId, projectId: string, log: FastifyBaseLogger }): Promise<number> {
- // Explicit per-project limit (set via the By-project table / concurrency pool) overrides everything.
+ // Explicit per-project limit (set via the By-project table / concurrency pool) overrides the
+ // self-hosted default, but on cloud it is clamped to the platform plan's limit.
if (!isNil(poolId)) {
const { data: value, error } = await tryCatch(() => concurrencyPoolService(log).getPoolLimit(poolId))
if (error === null && !isNil(value)) {
- return value
+ if (system.getEdition() !== ApEdition.CLOUD) {
+ return value
+ }
+ const cloudPlanLimit = await getMaxConcurrentJobsForPlatformPlan({ platformId, log })
+ return Math.min(value, cloudPlanLimit)
}
}
const planLimit = await getMaxConcurrentJobsForPlatformPlan({ platformId, log })
diff --git a/packages/server/api/test/unit/app/workers/job-queue/interceptors/rate-limiter-interceptor.test.ts b/packages/server/api/test/unit/app/workers/job-queue/interceptors/rate-limiter-interceptor.test.ts
index 264f7e107c2..3d7c4eaac61 100644
--- a/packages/server/api/test/unit/app/workers/job-queue/interceptors/rate-limiter-interceptor.test.ts
+++ b/packages/server/api/test/unit/app/workers/job-queue/interceptors/rate-limiter-interceptor.test.ts
@@ -462,13 +462,59 @@ describe('rateLimiterInterceptor', () => {
expect(result.verdict).toBe(InterceptorVerdict.REJECT)
})
+ it('should clamp a pool override above the plan limit on cloud edition', async () => {
+ vi.spyOn(system, 'getEdition').mockReturnValue(ApEdition.CLOUD)
+ vi.spyOn(system, 'getNumberOrThrow').mockImplementation((prop) => {
+ if (prop === AppSystemProp.FLOW_TIMEOUT_SECONDS) return 600
+ if (prop === AppSystemProp.DEFAULT_CONCURRENT_JOBS_LIMIT) return 100
+ return 0
+ })
+ const projectId = `proj-${crypto.randomUUID()}`
+ const platformId = `plat-${crypto.randomUUID()}`
+ const poolId = `pool-${crypto.randomUUID()}`
+ const jobData = createFlowJobData({ projectId, platformId })
+
+ await distributedStore.put(getPlatformPlanNameKey(platformId), PlanName.FREE)
+ await distributedStore.put(getProjectConcurrencyPoolKey(projectId), poolId)
+ await distributedStore.put(getConcurrencyPoolLimitKey(poolId), 50)
+
+ for (let i = 0; i < 5; i++) {
+ const r = await rateLimiterInterceptor.preDispatch({ jobId: `job-${i}`, jobData, job: createMockJob(), log: mockLog })
+ expect(r.verdict).toBe(InterceptorVerdict.ALLOW)
+ }
+
+ const result = await rateLimiterInterceptor.preDispatch({ jobId: 'job-overflow', jobData, job: createMockJob(), log: mockLog })
+ expect(result.verdict).toBe(InterceptorVerdict.REJECT)
+ })
+
+ it('should keep a pool override below the plan limit on cloud edition', async () => {
+ vi.spyOn(system, 'getEdition').mockReturnValue(ApEdition.CLOUD)
+ vi.spyOn(system, 'getNumberOrThrow').mockImplementation((prop) => {
+ if (prop === AppSystemProp.FLOW_TIMEOUT_SECONDS) return 600
+ if (prop === AppSystemProp.DEFAULT_CONCURRENT_JOBS_LIMIT) return 100
+ return 0
+ })
+ const projectId = `proj-${crypto.randomUUID()}`
+ const platformId = `plat-${crypto.randomUUID()}`
+ const poolId = `pool-${crypto.randomUUID()}`
+ const jobData = createFlowJobData({ projectId, platformId })
+
+ await distributedStore.put(getPlatformPlanNameKey(platformId), PlanName.FREE)
+ await distributedStore.put(getProjectConcurrencyPoolKey(projectId), poolId)
+ await distributedStore.put(getConcurrencyPoolLimitKey(poolId), 1)
+
+ await rateLimiterInterceptor.preDispatch({ jobId: 'job-1', jobData, job: createMockJob(), log: mockLog })
+ const result = await rateLimiterInterceptor.preDispatch({ jobId: 'job-2', jobData, job: createMockJob(), log: mockLog })
+ expect(result.verdict).toBe(InterceptorVerdict.REJECT)
+ })
+
it.each([
- [PlanName.PLUS, 15],
- [PlanName.PLUS_ANNUAL, 15],
- [PlanName.PLUS_CHAT, 15],
- [PlanName.TEAM, 15],
- [PlanName.TEAM_ANNUAL, 15],
- [PlanName.APPSUMO, 15],
+ [PlanName.PLUS, 10],
+ [PlanName.PLUS_ANNUAL, 10],
+ [PlanName.PLUS_CHAT, 10],
+ [PlanName.TEAM, 20],
+ [PlanName.TEAM_ANNUAL, 20],
+ [PlanName.APPSUMO, 10],
[PlanName.ENTERPRISE, 30],
])('should allow %s up to %i concurrent jobs and reject beyond it', async (planName, limit) => {
vi.spyOn(system, 'getEdition').mockReturnValue(ApEdition.CLOUD)
diff --git a/packages/web/public/locales/en/translation.json b/packages/web/public/locales/en/translation.json
index e89186b8969..d9886014013 100644
--- a/packages/web/public/locales/en/translation.json
+++ b/packages/web/public/locales/en/translation.json
@@ -623,6 +623,7 @@
"Default": "Default",
"The rate limiting feature is disabled. Enable the PROJECT_RATE_LIMITER_ENABLED environment variable to use this feature.": "The rate limiting feature is disabled. Enable the PROJECT_RATE_LIMITER_ENABLED environment variable to use this feature.",
"Maximum number of flows that can run at the same time for this project": "Maximum number of flows that can run at the same time for this project",
+ "Maximum number of flows that can run at the same time for this project, up to the {value} allowed by your plan": "Maximum number of flows that can run at the same time for this project, up to the {value} allowed by your plan",
"Active Flows Limit": "Active Flows Limit",
"Unlimited": "Unlimited",
"Maximum number of enabled flows in this project. Leave empty for no limit.": "Maximum number of enabled flows in this project. Leave empty for no limit.",
diff --git a/packages/web/src/app/components/project-settings/general/index.tsx b/packages/web/src/app/components/project-settings/general/index.tsx
index de1566b1640..6c56b53fe89 100644
--- a/packages/web/src/app/components/project-settings/general/index.tsx
+++ b/packages/web/src/app/components/project-settings/general/index.tsx
@@ -1,6 +1,8 @@
import {
+ ApEdition,
ApFlagId,
ColorName,
+ getConcurrentJobsLimitForCloudPlan,
PICKABLE_COLOR_NAMES,
PlatformRole,
PROJECT_COLOR_PALETTE,
@@ -60,6 +62,14 @@ export const GeneralSettings = ({ form }: GeneralSettingsProps) => {
const { data: defaultConcurrentJobsLimit } = flagsHooks.useFlag<number>(
ApFlagId.DEFAULT_CONCURRENT_JOBS_LIMIT,
);
+ const { data: edition } = flagsHooks.useFlag<ApEdition>(ApFlagId.EDITION);
+ const isCloud = edition === ApEdition.CLOUD;
+ const planConcurrentJobsLimit = getConcurrentJobsLimitForCloudPlan(
+ platform.plan.plan,
+ );
+ const concurrentJobsPlaceholderValue = isCloud
+ ? planConcurrentJobsLimit
+ : defaultConcurrentJobsLimit;
const showGeneralSettings = project.type === ProjectType.TEAM;
const showExternalIdSettings =
platform.plan.embeddingEnabled && platformRole === PlatformRole.ADMIN;
@@ -219,19 +229,27 @@ export const GeneralSettings = ({ form }: GeneralSettingsProps) => {
id="maxConcurrentJobs"
type="number"
min={1}
+ max={isCloud ? planConcurrentJobsLimit : undefined}
placeholder={
- defaultConcurrentJobsLimit
+ concurrentJobsPlaceholderValue
? t('Default ({value})', {
- value: defaultConcurrentJobsLimit,
+ value: concurrentJobsPlaceholderValue,
})
: t('Default')
}
value={field.value ?? ''}
- onChange={(e) =>
+ onChange={(e) => {
+ if (!e.target.value) {
+ field.onChange(null);
+ return;
+ }
+ const value = Number(e.target.value);
field.onChange(
- e.target.value ? Number(e.target.value) : null,
- )
- }
+ isCloud
+ ? Math.min(value, planConcurrentJobsLimit)
+ : value,
+ );
+ }}
onClear={() => field.onChange(null)}
disabled={form.formState.disabled || !isRateLimiterEnabled}
/>
@@ -240,6 +258,11 @@ export const GeneralSettings = ({ form }: GeneralSettingsProps) => {
? t(
'The rate limiting feature is disabled. Enable the PROJECT_RATE_LIMITER_ENABLED environment variable to use this feature.',
)
+ : isCloud
+ ? t(
+ 'Maximum number of flows that can run at the same time for this project, up to the {value} allowed by your plan',
+ { value: planConcurrentJobsLimit },
+ )
: t(
'Maximum number of flows that can run at the same time for this project',
)}