From e6a5c00ebf3a7463d1dc1cebe68dab8570d43d55 Mon Sep 17 00:00:00 2001 From: Mike Mattozzi Date: Mon, 27 Jun 2011 16:30:38 -0400 Subject: [PATCH] Adding standalone RPS requests per second stat collector --- examples/simpletest.ex.js | 1 + lib/monitoring/collectors.js | 9 +++++++++ nodeload.js | 4 ++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/examples/simpletest.ex.js b/examples/simpletest.ex.js index da9bc15..16b8f4f 100755 --- a/examples/simpletest.ex.js +++ b/examples/simpletest.ex.js @@ -23,6 +23,7 @@ nl.run({ 'result-codes', { name: 'latency', percentiles: [0.9, 0.99] }, 'concurrency', + 'rps', 'uniques', { name: 'http-errors', successCodes: [200,404], log: 'http-errors.log' } ], diff --git a/lib/monitoring/collectors.js b/lib/monitoring/collectors.js index 718367d..9c3bd60 100644 --- a/lib/monitoring/collectors.js +++ b/lib/monitoring/collectors.js @@ -17,6 +17,7 @@ var stats = require('../stats'); var Histogram = stats.Histogram; var Peak = stats.Peak; var ResultsCounter = stats.ResultsCounter; +var Rate = stats.Rate; var Uniques = stats.Uniques; var Accumulator = stats.Accumulator; var LogFile = stats.LogFile; @@ -41,6 +42,14 @@ StatsCollectors['result-codes'] = function ResultCodesCollector() { self.end = function(context, http) { self.stats.put(http.res.statusCode); }; }; +/** Track requests per second, storing stats in a stats.js#Rate object. The client must call +.end({res: http.ClientResponse}). */ +StatsCollectors['rps'] = function RpsCollector() { + var self = this; + self.stats = new Rate(); + self.end = function(context, http) { self.stats.put(); }; +}; + /** Track a status code that is returned in an HTTP header, storing stats in a stats.js#ResultsCounter object. The client must call .end({res: http.ClientResponse}). */ StatsCollectors['header-code'] = function HeaderCodeCollector(params) { diff --git a/nodeload.js b/nodeload.js index 7c0f1d4..e692065 100755 --- a/nodeload.js +++ b/nodeload.js @@ -65,8 +65,8 @@ this.loops=this.loops.concat(loops);this.emit('add',loops);} if(concurrency!==this.concurrency||rps!==this.rps){var rpsPerLoop=(rps/concurrency);this.loops.forEach(function(l){l.rps=rpsPerLoop;});this.emit('rps',rps);} this.concurrency=concurrency;this.rps=rps;if(timeout