我正在将一个 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 端点,它可能不应该这样做?
我还注意到操场上的查询非常慢,例如返回“hello world”字符串的简单查询需要 2 秒。但是,当我部署 lambda 时,这个问题并没有发生。使用 API Gateway 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
有人知道发生了什么,或者我应该怎么做才能确定根本错误?
提前致谢!