简体   繁体   English

Cloud Run 上的 Nest.js 使用公牛运行计划作业会引发随机连接错误?

[英]Nest.js on Cloud Run running scheduled jobs with bull throws random connection errors?

I'm trying to perform 3rd party API requests for fetching loads of paginated data (an array of ~16k objects with each object having ~25 key/value pairs), i thought i was getting rate limited but the requests run fine locally and in production as well when triggered manually我正在尝试执行第 3 方 API 请求以获取大量分页数据(约 16k 个对象的数组,每个 object 具有约 25 个键/值对),我认为我的速率受到限制,但请求在本地和在手动触发时也可以生产

but when they run on schedule by bull i get these random connection errors但是当他们按计划运行时,我得到了这些随机连接错误

errorMessage: 'Client network socket disconnected before secure TLS connection was established',
errorStack: 'Error: Client network socket disconnected before secure TLS connection was established\n' +
  '    at connResetException (node:internal/errors:691:14)\n' +
  '    at TLSSocket.onConnectEnd (node:_tls_wrap:1585:19)\n' +
  '    at TLSSocket.emit (node:events:402:35)\n' +
  '    at endReadableNT (node:internal/streams/readable:1343:12)\n' +
  '    at processTicksAndRejections (node:internal/process/task_queues:83:21)'
errorMessage: 'socket hang up',
errorStack: 'Error: socket hang up\n' +
  '    at connResetException (node:internal/errors:691:14)\n' +
  '    at TLSSocket.socketOnEnd (node:_http_client:471:23)\n' +
  '    at TLSSocket.emit (node:events:402:35)\n' +
  '    at endReadableNT (node:internal/streams/readable:1343:12)\n' +
  '    at processTicksAndRejections (node:internal/process/task_queues:83:21)'
errorMessage: 'read ECONNRESET',
errorStack: 'Error: read ECONNRESET\n' +
  '    at TLSWrap.onStreamRead (node:internal/stream_base_commons:220:20)'
errorMessage: 'write ECONNRESET',
errorStack: 'Error: write ECONNRESET\n' +
  '    at WriteWrap.onWriteComplete [as oncomplete] (node:internal/stream_base_commons:98:16)'

I'm running a Nest.js server on Cloud Run我在 Cloud Run 上运行 Nest.js 服务器

Here's my Docker configuration这是我的 Docker 配置

FROM node:16-alpine as build

WORKDIR /app

# Copy and install dependencies first so that they can be cached
COPY package.json .
COPY yarn.lock .
RUN yarn install

# Copy rest of the files and build
COPY . .
RUN yarn build
RUN ls -a

FROM node:16-alpine

WORKDIR /app

# Copy and install dependencies first so that they can be cached
COPY package.json .
RUN yarn install --prod

# Copy files and dist folder from build image
COPY . .
COPY --from=build /app/dist ./dist
RUN ls -a


EXPOSE 3000

CMD ["node", "dist/src/main.js"]

This instance has 4GiB memory, 2 CPUs, request timeout set to 2400 seconds and maximum requests per container to 80, minimum & maximum number of instances are set to 1 and 25 respectively.此实例有 4GiB memory,2 个 CPU,请求超时设置为 2400 秒,每个容器的最大请求数为 80,最小和最大实例数分别设置为 1 和 25。

And all of the traffic is routed through a VPC connector, it is a f1-micro instance with min instances set to 2 and max 10.所有流量都通过 VPC 连接器路由,它是一个f1-micro实例,最小实例设置为 2,最大实例设置为 10。

For bull there are 5 different workers setup which are randomly assigned to the job对于公牛,有 5 个不同的工人设置,它们被随机分配到工作中

I wasn't getting these errors on App Engine where this was previously deployed to我在之前部署到的 App Engine 上没有收到这些错误

Does anyone know what's causing this?有谁知道这是什么原因造成的?

I suggest review the Concurrency value set in Cloud Run.我建议查看 Cloud Run 中设置的并发值。 By default each Cloud Run container can receive 80 requests at the same time but you can increase to a maxim of 1000, you can modify this value depending if your code can process parallel requests at the same time, in this link you can find how to set your concurrency value to Cloud Run默认情况下,每个 Cloud Run 容器可以同时接收 80 个请求,但您最多可以增加到 1000 个,您可以根据您的代码是否可以同时处理并行请求来修改此值,在此链接中您可以找到如何将您的并发值设置为 Cloud Run

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM