0

我正在将一个 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

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

提前致谢!

4

1 回答 1

0

我想我找到了一个临时解决方案。主要问题是我的电脑只剩下 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.enablefalse解决问题,但我想我现在必须在每次更改时手动重新获取架构。

我仍然不知道为什么node每次graphql fetch 的过程都会增加,即使模式没有改变。

于 2021-06-21T23:07:08.760 回答