node.js - 内存不足异常 - 未处理的 RangeError
问题描述
我创建了一个 NodeJS 服务,它从 ActiveMQ 队列中读取消息、远程设置、获取这些消息、对其进行处理并将一些数据推送到 GUI。
我面临的问题是在尝试在 NodeJS 端处理这些消息时,当它们以大约的速度快速进入 ActiveMQ 队列时。每秒 5 条消息 (JSON),每条 JSON 消息的大小约为 18kb。传入的消息被写入文件,保存到中间 MSSQL 表中,一旦保存,JSON 文件就会移动到 Processed 文件夹。
环境设置是:
- NodeJS 版本 8.9.4。
- ActiveMQ 版本 5.15.4。
- Java 版本 1.8.0_171。
- 在主 Node 进程旁边创建了三个工作进程来处理消息负载。
工作人员是使用节点模块“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");
}
}
}
}
什么可能导致此问题?
如果需要任何其他信息,请告诉我。
解决方案
推荐阅读
- swift - 排除 Swift 包中的文件
- python - 值错误:标签的长度必须为“x”python 3
- python - 如何在硒中选择没有选项标签的弹出菜单选项?
- pyspark - 获取上个月的值
- math - 计算一个正方形在旋转 45 度后需要缩小多少
- java - 此版本不符合 Google Play 64 位要求。本机 Java 应用程序的所有 .so 都已存在
- c - If else C 中的错误
- kubernetes - 无法将 NFS 挂载设置为 Azure AKS 节点上 kubernetes pod 的默认存储
- python - 在 Python 中使用 For 循环并行循环
- python-3.x - 如何在表格中正确显示汉字