Skip to content

Commit a30b74d

Browse files
committed
renamed: node-cluster to cluster + updated example
1 parent 88b174d commit a30b74d

File tree

5 files changed

+43
-20
lines changed

5 files changed

+43
-20
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ exports.install = function(framework) {
44

55
function view_homepage() {
66
var self = this;
7+
process.send('Response framework ID: ' + self.framework.id);
78
self.view('homepage');
89
}

cluster/index.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
var http = require('http');
2+
var cluster = require('cluster');
3+
var os = require('os');
4+
5+
var debug = true;
6+
7+
if (!cluster.isMaster) {
8+
9+
// This code will be executed according the number of CPU
10+
// This code will be using: single process RAM * numCPUs
11+
var framework = require('total.js');
12+
13+
// Set framework ID
14+
framework.on('message', function(message) {
15+
if (message.type === 'id')
16+
framework.id = message.id;
17+
});
18+
19+
framework.run(http, debug);
20+
console.log("http://{0}:{1}/".format(framework.ip, framework.port));
21+
return;
22+
}
23+
24+
var numCPUs = os.cpus().length;
25+
26+
for (var i = 0; i < numCPUs; i++) {
27+
28+
// Run framework
29+
var fork = cluster.fork();
30+
31+
fork.on('message', onMessage);
32+
33+
// Send ID
34+
fork.send({ type: 'id', id: i });
35+
}
36+
37+
function onMessage(message) {
38+
console.log('Message ->', message);
39+
}
40+
41+
// Use a terminal for testing:
42+
// $ siege -b -r 10 http://127.0.0.1:8004/

node-cluster/index.js

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)