Skip to content

Commit

Permalink
(pmx) add benchmark npm command
Browse files Browse the repository at this point in the history
  • Loading branch information
Unitech committed Mar 29, 2017
1 parent dafa705 commit 7a17bb2
Show file tree
Hide file tree
Showing 14 changed files with 264 additions and 1 deletion.
42 changes: 42 additions & 0 deletions examples/pmx/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

const PM2 = require('../..');

var pm2 = new PM2.custom({
cwd : __dirname + '/elements'
});


pm2.start([{
script : 'error.js'
}, {
script : 'metric.js'
}, {
script : 'counter.js'
}, {
script : 'meter.js'
}, {
script : 'histogram.js'
}, {
script : 'event.js'
}, {
script : 'notify.js'
}, {
script : 'log.js'
}, {
script : 'log-cluster.js',
instances : 2
}, {
script : 'http.js'
}, {
script : 'cluster.js',
instances : 4,
env : {
PORT : 9803
}
}, {
script : 'trace.js',
trace : true
}], (err, procs) => {
console.log(`${procs.length} test apps started`);
pm2.disconnect();
});
46 changes: 46 additions & 0 deletions examples/pmx/elements/cluster.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

var http = require('http');

http.createServer(function(req, res) {
res.writeHead(200);
setTimeout(function() {
res.end('transaction');
}, 10);
}).listen(process.env.PORT || 9010);

setInterval(function() {
request(['/user', '/bla', '/user/lol/delete', '/POST/POST'][Math.floor((Math.random() * 4))]);
}, 140);

function makeid()
{
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

for( var i=0; i < 5; i++ )
text += possible.charAt(Math.floor(Math.random() * possible.length));

return text;
}

function request(path) {
var options = {
hostname: '127.0.0.1'
,port: 9010
,path: path || '/users'
,method: 'GET'
,headers: { 'Content-Type': 'application/json' }
};

var req = http.request(options, function(res) {
res.setEncoding('utf8');
res.on('data', function (data) {
//console.log(data);
});
});
req.on('error', function(e) {
console.log('problem with request: ' + e.message);
});
req.end();

}
12 changes: 12 additions & 0 deletions examples/pmx/elements/counter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@


const pmx = require('pmx');
const Probe = pmx.probe();

var metric = Probe.counter({
name : 'Counter'
});

setInterval(function() {
metric.inc()
}, 500);
4 changes: 4 additions & 0 deletions examples/pmx/elements/error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

setInterval(function() {
new Error('toto');
}, 10);
9 changes: 9 additions & 0 deletions examples/pmx/elements/event.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

const pmx = require('pmx');

setInterval(function() {
pmx.emit('user:register', {
user : 'Alex registered',
email : '[email protected]'
});
}, 200);
15 changes: 15 additions & 0 deletions examples/pmx/elements/histogram.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@


const pmx = require('pmx');
const Probe = pmx.probe();

var metric = Probe.histogram({
name : 'Histogram'
});

var latency;

setInterval(function() {
latency = Math.round(Math.random() * 100);
metric.update(latency);
}, 100);
46 changes: 46 additions & 0 deletions examples/pmx/elements/http.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

var http = require('http');

http.createServer(function(req, res) {
res.writeHead(200);
setTimeout(function() {
res.end('transaction');
}, 10);
}).listen(process.env.PORT || 9010);

setInterval(function() {
request(['/user', '/bla', '/user/lol/delete', '/POST/POST'][Math.floor((Math.random() * 4))]);
}, 140);

function makeid()
{
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

for( var i=0; i < 5; i++ )
text += possible.charAt(Math.floor(Math.random() * possible.length));

return text;
}

function request(path) {
var options = {
hostname: '127.0.0.1'
,port: 9010
,path: path || '/users'
,method: 'GET'
,headers: { 'Content-Type': 'application/json' }
};

var req = http.request(options, function(res) {
res.setEncoding('utf8');
res.on('data', function (data) {
//console.log(data);
});
});
req.on('error', function(e) {
console.log('problem with request: ' + e.message);
});
req.end();

}
4 changes: 4 additions & 0 deletions examples/pmx/elements/log-cluster.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
setInterval(function() {
console.log('log');
console.error('log');
}, 200);
5 changes: 5 additions & 0 deletions examples/pmx/elements/log.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

setInterval(function() {
console.log('log');
console.error('log');
}, 200);
11 changes: 11 additions & 0 deletions examples/pmx/elements/meter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

const pmx = require('pmx');
const Probe = pmx.probe();

var metric = Probe.meter({
name : 'Meter'
});

setInterval(function() {
metric.mark()
}, 200);
16 changes: 16 additions & 0 deletions examples/pmx/elements/metric.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

const pmx = require('pmx');
const Probe = pmx.probe();

var data = 10;

var metric = Probe.metric({
name : 'Realtime user',
value : function() {
return data;
}
});

setInterval(function() {
data = Math.random();
}, 500);
6 changes: 6 additions & 0 deletions examples/pmx/elements/notify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

const pmx = require('pmx');

setInterval(function() {
pmx.notify({ success : false });
}, 200);
46 changes: 46 additions & 0 deletions examples/pmx/elements/trace.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

var http = require('http');

http.createServer(function(req, res) {
res.writeHead(200);
setTimeout(function() {
res.end('transaction');
}, 10);
}).listen(9016);

setInterval(function() {
request(['/user', '/bla', '/user/lol/delete', '/POST/POST'][Math.floor((Math.random() * 4))]);
}, 140);

function makeid()
{
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

for( var i=0; i < 5; i++ )
text += possible.charAt(Math.floor(Math.random() * possible.length));

return text;
}

function request(path) {
var options = {
hostname: '127.0.0.1'
,port: 9016
,path: path || '/users'
,method: 'GET'
,headers: { 'Content-Type': 'application/json' }
};

var req = http.request(options, function(res) {
res.setEncoding('utf8');
res.on('data', function (data) {
//console.log(data);
});
});
req.on('error', function(e) {
console.log('problem with request: ' + e.message);
});
req.end();

}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@
"description": "Production process manager for Node.JS applications with a built-in load balancer.",
"main": "index.js",
"scripts": {
"test": "NODE_ENV=test bash test/pm2_programmatic_tests.sh && NODE_ENV=test bash test/pm2_behavior_tests.sh"
"test": "NODE_ENV=test bash test/pm2_programmatic_tests.sh && NODE_ENV=test bash test/pm2_behavior_tests.sh",
"bench-pmx" : "pm2 delete all; pm2 install pm2-probe; node examples/pmx/app.js; pm2 ls"
},
"keywords": [
"cli",
Expand Down

0 comments on commit 7a17bb2

Please sign in to comment.