3

我一直在进行大型多服务器 Node.js 部署。技术栈:

服务器 1(Ubuntu 12.04):

  • Node.js API Server(Express 应用,用于输入)
  • Node.js Push Server(100个worker,用于发送结果)
  • 雷迪斯
  • 豆茎

服务器 2-4(Ubuntu 12.04):

  • Node.js引擎服务器(每台服务器 150 个工作人员,用于计算)

所有 Node.js 应用程序都使用 Nodestalker 作为他们的 Beanstalkd 客户端。

启动所有服务器后,一个或多个 Node.js 应用程序将反复崩溃并出现此错误(LongJohn 输出):

Error: read ECONNRESET
    at errnoException (net.js:901:11)
    at onread (net.js:556:19)
---------------------------------------------
    at Readable.on (_stream_readable.js:681:33)
    at BeanstalkClient.command (/opt/app_deployment/engine/node_modules/nodestalkerib/beanstalk_client.js:248:13)
    at BeanstalkClient.watch    (/opt/app_deployment/engine/node_modules/nodestalker/l/beanstalk_client.js:285:14)
    at consumer (/opt/app_deployment/engine/scrape.js:52:12)
    at listOnTimeout (timers.js:110:15)
---------------------------------------------
    at Array.<anonymous> (/opt/app_deployment/engine/compute.js:215:9)
    at fire (/opt/app_deployment/engine/node_modules/jquery/lib/node-jquery.js:999:)
    at self.fireWith (/opt/app_deployment/engine/node_modules/jquery/lib/node-jquerjs:1109:7)
    at Object.<anonymous> (/opt/app_deployment/engine/node_modules/jquery/lib/node-uery.js:1236:16)
    at fire (/opt/app_deployment/common/node_modules/jquery/lib/node-jquery.js:999:)
    at self.fireWith (/opt/app_deployment/common/node_modules/jquery/lib/node-jquerjs:1109:7)
    at self.fire (/opt/app_deployment/common/node_modules/jquery/lib/node-jquery.js116:10)
    at /opt/app_deployment/common/results.js:18:19

成功打开所有连接的服务器工作正常,直到手动重新启动。

每个引擎服务器的每个工作人员都有 2 个开放的 Beanstalk 客户端,每个推送工作人员也有一个 Beanstalkd 客户端。这将导致在任何给定时间与 Beanstalk 建立约 1000 个打开的连接。

经过研究,似乎我已经达到了打开文件描述符的限制(默认为 1024)。但是,无论我将限制提高到什么程度,在我重新启动进程后,错误仍然几乎立即发生。快速 lsof 显示没有连接泄漏。

作为 root,我已经ulimit -n 4096在每个运行进程的用户上运行,这会立即准确地反映在ulimit -n之后。

我还在limits.conf 中为所有相关用户编辑了软和硬nofile 限制。这可能是巧合,也可能不是巧合,但这些值不适用于服务器重新启动时的用户。

我的limits.conf:

beanstalkd soft nofile 4096
beanstalkd hard nofile 4096

服务器重新启动后su beanstalkd仍然ulimit -n显示 1024。我session required pam_limits.so取消了/etc/pam.d/common-session所有其他 pam.d 文件的注释。

简而言之,所有迹象都指向文件描述符的障碍,但无论将限制提高到什么程度,错误仍然会发生。提前致谢!

4

0 回答 0