GWicke has uploaded a new change for review.
https://gerrit.wikimedia.org/r/88514
Change subject: Clean up server.js and add heap dump handler using the heapdump
module
......................................................................
Clean up server.js and add heap dump handler using the heapdump module
Change-Id: I2f81b2471d5adc599e1e37b5bcd19bfb2bb3d1d5
---
M js/api/server.js
1 file changed, 47 insertions(+), 34 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Parsoid
refs/changes/14/88514/1
diff --git a/js/api/server.js b/js/api/server.js
index 79df13a..eda0907 100755
--- a/js/api/server.js
+++ b/js/api/server.js
@@ -5,43 +5,56 @@
*/
var cluster = require('cluster');
-var app = require('./ParserService.js');
-// Start a few more workers than there are cpus visible to the OS, so that we
-// get some degree of parallelism even on single-core systems. A single
-// long-running request would otherwise hold up all concurrent short requests.
-var numCPUs = require('os').cpus().length + 3;
if (cluster.isMaster) {
- // Fork workers.
- for (var i = 0; i < numCPUs; i++) {
- cluster.fork();
- }
+ // Start a few more workers than there are cpus visible to the OS, so
that we
+ // get some degree of parallelism even on single-core systems. A single
+ // long-running request would otherwise hold up all concurrent short
requests.
+ var numCPUs = require('os').cpus().length + 3;
+ // Fork workers.
+ for (var i = 0; i < numCPUs; i++) {
+ cluster.fork();
+ }
- cluster.on('exit', function(worker, code, signal) {
- if (!worker.suicide) {
- var exitCode = worker.process.exitCode;
- console.log('worker', worker.process.pid,
- 'died ('+exitCode+'), restarting.');
- cluster.fork();
- }
- });
+ cluster.on('exit', function(worker, code, signal) {
+ if (!worker.suicide) {
+ var exitCode = worker.process.exitCode;
+ console.log('worker', worker.process.pid,
+ 'died ('+exitCode+'), restarting.');
+ cluster.fork();
+ }
+ });
- process.on('SIGTERM', function() {
- console.log('master shutting down, killing workers');
- var workers = cluster.workers;
- Object.keys(workers).forEach(function(id) {
- console.log('Killing worker ' + id);
- workers[id].destroy();
- });
- console.log('Done killing workers, bye');
- process.exit(1);
- } );
+ process.on('SIGTERM', function() {
+ console.log('master shutting down, killing workers');
+ var workers = cluster.workers;
+ Object.keys(workers).forEach(function(id) {
+ console.log('Killing worker ' + id);
+ workers[id].destroy();
+ });
+ console.log('Done killing workers, bye');
+ process.exit(1);
+ });
} else {
- process.on('SIGTERM', function() {
- console.log('Worker shutting down');
- process.exit(1);
- });
- // when running on appfog.com the listen port for the app
- // is passed in an environment variable. Most users can ignore this!
- app.listen(process.env.VCAP_APP_PORT || 8000);
+ // Worker.
+ process.on('SIGTERM', function() {
+ console.log('Worker shutting down');
+ process.exit(1);
+ });
+
+ // Enable heap dumps in /tmp on kill -USR2.
+ // See https://github.com/bnoordhuis/node-heapdump/
+ // For node 0.6/0.8: npm install [email protected]
+ // For 0.10: npm install heapdump
+ process.on('SIGUSR2', function() {
+ var heapdump = require('heapdump');
+ console.error('SIGUSR2 received! Writing snapshot.');
+ process.chdir('/tmp');
+ heapdump.writeSnapshot();
+ });
+
+ var app = require('./ParserService.js');
+ // when running on appfog.com the listen port for the app
+ // is passed in an environment variable. Most users can ignore this!
+ app.listen(process.env.VCAP_APP_PORT || 8000);
}
--
To view, visit https://gerrit.wikimedia.org/r/88514
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I2f81b2471d5adc599e1e37b5bcd19bfb2bb3d1d5
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Parsoid
Gerrit-Branch: master
Gerrit-Owner: GWicke <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits