Q:

nodejs with nginx proxy , memory usage

I use nginx proxy to nodejs app (express) , I found the memory usage is bigger than other php app,  I'm new to nodejs please help me review does these config and stat normal or something wrong?
# ps aux --sort -rss | head
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root      3587  0.1  9.3 1122596 191268 ?      Ssl  Oct10   0:47 node /var/www/html/domain1.com/app/app.js
mongod    2266  0.4  2.6 652476 53572 ?        Sl   Oct01  65:18 /usr/bin/mongod -f /etc/mongod.conf
root      2380  0.0  1.9 984316 39184 ?        Ssl  Oct01   8:18 PM2 v0.14.7: God Daemon
nginx   18011  6.2  0.9 253192 18576 ?        S    02:56   0:00 php-fpm: pool www
nginx   17492  3.0  0.9 252996 18452 ?        S    02:53   0:05 php-fpm: pool www
nginx   17269  3.1  0.9 252984 18428 ?        S    02:52   0:07 php-fpm: pool www
nginx   17261  3.1  0.9 252888 18380 ?        S    02:51   0:08 php-fpm: pool www
nginx   17201  3.3  0.8 252936 18148 ?        S    02:51   0:10 php-fpm: pool www
postgres  3596  0.0  0.5 326276 11844 ?        Ss   Oct10   0:01 postgres: db_admin db 127.0.0.1(54307) idle

# free -m
             total       used       free     shared    buffers     cached
Mem:          1991       1209        781          8        121        221
-/+ buffers/cache:        866       1124 
Swap:          511         48        463 

nginx config
server {
  listen 80;
  server_name domain1.com  www.domain1.com;
  access_log /var/log/nginx/domain1.com.access.log;
  location ~ ^/sitemap/(.*)$ {
    root /var/www/html/domain1.com/app/Sitemap/SitemapGz;
  }
  location /robots.txt {
    alias /var/www/html/domain1.com/app/robots.txt;
  }
  location ~ ^/(images/|javascripts/|stylesheets/|fonts) {
    root /var/www/html/domain1.com/app/assets;
    access_log off;
    expires max;
  }
  location / {
    set $fixed_destination $http_destination;
    if ( $http_destination ~* ^https(.*)$ )
    {
    set $fixed_destination http$1;
    }
    proxy_pass http://127.00.0.1:8002/;

    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Destination $fixed_destination;

    client_max_body_size 32M;
    client_body_buffer_size 512k;
    proxy_connect_timeout 300;
    proxy_send_timeout 300;
    proxy_read_timeout 300;
    proxy_buffer_size 4k;
    proxy_buffers 4 32k;
    proxy_busy_buffers_size 64k;
    proxy_temp_file_write_size 64k;
  }
}

nginx config
user              nginx;
worker_processes  2;

error_log  /var/log/nginx/error.log;

pid        /var/run/nginx.pid;

events {
    worker_connections  2048;
}

http {
  # fastcgi cache ...

  include       /etc/nginx/mime.types;
  default_type  application/octet-stream;

  log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                    '$status $body_bytes_sent "$http_referer" '
                    '"$http_user_agent" "$http_x_forwarded_for"';

  access_log  /var/log/nginx/access.log  main;

  sendfile        on;
  #tcp_nopush     on;

  #keepalive_timeout  0;
  keepalive_timeout  65;

  reset_timedout_connection on;
  send_timeout 2;

  gzip  on;

  gzip_comp_level    5;
  gzip_min_length    256;
  gzip_proxied       any;
  gzip_vary          on;

  gzip_types
  application/atom+xml
  application/javascript
  application/json
  application/ld+json
  application/manifest+json
  application/rdf+xml
  application/rss+xml
  application/schema+json
  application/vnd.geo+json
  application/vnd.ms-fontobject
  application/x-font-ttf
  application/x-javascript
  application/x-web-app-manifest+json
  application/xhtml+xml
  application/xml
  font/eot
  font/opentype
  image/bmp
  image/svg+xml
  image/vnd.microsoft.icon
  image/x-icon
  text/cache-manifest
  text/css
  text/javascript
  text/plain
  text/vcard
  text/vnd.rim.location.xloc
  text/vtt
  text/x-component
  text/x-cross-domain-policy
  text/xml;

  # Load config files from the /etc/nginx/conf.d directory
  # The default server is in conf.d/default.conf
  include /etc/nginx/conf.d/*.conf;
}

A:

Node.js uses javascript V8 engine underneath and the engine uses a sophisticate algorithm for garbage collection, so if it sees that you have plenty of free memory it will try to take advantage of it. This means that memory high memory usage is not necessarily an indication of a problem - node.js may use 85-90% of all available memory but it runs super fast and there is nothing wrong. The high memory usage may be normal or it may be a problem but there is no way to tell. Unless your app crashes of runs very slowly I would not worry about it but I would keep an eye on it just to establish a baseline.
BTW, if you by any chance use newrelic for monitoring of your app it has a tendency to blow up memory usage 2-4 times but this is the way it works and there is nothing wrong with it. However, it also has a documented memory leak relates to SSL, so you may need to check if it affects you.

