NodeJS Lambda误差:阵列缓冲区分配失败

nfs0ujit  于 2023-03-01  发布在  Node.js
关注(0)|答案(1)|浏览(114)

我有一些代码很大的Lambda。当我尝试运行测试时,一切都很好。
部署后,我尝试在AWS控制台中运行它,并看到以下错误:

RangeError: Array buffer allocation failed
at new ArrayBuffer (<anonymous>)
at Object.<anonymous> (/var/task/node_modules/brotli/build/encode.js:21:207)
at Module._compile (node:internal/modules/cjs/loader:1165:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1219:10)
at Module.load (node:internal/modules/cjs/loader:1043:32)
at Function.Module._load (node:internal/modules/cjs/loader:878:12)
at Module.require (node:internal/modules/cjs/loader:1067:19)
at require (node:internal/modules/cjs/helpers:103:18)
at Object.<anonymous> (/var/task/node_modules/brotli/compress.js:1:14)
at Module._compile (node:internal/modules/cjs/loader:1165:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1219:10)
at Module.load (node:internal/modules/cjs/loader:1043:32)
at Function.Module._load (node:internal/modules/cjs/loader:878:12)
at Module.require (node:internal/modules/cjs/loader:1067:19)
at require (node:internal/modules/cjs/helpers:103:18)
at Object.<anonymous> (/var/task/node_modules/brotli/index.js:1:20)
START RequestId: dc611535-421d-4bb9-9632-1f17f016d093 Version: $LATEST
RequestId: dc611535-421d-4bb9-9632-1f17f016d093 Error: Runtime exited with error: exit status 7
Runtime.ExitError
END RequestId: dc611535-421d-4bb9-9632-1f17f016d093
REPORT RequestId: dc611535-421d-4bb9-9632-1f17f016d093  Duration: 16226.67 ms   Billed Duration: 16227 ms   Memory Size: 128 MB Max Memory Used: 60 MB

我看到过类似的案例,涉及最大内存大小,但在我的案例中使用的内存小于最大内存

41zrol4v

41zrol4v1#

128MB的内存,如果你处理非常大的文件,是非常少的,不要忘记,在Lambda函数的CPU分配是直接与分配的内存成比例的,所以,尽量增加内存(至少512MB)。
不管怎样,我不知道代码中涉及到什么逻辑,但是你确定Lambda是这里最好的解决方案吗?涉及到的文件有多大?是ETL、批处理还是其他什么?

相关问题