Skip to content

Commit 8c6821e

Browse files
gautamg795Convex, Inc.
authored and
Convex, Inc.
committed
report 512MB when running in the dynamic lambda (#37051)
GitOrigin-RevId: 6fa1d9849c6af5f78ee7eacb1908bcc81d1a0656
1 parent f3997fa commit 8c6821e

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

npm-packages/node-executor/src/executor.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,25 @@ import { buildDeps, BuildDepsRequest } from "./build_deps";
2929
import { ConvexError, JSONValue } from "convex/values";
3030
import { logDebug, logDurationMs } from "./log";
3131

32+
// Small hack to detect if we're running in the dynamic or static lambda.
33+
const AWS_LAMBDA_EXECUTOR_TYPE = (
34+
process.env.AWS_LAMBDA_FUNCTION_NAME ?? ""
35+
).endsWith("-d")
36+
? "DYNAMIC"
37+
: "STATIC";
38+
3239
const AWS_LAMBDA_FUNCTION_MEMORY_SIZE = parseInt(
3340
process.env.AWS_LAMBDA_FUNCTION_MEMORY_SIZE ?? "512",
3441
10,
3542
);
3643

44+
// We allocate extra memory (4GB) for dynamic lambdas, but don't want to charge customers for this implementation detail.
45+
// We report 512MB (which may be an undercharge) but this should only be a temporary state while the static lambda deploys.
46+
const AWS_LAMBDA_BILLED_MEMORY_SIZE =
47+
AWS_LAMBDA_EXECUTOR_TYPE === "DYNAMIC"
48+
? 512
49+
: AWS_LAMBDA_FUNCTION_MEMORY_SIZE;
50+
3751
// When we bundle commonJS modules as ESM with esbuild, the bundled code might still use
3852
// `require`, exports, module, __dirname or __filename despite being in ESM.
3953
//
@@ -102,6 +116,14 @@ export async function invoke(
102116

103117
logDurationMs("Total invocation time", start);
104118
logDebug(`Memory allocated: ${AWS_LAMBDA_FUNCTION_MEMORY_SIZE}MB`);
119+
if (
120+
AWS_LAMBDA_EXECUTOR_TYPE === "DYNAMIC" &&
121+
AWS_LAMBDA_BILLED_MEMORY_SIZE !== AWS_LAMBDA_FUNCTION_MEMORY_SIZE
122+
) {
123+
logDebug(
124+
`Dynamic executor used: reporting ${AWS_LAMBDA_BILLED_MEMORY_SIZE}MB of billed memory`,
125+
);
126+
}
105127
responseStream.write(JSON.stringify(result));
106128
}
107129

@@ -232,7 +254,7 @@ export async function execute(
232254
downloadTimeMs,
233255
totalExecutorTimeMs,
234256
syscallTrace: syscalls.syscallTrace,
235-
memoryAllocatedMb: AWS_LAMBDA_FUNCTION_MEMORY_SIZE,
257+
memoryAllocatedMb: AWS_LAMBDA_BILLED_MEMORY_SIZE,
236258
};
237259
}
238260

0 commit comments

Comments
 (0)