我使用nginx代理到nodejs应用程序(express),我发现内存使用情况比其他php应用程序大,我是新的nodejs请帮我检查这些configuration和统计正常或错误吗?
# 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
nginxconfiguration
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; } }
nginxconfiguration
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; }
Node.js在下面使用JavaScript V8引擎,引擎使用垃圾收集的复杂algorithm,所以如果它看到你有足够的空闲内存,它会尝试利用它。 这意味着内存高内存使用率不一定是问题的表示 – node.js可能会使用所有可用内存的85-90%,但运行速度超快,没有任何错误。 高内存使用率可能是正常的,或者可能是一个问题,但没有办法告诉。 除非你的应用程序崩溃运行非常缓慢,我不会担心,但我会留意它只是为了build立一个基准。
顺便说一句,如果你有任何机会使用newrelic监视你的应用程序,它有一个倾向,炸毁内存使用2-4次,但这是它的工作方式,没有什么错。 但是,它也有一个logging与SSL有关的内存泄漏,所以你可能需要检查是否影响到你。