Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

implemented lighter request support

  • Loading branch information...
commit f4a3d0ce10edfd5c507088101dc61130846e3ba8 1 parent 215b0b0
@tj authored
View
2  examples/basic.js
@@ -20,7 +20,7 @@ cluster(server)
.set('workers', 6)
.use(cluster.debug())
.use(cluster.repl(9999))
- .use(cluster.stats({ connections: true, requests: true }))
+ .use(cluster.stats({ connections: true, lightRequests: true }))
.use(live())
.listen(3000);
View
2  examples/volatile.js
@@ -21,7 +21,7 @@ cluster(server)
.set('workers', 6)
.use(cluster.debug())
.use(cluster.repl(9999))
- .use(cluster.stats({ connections: true, requests: true }))
+ .use(cluster.stats({ connections: true, lightRequests: true }))
.use(live())
.listen(3000);
View
12 lib/cluster-live.js
@@ -42,6 +42,8 @@ function live(port, host, options) {
function live(master) {
if (!master.stats) throw new Error('cluster-live requires the stats() plugin');
+ if (!master.lightRequestStats) throw new Error('cluster-live requires stats() "lightRequests"');
+ if (!master.connectionStats) throw new Error('cluster-live requires stats() "connections"');
// setup app
var app = require('./app')(options);
@@ -109,8 +111,14 @@ function live(port, host, options) {
sockets.emit('client connection', stripWorker(worker));
});
- master.on('client request', function(worker, request){
- sockets.emit('client request', stripWorker(worker), request);
+ master.on('client light request', function(worker, request){
+ app.io.broadcast([
+ worker.id
+ , request
+ , worker.stats.connectionsActive
+ , worker.stats.connectionsTotal
+ , worker.stats.requestsTotal
+ ].join(':'));
});
master.on('worker removed', function(worker){
View
23 lib/public/javascripts/main.js
@@ -14,6 +14,16 @@ window.onload = function(){
case 'event':
cluster.emit.apply(cluster, obj.args);
break;
+ default:
+ var parts = obj.split(':')
+ , worker = getWorkerById(parts[0]);
+
+ worker.emit('request');
+ worker.emit('stats', {
+ connectionsActive: parts[2]
+ , connectionsTotal: parts[3]
+ , requestsTotal: parts[4]
+ });
}
});
@@ -28,9 +38,12 @@ window.onload = function(){
return false;
});
- // get / initialize a worker
+ function getWorkerById(id) {
+ return workers[id] = workers[id] || new Worker(id);
+ }
+
function getWorker(worker) {
- return workers[worker.id] = workers[worker.id] || new Worker(worker.id);
+ return getWorkerById(worker.id);
}
cluster.on('master closing', function(){
@@ -75,12 +88,6 @@ window.onload = function(){
worker.startReporting().removeOverlay();
});
- cluster.on('client request', function(_worker, request){
- var worker = getWorker(_worker);
- worker.emit('stats', _worker.stats);
- worker.emit('request', request);
- });
-
cluster.on('client connection', function(_worker){
var worker = getWorker(_worker);
worker.emit('stats', _worker.stats);
View
6 lib/utils.js
@@ -1,4 +1,10 @@
+/*!
+ * cluster-live - utils
+ * Copyright(c) 2011 TJ Holowaychuk <tj@vision-media.ca>
+ * MIT Licensed
+ */
+
/**
* Faster `Array.prototype.slice.call()` util.
*
Please sign in to comment.
Something went wrong with that request. Please try again.