Simple node.js app deployed to Bluemix seems to be leaking memory -
i learning node.js, , have simple application seems leaking memory when deployed bluemix. need assistance in determining if caused code, or module using.
when deployed monitoring , cloudant services crash out of memory error, , restarted bluemix every 12-14 hours - 256 megs of ram. upped ram 1 gig , still occurs (although less frequently).
when deploy app bluemix , issue calls / route can see memory climb up. when testing locally in windows, not see same behavior (testing via process explorer , seeing amount of private bytes & working set)
i have simplified app (and removed monitoring service) , can still reproduce, though increase slower simplified app.
/*jshint node:true*/ //------------------------------------------------------------------------------ // app.js - middleware routing //------------------------------------------------------------------------------ // application uses express it's web server // more info, see: http://expressjs.com var express = require( 'express' ); // handling post bodies , multi-part bodies0 var bodyparser = require( 'body-parser' ); var multer = require( 'multer' ); // create new express server var app = express(); // app environment cloud foundry var cfenv = require( 'cfenv' ); var appenv = cfenv.getappenv(); // catch handlers unhandled urls // app.post( '/*', function( req, res ){ logrequest( req ); res.send( 'unhandled post received' ); }); app.get( '/*', function( req, res ){ logrequest( req ); res.send( 'unhandled received' ); }); // start server on specified port , binding host app.listen(appenv.port, appenv.bind, function() { // print message when server starts listening console.log("server starting on -- " + appenv.url); }); function logrequest(req){ console.log("received,"+new date().tolocalestring()+","+req.method+","+req.originalurl); }
here data gathered, memory listed in megs, , issued requests / route:
- 83.1m on startup
- 83.5m after 1 call /
- 83.5m after 5 more calls /
- 83.6 after 5 more calls /
- 84.2 after 20 more calls /
- 85.1 after 10 more calls /
- 86.6 after 20 more calls /
i tried using heapdump module, fails when being deployed bluemix.
cf-node-debug installation successful - see bottom of question installed cf-node-debug suggested, in package.json specified:
"scripts": { "start": "node_modules/.bin/cf-node-debug app.js" },
when pushed app got following:
t13:19:44.08-0400 [stg/39] out -----> downloaded app package (36k) t13:19:44.46-0400 [stg/39] out -----> downloaded app buildpack cache (2.6m) t13:19:44.80-0400 [stg/0] out -----> node.js buildpack version: v1.18-20150519-1759 t13:19:44.85-0400 [stg/0] out -----> resetting git environment t13:19:45.35-0400 [stg/0] out tip: specify node version in package.json t13:19:45.35-0400 [stg/0] out -----> defaulting latest stable node: 0.12.2 t13:19:45.35-0400 [stg/0] out -----> installing ibm sdk node.js cache t13:19:45.78-0400 [stg/0] out -----> checking , configuring service extensions t13:19:45.95-0400 [stg/0] out -----> restoring node_modules directory cache t13:19:46.21-0400 [stg/0] out -----> pruning cached dependencies not specified in package.json t13:19:47.22-0400 [stg/0] out -----> installing dependencies t13:19:54.50-0400 [stg/0] out > ws@0.4.32 install /tmp/staged/app/node_modules/cf-node-debug/node_modules/node-inspector/node_modules/ws t13:19:54.50-0400 [stg/0] out > (node-gyp rebuild 2> builderror.log) || (exit 0) t13:20:04.31-0400 [stg/0] out make: entering directory `/tmp/staged/app/node_modules/cf-node-debug/node_modules/node-inspector/node_modules/ws/build' t13:20:04.32-0400 [stg/0] out cxx(target) release/obj.target/bufferutil/src/bufferutil.o t13:20:04.71-0400 [stg/0] out solink_module(target) release/obj.target/bufferutil.node t13:20:04.76-0400 [stg/0] out solink_module(target) release/obj.target/bufferutil.node: finished t13:20:04.77-0400 [stg/0] out copy release/bufferutil.node t13:20:04.78-0400 [stg/0] out cxx(target) release/obj.target/validation/src/validation.o t13:20:05.15-0400 [stg/0] out solink_module(target) release/obj.target/validation.node t13:20:05.21-0400 [stg/0] out solink_module(target) release/obj.target/validation.node: finished t13:20:05.21-0400 [stg/0] out copy release/validation.node t13:20:05.24-0400 [stg/0] out make: leaving directory `/tmp/staged/app/node_modules/cf-node-debug/node_modules/node-inspector/node_modules/ws/build' t13:20:05.29-0400 [stg/0] out npm warn deprecated static-favicon@1.0.2: use serve-favicon module t13:20:05.80-0400 [stg/0] out cf-node-debug@0.1.2 node_modules/cf-node-debug t13:20:05.80-0400 [stg/0] out ├── underscore@1.6.0 t13:20:05.80-0400 [stg/0] out ├── q@1.0.1 t13:20:05.80-0400 [stg/0] out ├── passport-local@1.0.0 (passport-strategy@1.0.0) t13:20:05.80-0400 [stg/0] out ├── nopt@2.2.1 (abbrev@1.0.7) t13:20:05.80-0400 [stg/0] out ├── passport@0.2.2 (pause@0.0.1, passport-strategy@1.0.0) t13:20:05.80-0400 [stg/0] out ├── client-sessions@0.6.0 (cookies@0.3.8) t13:20:05.80-0400 [stg/0] out ├── http-proxy@1.1.6 (eventemitter3@1.1.0) t13:20:05.80-0400 [stg/0] out ├── body-parser@1.3.1 (raw-body@1.1.6, qs@0.6.6, bytes@1.0.0, type-is@1.2.1) t13:20:05.80-0400 [stg/0] out ├── express@4.4.5 (parseurl@1.0.1, utils-merge@1.0.0, merge-descriptors@0.0.2, cookie@0.1.2, escape-html@1.0.1, qs@0.6.6, cookie-signature@1. @1.0.0, fresh@0.2.2, vary@0.1.0, methods@1.0.1, serve-static@1.2.3, buffer-crc32@0.2.3, path-to-regexp@0.1.2, type-is@1.2.1, accepts@1.0.7, proxy-addr@1.0.1, debug@1.0.2, send@0.4.3) t13:20:05.80-0400 [stg/0] out ├── cfenv@0.2.0 (ports@1.1.0, js-yaml@3.0.2) t13:20:05.80-0400 [stg/0] out ├── handlebars@2.0.0 (optimist@0.3.7, uglify-js@2.3.6) t13:20:05.80-0400 [stg/0] out └── node-inspector@0.7.3 (opener@1.3.0, debug@0.8.1, which@1.0.9, async@0.4.1, strong-data-uri@0.1.1, yargs@1.1.3, rc@0.3.5, glob@3.2.11, exp 4.32) t13:20:06.02-0400 [stg/0] out -----> caching node_modules directory future builds t13:20:06.59-0400 [stg/0] out -----> cleaning node-gyp , npm artifacts t13:20:06.60-0400 [stg/0] out -----> no procfile found; adding npm start new procfile t13:20:06.60-0400 [stg/0] out -----> building runtime environment t13:20:06.60-0400 [stg/0] out -----> checking , configuring service extensions t13:20:06.85-0400 [stg/0] out -----> installing app management t13:20:06.90-0400 [stg/0] out -----> warn: app management (development mode) cannot installed because start script cannot found. t13:20:06.91-0400 [stg/0] out tip: specify start script in 'package.json' or 'procfile'. t13:20:06.92-0400 [stg/0] err t13:20:11.28-0400 [stg/39] out -----> uploading droplet (20m) t13:20:20.47-0400 [dea/39] out starting app instance (index 0) guid 1dde346e-4e51-407f-af7b-607772826e72 t13:20:32.91-0400 [app/0] out t13:20:32.91-0400 [app/0] out > nodejsstarterapp@0.0.1 start /home/vcap/app t13:20:32.91-0400 [app/0] out > cf-node-debug app.js t13:20:33.38-0400 [app/0] err util.js:634 t13:20:33.38-0400 [app/0] err ctor.prototype = object.create(superctor.prototype, { t13:20:33.38-0400 [app/0] err ^ t13:20:33.38-0400 [app/0] err typeerror: cannot read property 'prototype' of undefined t13:20:33.38-0400 [app/0] err @ object.exports.inherits (util.js:634:43) t13:20:33.38-0400 [app/0] err @ object.<anonymous> (/home/vcap/app/node_modules/cf-node-debug/node_modules/http-proxy/lib/http-proxy/index.js:106:17) t13:20:33.38-0400 [app/0] err @ module._compile (module.js:460:26) t13:20:33.38-0400 [app/0] err @ object.module._extensions..js (module.js:478:10) t13:20:33.38-0400 [app/0] err @ module.load (module.js:355:32) t13:20:33.38-0400 [app/0] err @ function.module._load (module.js:310:12) t13:20:33.38-0400 [app/0] err @ module.require (module.js:365:17) t13:20:33.38-0400 [app/0] err @ require (module.js:384:17) t13:20:33.38-0400 [app/0] err @ object.<anonymous> (/home/vcap/app/node_modules/cf-node-debug/node_modules/http-proxy/lib/http-proxy.js:4:17) t13:20:33.38-0400 [app/0] err @ module._compile (module.js:460:26) t13:20:33.40-0400 [app/0] err npm err! linux 3.13.0-39-generic t13:20:33.40-0400 [app/0] err npm err! argv "/home/vcap/app/vendor/node/bin/node" "/home/vcap/app/vendor/node/bin/npm" "start" t13:20:33.40-0400 [app/0] err npm err! node v0.12.2 t13:20:33.40-0400 [app/0] err npm err! npm v2.7.4 t13:20:33.40-0400 [app/0] err npm err! code elifecycle t13:20:33.40-0400 [app/0] err npm err! nodejsstarterapp@0.0.1 start: `cf-node-debug app.js` t13:20:33.40-0400 [app/0] err npm err! exit status 1 t13:20:33.40-0400 [app/0] err npm err! t13:20:33.40-0400 [app/0] err npm err! failed @ nodejsstarterapp@0.0.1 start script 'cf-node-debug app.js'. t13:20:33.41-0400 [app/0] err npm err! problem nodejsstarterapp package, t13:20:33.41-0400 [app/0] err npm err! not npm itself. t13:20:33.41-0400 [app/0] err npm err! tell author fails on system: t13:20:33.41-0400 [app/0] err npm err! cf-node-debug app.js t13:20:33.41-0400 [app/0] err npm err! can info via: t13:20:33.41-0400 [app/0] err npm err! npm owner ls nodejsstarterapp t13:20:33.41-0400 [app/0] err npm err! there additional logging output above. t13:20:33.41-0400 [app/0] err npm err! please include following file support request: t13:20:33.41-0400 [app/0] err npm err! /home/vcap/app/npm-debug.log t13:20:33.47-0400 [dea/39] err instance (index 0) failed start accepting connections $ npm --version 1.4.28 $ node --version v0.10.33
looks http-proxy@1.1.6 (eventemitter3@1.1.0)
note: using sdk node.js ibm
at jack's suggestion tried specifying engine like:
"engines": { "node": "0.10.x", "npm": "2.7.4" },
the staging reported:
2015-06-04t14:27:41.87-0400 [stg/0] out -----> resetting git environment 2015-06-04t14:27:42.31-0400 [stg/0] out -----> requested node range: 0.10.x 2015-06-04t14:27:42.31-0400 [stg/0] out -----> resolved node version: 0.10.38 2015-06-04t14:27:42.31-0400 [stg/0] out -----> installing ibm sdk node.js cache
but obtained same error before:
2015-06-04t14:28:12.89-0400 [app/0] err util.js:556 2015-06-04t14:28:12.89-0400 [app/0] err ctor.prototype = object.create(superctor.prototype, { 2015-06-04t14:28:12.89-0400 [app/0] err ^ 2015-06-04t14:28:12.89-0400 [app/0] err typeerror: cannot read property 'prototype' of undefined
update 3:35pm est
i forked cf-node-debug , modified http-proxy 1.11.x. updated package.json to:
"cf-node-debug": "git://github.com/retinaburn/cf-node-debug.git",
i pushed app, , have access debug console, there not seem heap dumps can use investigate memory leaks.
you may want isolate issues. behavior occurs when running application locally? there node-module memwatch may help. think memwatch works node.js 10.x there memwatch-next work node.js 0.12.x.
Comments
Post a Comment