简体   繁体   English

NodeJs进程在aws上耗尽内存

[英]NodeJs process running out of memory on aws

I am running a nodeJS app on aws t2micro instance with Mongodb.我正在使用 Mongodb 在 aws t2micro 实例上运行 nodeJS 应用程序。 This is how my index.js file on server looks like这是我服务器上的 index.js 文件的样子

const db = require('./src/db');
const coins = require('./src/scrapers/populate-coins'); 
const scrape = require('./src/scrapers/index.js');
const settings = require('./src/trading/init-settings.js');
const trading = require('./src/trading/index.js');
const server = require('./src/index.js');

Here scrape and trading are processes that run within a setInterval while server handles the API request.这里的抓取和交易是在服务器处理 API 请求时在 setInterval 内运行的过程。 I am using a angular frontend and have deployed the whole thing on single aws t2micro instance with 1GB RAM and 16GB storage.我正在使用 angular 前端,并已将整个事物部署在具有 1GB RAM 和 16GB 存储空间的单个 aws t2micro 实例上。 Things went fine for couple of days until data in db was insignificant.事情顺利几天,直到数据库中的数据微不足道。 Once I had >10K rows of data in one of my tables, API calls started taking a lot of time, as much as 1 minute.一旦我的一个表中有超过 10K 行的数据,API 调用就开始花费大量时间,多达 1 分钟。 In the dev tools it showed the waiting(TTFB) took ~40s.在开发工具中,它显示等待(TTFB)花费了大约 40 秒。 Upon checking the logs I am getting this检查日志后,我得到了这个

0|trading  | Warning: connect.session() MemoryStore is not
0|trading  | designed for a production environment, as it will leak
0|trading  | memory, and will not scale past a single process.
0|trading  | FATAL ERROR: Committing semi space failed. Allocation failed - process out of memory
0|trading  |  1: node::Abort() [node /home/ec2-user/app/bc-trading/index.js]
0|trading  |  2: 0x13740dc [node /home/ec2-user/app/bc-trading/index.js]
0|trading  |  3: v8::Utils::ReportOOMFailure(char const*, bool) [node /home/ec2-user/app/bc-trading/index.js]
0|trading  |  4: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [node /home/ec2-user/app/bc-trading/index.js]
0|trading  |  5: v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [node /home/ec2-user/app/bc-trading/index.js]
0|trading  |  6: v8::internal::Heap::CollectGarbage(v8::internal::GarbageCollector, v8::internal::GarbageCollectionReason, char const*, v8::GCCallbackFlags) [node /home/ec2-user/app/bc-trading/index.js]
0|trading  |  7: v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationSpace) [node /home/ec2-user/app/bc-trading/index.js]
0|trading  |  8: v8::internal::Runtime_AllocateInNewSpace(int, v8::internal::Object**, v8::internal::Isolate*) [node /home/ec2-user/app/bc-trading/index.js]

Can anyone help me figure out what is going on here?谁能帮我弄清楚这里发生了什么? Help will be highly appreciated.帮助将不胜感激。 api 调用的屏幕截图

I'd recommend adding logging to check if the size of the object processed is large or execute the function and monitor the server memory/cpu usage, it could be either mongoDb or the node process that is using all the resources and therefore causing the error/slow responses and also log the server metrics before the start and after the end of each function.我建议添加日志来检查处理的对象的大小是否很大或执行函数并监视服务器内存/cpu 使用情况,它可能是 mongoDb 或正在使用所有资源的节点进程,因此导致错误/slow 响应,并在每个函数开始之前和结束之后记录服务器指标。
You should also consider that running angular , node and mongoDb on 1 gb of ram will cause issues if there are enough records in the db even if it is a dev environment, the node garbage collector might not be able to free up memory and you will end up with a buildup that will slow everything down.您还应该考虑在 1 gb ram 上运行 angular 、 node 和 mongoDb 会导致问题,如果数据库中有足够的记录,即使它是一个开发环境,节点垃圾收集器可能无法释放内存,您将最终会导致一切都变慢的堆积。

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

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