简体   繁体   English

Node.js应用不断崩溃-内存

[英]Node.js App Crashing Constantly - memory

I have a Node.js app that is basically the boilerplate that CONSTANTLY crashes due to this error: 我有一个Node.js应用程序,该应用程序基本上是由于以下错误而崩溃的样板:

an instance of the app crashed: out of memory

I have no idea how this app could crash with 256mb of memory. 我不知道这个应用程序如何在256mb的内存下崩溃。 It does almost nothing server side beside respond to http requests and I am wondering how this could be. 除了响应HTTP请求外,服务器端几乎没有任何作用,我想知道这怎么可能。 Garbage collection problem? 垃圾收集有问题吗?

app.js app.js

 require('newrelic'); //monitoring var express = require('express');//middleware var app = express(); var cfenv = require('cfenv');// Cloud Foundry library var appEnv = cfenv.getAppEnv(); app.use(express.static(__dirname + '/public')); app.listen(appEnv.port, appEnv.bind, function() { console.log("server starting on " + appEnv.url); }); 

UPDATE This appears to be the issue . 更新 这似乎是问题所在 Can't do anything at this point but remove the service. 目前无法执行任何操作,但是请删除该服务。 :( :(

when running an app in a low memory environment, it can happen that garbage collection is not triggered early enough. 在内存不足的环境中运行应用程序时,可能会发生垃圾回收未足够早触发的情况。 You can invoke it manully and see if that helps. 您可以手动调用它,看看是否有帮助。

Add --expose-gc to the start command of your app - eg: --expose-gc添加到应用程序的启动命令-例如:

node --expose-gc myapp.js

Then in your code do this periodically: 然后在您的代码中定期执行此操作:

Global.gc()

In order to monitor the memory consumption of your app you can do a cf curl: 为了监视您的应用程序的内存消耗,您可以执行cf curl:

cf curl /v2/apps/<your app guid>

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

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