简体   繁体   中英

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). 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. 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.

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. 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. I'm not sure if this is a safe/ignorable increase in rss or the heap or if I should be concerned. It seems like it's almost buffering index.html , app.js , and app.css into memory.

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.

Here's an example of the clusters responding to a really basic GET request: asciicast

Turns out this was caused by my newrelic monitor installed w/ npm . Be wary of third party tools! :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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