可能检测到EventEmitter内存泄漏NodeJS-Lambda



我正在将一个graphql服务器连接到aws lambda,并在执行serverless-offline:时收到此警告

(node:16890) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 SIGINT listeners added to [process]. Use emitter.setMaxListeners() to increase limit
(node:16890) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 SIGTERM listeners added to [process]. Use emitter.setMaxListeners() to increase limit

我不确定这意味着什么,我做了一个快速搜索,看起来lambda中的nodejs进程消耗了很多内存?我不知道这是不是我的情况。

我还注意到,我收到了很多到graphql端点的POST请求消息,这些消息每秒都在记录:

... A LOT MORE ABOVE
offline: POST /dev/graphql (λ: graphql)
offline: (λ: graphql) RequestId: ckq75v15l004t16fo89ckgze1  Duration: 957.66 ms  Billed Duration: 958 ms
offline: POST /dev/graphql (λ: graphql)
offline: (λ: graphql) RequestId: ckq75v3ge004w16fogcfn6e47  Duration: 1166.56 ms  Billed Duration: 1167 ms
offline: POST /dev/graphql (λ: graphql)
offline: (λ: graphql) RequestId: ckq75v5yj004z16fo8ugr87k4  Duration: 1201.69 ms  Billed Duration: 1202 ms
offline: POST /dev/graphql (λ: graphql)
offline: (λ: graphql) RequestId: ckq75v8gk005216fo1g714h9l  Duration: 966.74 ms  Billed Duration: 967 ms
... A LOT MORE BELOW

我可以理解我的处理程序多次获取graphql端点,也许它不应该这样做?

我还注意到操场上的查询速度非常慢,对于一个返回"helloworld"字符串的简单查询,大约需要2秒。然而,当我部署lambda时,这个问题并没有发生。当使用API网关url时,速度要快得多。

这是我的电脑有问题吗?我能解决这个问题吗?

我有时会遇到内存泄漏问题,导致服务器关闭,并抛出以下错误:

<--- Last few GCs --->
[15693:0x10291f000]  1554018 ms: Mark-sweep 2014.3 (2058.8) -> 2013.6 (2058.6) MB, 3415.0 / 1.4 ms  (average mu = 0.078, current mu = 0.006) allocation failure GC in old space requested
[15693:0x10291f000]  1557368 ms: Mark-sweep 2014.6 (2058.6) -> 2013.6 (2057.8) MB, 3298.1 / 10.9 ms  (average mu = 0.047, current mu = 0.015) allocation failure scavenge might not succeed

<--- JS stacktrace --->

这是graphql处理程序:

const resolvers = {
Query: {
hello: () => 'world'
}
};
const app = express();
const server = new ApolloServer({
typeDefs,
resolvers,
});
server.applyMiddleware({ app });
app.get('graphql', graphiql({ endpoint: '/graphql' }));
const handler = serverless(app);
export { handler as graphqlHandler };

和lambda函数:

functions:
graphql:
handler: src/graphql.graphqlHandler
events:
- http:
path: graphql
method: get
cors: true
- http:
path: graphql
method: post
cors: true

有人知道发生了什么吗?或者我应该怎么做才能确定根本错误?

提前感谢!

我想我找到了一个临时解决方案。主要问题是我的电脑只剩下大约2 GB的RAM空间。所以graphql游乐场每2秒钟获取一次本地模式。这是操场配置:

{
"editor.cursorShape": "line",
"editor.fontFamily": "'Source Code Pro', 'Consolas', 'Inconsolata', 'Droid Sans Mono', 'Monaco', monospace",
"editor.fontSize": 14,
"editor.reuseHeaders": true,
"editor.theme": "dark",
"general.betaUpdates": false,
"prettier.printWidth": 80,
"prettier.tabWidth": 2,
"prettier.useTabs": false,
"request.credentials": "omit",
"schema.disableComments": true,
"schema.polling.enable": false, // Fetch enabled
"schema.polling.endpointFilter": "*localhost*",
"schema.polling.interval": 2000, <---- Fetch every 2 seconds
"tracing.hideTracingResponse": true,
"queryPlan.hideQueryPlanResponse": true
}

schema.polling.enable设置为false解决了这个问题,但我想我现在必须在每次更改模式时手动重新绘制它。

我仍然不知道为什么node进程在每次graphql获取中都会增加,即使模式没有改变。

最新更新