-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
62 lines (47 loc) · 1.44 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
var Waiter = require('./lib/waiter');
var async = require('async'),
xrange = require('xrange'),
request = require('request'),
usage = require('usage');
var util = require('util');
var numRequests = 100,
simultaneous = 10,
requestsPerSecond = 50;
var options = {
url: process.argv[2]
};
var waiter = new Waiter(requestsPerSecond);
var start = Date.create();
var usageCount = 0,
usageSum = 0;
var getPoundedness = function (pid) {
usage.lookup(pid, function (err, result) {
if (err) {
console.log(err);
return;
}
usageSum += result.cpu;
usageCount += 1;
});
};
var processThread;
if (process.argv[3]) {
processThread = setInterval(getPoundedness.bind(null, parseInt(process.argv[3], 10)), 50);
}
async.eachLimit(xrange(numRequests), simultaneous, function (each, callback) {
waiter.wait(function () {
request(options, function (err, resp, body) {
callback(err, resp && resp.statusCode);
});
});
}, function (err) {
var duration = Date.create().millisecondsSince(start);
var expected = (1000 * numRequests / requestsPerSecond) - 1000;
console.log(util.format('Finished in %sms.', duration));
console.log(util.format('Ideal %sms', expected));
if (err) {
console.log('Received error', err);
}
console.log('Average CPU', usageSum / usageCount);
clearInterval(processThread);
});