Skip to content

Commit

Permalink
Single concurrency (#5)
Browse files Browse the repository at this point in the history
* Stop gap: Single lambda integration with forced concurrency = 1

* Hide separate routing for write endpoints

* cargo fmt

* remove reset collections
  • Loading branch information
rhlbhatnagar authored Jan 3, 2024
1 parent 0d5ce46 commit d51b784
Showing 1 changed file with 31 additions and 28 deletions.
59 changes: 31 additions & 28 deletions cdk/lib/cdk-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,6 @@ export class QdrantLambdaStack extends Stack {

const qdrantReadLambda = new Function(this, "QdrantReadLambda", {
...commonLambdaParams,
code: Code.fromAsset("../target/lambda/main_lambda/bootstrap.zip"),
filesystem: LambdaFilesystem.fromEfsAccessPoint(accessPoint, "/mnt/efs"),
vpc: vpc,
});

// IMP: On fresh AWS accounts the min concurrency limit = max lambda concurrency = 10,
// If that's the case won't be able to reserve a concurrent execution for this lambda
// as this takes your free lambda limit (max - reserved) < min.

// So you might need to request in your max concurrency limit.
// https://console.aws.amazon.com/servicequotas/home

const qdrantWriteLambda = new Function(this, "QdrantWriteLambda", {
...commonLambdaParams,
// Write lambda has a forced concurrency of 1. So don't run into race conditions on the network file system.
reservedConcurrentExecutions: 1,
code: Code.fromAsset("../target/lambda/main_lambda/bootstrap.zip"),
filesystem: LambdaFilesystem.fromEfsAccessPoint(accessPoint, "/mnt/efs"),
Expand All @@ -67,24 +52,42 @@ export class QdrantLambdaStack extends Stack {
qdrantReadLambda
);

const writeIntegration = new HttpLambdaIntegration(
"WriteIntegration",
qdrantWriteLambda
);

// By default, all routes go through the read integration
const httpApi = new HttpApi(this, "QdrantHttpApi", {
defaultIntegration: readIntegration,
});

// Write routes go to the write integration.
writeEndpoints.forEach((endpoint) => {
new HttpRoute(this, endpoint.name, {
httpApi: httpApi,
routeKey: HttpRouteKey.with(endpoint.route, endpoint.method),
integration: writeIntegration,
});
});
// TODO: Uncomment this once we move to separate read + write integrations.

// IMP: On fresh AWS accounts the min concurrency limit = max lambda concurrency = 10,
// If that's the case won't be able to reserve a concurrent execution for this lambda
// as this takes your free lambda limit (max - reserved) < min.

// So you might need to request in your max concurrency limit.
// https://console.aws.amazon.com/servicequotas/home

// const qdrantWriteLambda = new Function(this, "QdrantWriteLambda", {
// ...commonLambdaParams,
// // Write lambda has a forced concurrency of 1. So don't run into race conditions on the network file system.
// reservedConcurrentExecutions: 1,
// code: Code.fromAsset("../target/lambda/main_lambda/bootstrap.zip"),
// filesystem: LambdaFilesystem.fromEfsAccessPoint(accessPoint, "/mnt/efs"),
// vpc: vpc,
// });

// const writeIntegration = new HttpLambdaIntegration(
// "WriteIntegration",
// qdrantWriteLambda
// );

// // Write routes go to the write integration.
// writeEndpoints.forEach((endpoint) => {
// new HttpRoute(this, endpoint.name, {
// httpApi: httpApi,
// routeKey: HttpRouteKey.with(endpoint.route, endpoint.method),
// integration: writeIntegration,
// });
// });

new CfnOutput(this, "ApiGatewayURL", {
value: httpApi.url!,
Expand Down

0 comments on commit d51b784

Please sign in to comment.