简体   繁体   English

带Express Server和pm2的可能的node.js内存过度使用

[英]possible node.js memory overuse w/ express server and pm2

I'm working on one part of a set of services that work together for an app/platform. 我正在为一组应用程序/平台一起工作的一组服务中的一部分。 The area I'm needing help on is in a vanilla express server that we use to serve up our client app (a react app, to be specific). 我需要帮助的区域是我们用于提供客户端应用程序(具体来说是React应用程序)的香草快递服务器。 We have a number of other services running on other node processes that our client app interacts with and consumes. 我们在客户端应用程序与之交互和使用的其他节点进程上运行着许多其他服务。

For the time being, it's a really lightweight express server that simply uses res.sendfile() to send the html file down to the client. 目前,这是一个真正的轻量级快递服务器,仅使用res.sendfile()将html文件发送到客户端。 We'll eventually transition to a more isomorphic (yay for buzzwords) approach that renders on the server. 最终,我们将过渡到在服务器上呈现的同构(对流行语来说也是)方法。 We use the fantastic pm2 module to monitor and configure our node processes on the server, and that's where my main question lies. 我们使用出色的pm2模块来监视和配置服务器上的节点进程,这就是我的主要问题。

Here's the most relevant part of the entire server: 这是整个服务器中最相关的部分:

 app.use("/app", express.static(__dirname + '/public')); app.get('*', function(req, res) { res.sendFile(path.join(__dirname + '/index.html')); }); 

We use a few standard middleware functions before it gets to this point in the stack. 在堆栈中达到这一点之前,我们使用了一些标准的中间件功能。 I don't think those are relevant here, but I can include them if someone thinks that could be where the issue lies. 我认为这些与这里无关,但是如果有人认为这可能是问题所在,则可以包括在内。

We use a wildcard route to move some of the routing responsibility to react-router , which makes use of the html5 history/location APIs. 我们使用通配符路由将一些路由职责移至react-router ,它利用了html5历史记录/位置API。 There's very little configuration to the server apart from this basic route/response code. 除了此基本路由/响应代码外,服务器的配置很少。

This seems extremely lightweight, but when I was looking at the results of pm2 monit (which shows memory usage) I looks like each cluster takes a ~3mb increase per request. 这似乎是非常轻量级的,但是当我查看pm2 monit的结果(显示内存使用情况)时,我似乎每个集群每个请求的费用增加了约3mb。 I'm not sure if this is a safe/ignorable increase in rss or the heap or if I should be concerned. 我不确定这是否是rss或堆的安全/可忽略的增加,还是我应该关注。 It seems like it's almost buffering index.html , app.js , and app.css into memory. 似乎几乎将index.htmlapp.jsapp.css缓冲到内存中。

Can anyone help me diagnose this? 谁能帮我诊断一下? Am I looking at a memory leak? 我在查看内存泄漏吗? Should I even be considering a memory leak here? 我是否应该在这里考虑内存泄漏? I don't see any of the usual signs (accumulating memory over time w/o interaction, etc.). 我没有看到任何通常的迹象(随着时间的推移,在没有交互作用的情况下累积内存等)。 I suppose at some level I'm depending on pm2 here, but it's a fairly well-known module that gets lots of action in production for different people so I'm not too skeptical yet. 我想在某种程度上我要依赖pm2,但这是一个相当知名的模块,可以在生产中为不同的人提供很多操作,因此我还不太怀疑。

Here's an example of the clusters responding to a really basic GET request: 这是集群响应真正的基本GET请求的示例: asciicast

Turns out this was caused by my newrelic monitor installed w/ npm . 原来这是由于我的newrelic监视器安装了w / npm引起的 Be wary of third party tools! 警惕第三方工具! :) :)

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

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