首页 > 解决方案 > 内存不足异常 - 未处理的 RangeError

问题描述

我创建了一个 NodeJS 服务,它从 ActiveMQ 队列中读取消息、远程设置、获取这些消息、对其进行处理并将一些数据推送到 GUI。

我面临的问题是在尝试在 NodeJS 端处理这些消息时,当它们以大约的速度快速进入 ActiveMQ 队列时。每秒 5 条消息 (JSON),每条 JSON 消息的大小约为 18kb。传入的消息被写入文件,保存到中间 MSSQL 表中,一旦保存,JSON 文件就会移动到 Processed 文件夹。

环境设置是:

工作人员是使用节点模块“Workerpool”创建的。 https://github.com/josdejong/workerpool

RAM: 2 GB
Processor: Intel Xeon Dual Core processor @2.27GHz 
OS: Windows Server 2008 R2

在处理来自 ActiveMQ 队列的大约 3000 条消息后,我一直遇到一个Unhandled rejection Range Error: Out of Memory Exception问题,消息从外部源以 200 毫秒/消息的频率推送到队列。

编码:


message.readString('utf-8', function (err, body) {
  fs.writeFile('/path/to/writefileto', JSON.stringify(body), function(err) {
  if(err) {
    // handle the error
  } else {
    /* if the file exists in the source path, move to a Processed path */
    if(fs.existsSync('/path/writtento')) {
      fs.rename('/path/writtento', '/path/to/processedDir', function(err) {
         if(!err) {
           console.log("Successful in moving the file to Processed path");
         }
      }
    }
  }

什么可能导致此问题?

如果需要任何其他信息,请告诉我。

标签: node.jsactivemqworker-pool

解决方案


推荐阅读