Skip to content

Commit

Permalink
[poller-lambdas] limit concurrency of lambda to two (rather than one)
Browse files Browse the repository at this point in the history
only one lambda should be happening at once, however the lambda queues up its next execution whilst it's still running, so concurrency of 2 should prevent throttling, but also guard against it going haywire
  • Loading branch information
twrichards committed Dec 13, 2024
1 parent 7cf1ec3 commit 7260e5c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions cdk/lib/__snapshots__/newswires.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ exports[`The Newswires stack matches the snapshot 1`] = `
},
"MemorySize": 128,
"RecursiveLoop": "Allow",
"ReservedConcurrentExecutions": 1,
"ReservedConcurrentExecutions": 2,
"Role": {
"Fn::GetAtt": [
"EXAMPLEfixedfrequencyLambdaServiceRoleBA2F232F",
Expand Down Expand Up @@ -1267,7 +1267,7 @@ exports[`The Newswires stack matches the snapshot 1`] = `
},
"MemorySize": 128,
"RecursiveLoop": "Allow",
"ReservedConcurrentExecutions": 1,
"ReservedConcurrentExecutions": 2,
"Role": {
"Fn::GetAtt": [
"EXAMPLElongpollingLambdaServiceRoleF2C4DC08",
Expand Down
6 changes: 5 additions & 1 deletion cdk/lib/constructs/pollerLambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,18 @@ export class PollerLambda {
);
}

// only one lambda should be happening at once, however the lambda queues up its next execution whilst it's still running
// so concurrency of 2 should prevent throttling, but also guard against it going haywire
const reservedConcurrentExecutions = 2;

const functionName = `${scope.stack}-${scope.stage}-${lambdaAppName}`;
const lambda = new GuLambdaFunction(scope, `${pollerId}Lambda`, {
app: lambdaAppName, // varying app tag for each lambda allows riff-raff to find by tag
functionName,
runtime: LAMBDA_RUNTIME,
architecture: LAMBDA_ARCHITECTURE,
recursiveLoop: RecursiveLoop.ALLOW, // this allows the lambda to indirectly call itself via the SQS queue
reservedConcurrentExecutions: 1,
reservedConcurrentExecutions,
environment: {
[POLLER_LAMBDA_ENV_VAR_KEYS.INGESTION_LAMBDA_QUEUE_URL]:
ingestionLambdaQueue.queueUrl,
Expand Down

0 comments on commit 7260e5c

Please sign in to comment.