From 0de920ed93640683202e39fdcff45b535c0b0a6e Mon Sep 17 00:00:00 2001 From: Antoine WEBER Date: Tue, 22 Sep 2015 14:50:45 +0200 Subject: [PATCH] clusterisation du serveur --- README | 8 +++++++ bin/www | 65 +++++++++++++++++++++++++++++++++++----------------- package.json | 3 ++- public/test | 1 - 4 files changed, 54 insertions(+), 23 deletions(-) delete mode 100644 public/test diff --git a/README b/README index 4f1549c..2c14bb2 100644 --- a/README +++ b/README @@ -63,8 +63,16 @@ sudo ln -s ~/Movies /media/plex configurer vos chaines sur: http://localhost:32400/web/index.html +=================== +COMPILATION + +npm install enclose -g +enclose -o bin/mac_bin --loglevel info -c enclose_config.js -v 0.12.7 ./bin/www + + =================== TODO Liste +ajouter une présentation sur l'index, configurable dans config.js gérer les images des vignettes faire une page spéciales pour les séries gérer les téléchargements multi-source en proposant un lien aria2 (voir aria2.sourceforge.net) diff --git a/bin/www b/bin/www index bc75022..957c9a6 100755 --- a/bin/www +++ b/bin/www @@ -1,33 +1,56 @@ #!/usr/bin/env node + //On commence par la mise en cluster + var cluster = require('cluster'); -/** - * Module dependencies. - */ + // Code to run if we're in the master process + if (cluster.isMaster) { + // Count the machine's CPUs + var cpuCount = require('os').cpus().length; -var app = require('../app'); -var debug = require('debug')('plex_webdown:server'); -var http = require('http'); + // Create a worker for each CPU + for (var i = 0; i < cpuCount; i += 1) { + console.log('Création du fork ' + i); + cluster.fork(); + } -/** - * Get port from environment and store in Express. - */ + // Listen for dying workers + cluster.on('exit', function (worker) { + // Replace the dead worker, we're not sentimental + console.log('Worker ' + worker.id + ' died :('); + cluster.fork(); + }); -var port = normalizePort(process.env.PORT || '3000'); -app.set('port', port); + // Code to run if we're in a worker process + } else { + /** + * Module dependencies. + */ + var app = require('../app'); + var debug = require('debug')('plex_webdown:server'); + var http = require('http'); -/** - * Create HTTP server. - */ + /** + * Get port from environment and store in Express. + */ -var server = http.createServer(app); + var port = normalizePort(process.env.PORT || '3000'); + app.set('port', port); -/** - * Listen on provided port, on all network interfaces. - */ + /** + * Create HTTP server. + */ + + var server = http.createServer(app); + + /** + * Listen on provided port, on all network interfaces. + */ + + server.listen(port); + server.on('error', onError); + server.on('listening', onListening); +} -server.listen(port); -server.on('error', onError); -server.on('listening', onListening); /** * Normalize a port into a number, string, or false. diff --git a/package.json b/package.json index ff875d2..f918465 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "jade": "~1.11.0", "morgan": "~1.6.1", "serve-favicon": "~2.3.0", - "sqlite3": "~3" + "sqlite3": "~3", + "cluster":"~0.7.7" } } diff --git a/public/test b/public/test deleted file mode 100644 index ee34b4d..0000000 --- a/public/test +++ /dev/null @@ -1 +0,0 @@ -contenu test