Comparing version 0.0.0 to 0.0.1
var async = require('async') | ||
, request = require('request') | ||
, fs = require('fs') | ||
, extend = require('util')._extend | ||
, format = require('util').format | ||
, log = require('log4js').getLogger('lib/runner') | ||
@@ -13,9 +16,16 @@ , stepTypes = require('./step-types') | ||
//TODO: validate ctx!!! | ||
var total = ctx.total | ||
var macro = ctx | ||
, total = ctx.total | ||
, interval = ctx.interval | ||
, expected = 0 | ||
, rid = 0 | ||
, lastSec = 0 | ||
, lastRPS = 0 | ||
, csv | ||
, secIntr | ||
; | ||
ctx.agents = []; | ||
csv = initCsvOutput(ctx); | ||
//prepare stats bag per step | ||
@@ -33,6 +43,31 @@ ctx.scenario.forEach(function(step) { | ||
}) | ||
}); | ||
macro.fired = 0; | ||
macro.sec = lastSec = 0; | ||
macro.starttime = Date.now(); | ||
secIntr = setInterval( | ||
function() { | ||
log.info( "RPS:" , lastRPS = macro.fired ); | ||
csv.write( format("%s,%s\n", lastRPS, macro.sec) ); | ||
macro.fired = 0; | ||
lastSec = macro.sec++ | ||
} | ||
, 1000 | ||
); | ||
macro.onRequest = function() { | ||
macro.fired++; | ||
} | ||
macro.onResult = function(rslt) { | ||
csv.write( | ||
format(",%s,%s,%s,%s,%s,%s,%s,%s,%s,%s\n" | ||
, macro.sec, rslt.aid, rslt.step, rslt.rid, rslt.dur, rslt.statusCode, rslt.url, rslt.error, rslt.starttime, rslt.endtime | ||
) | ||
) | ||
} | ||
async.whilst( | ||
@@ -51,3 +86,6 @@ function() { | ||
return log.info("[a#%s] - finished. expecting %s more agents to finish", agent.id ); | ||
clearInterval(secIntr); | ||
csv.end(); | ||
done() | ||
@@ -71,5 +109,6 @@ } | ||
var agent = | ||
{ id : agentId++ | ||
, jar : request.jar() | ||
, stats: new Stats() | ||
{ id : agentId++ | ||
, jar : request.jar() | ||
, stats : new Stats() | ||
, params : extend({}, macro.params) | ||
, results: [] | ||
@@ -80,5 +119,2 @@ } | ||
macro.fired = 0; | ||
macro.starttime = Date.now(); | ||
async.eachSeries( macro.scenario | ||
@@ -122,2 +158,15 @@ , function(step, next) { | ||
function initCsvOutput(ctx) { | ||
var exists = fs.existsSync( ctx.csv ) | ||
, csv | ||
; | ||
csv = fs.createWriteStream(ctx.csv, {'flags': 'a'}); | ||
if (!exists) | ||
csv.write("sec-id,RPS,agent-id,step-name,req-id-in-step,dur,status-code,url,hard-error,start-time,end-time\n"); | ||
else | ||
log.warn("appending to an existing file: ", ctx.csv); | ||
return csv | ||
} |
@@ -23,3 +23,3 @@ var LOG = require('log4js').getLogger('lib/steps/req') | ||
, function(reqInfo, next) { | ||
var url = parameterize(macro.params, reqInfo.get) | ||
var url = parameterize(agent.params, reqInfo.get) | ||
, rslt = | ||
@@ -32,2 +32,3 @@ { aid : aid | ||
} | ||
, sec | ||
; | ||
@@ -77,3 +78,4 @@ | ||
); | ||
macro.fired++ | ||
macro.onRequest() | ||
} | ||
@@ -84,3 +86,2 @@ , function(e) { | ||
log.info("step stats [%s] : %s", step.name, step.stats); | ||
log.info("RPS:" , macro.fired * 1000 / (Date.now() - macro.starttime ) ) | ||
} | ||
@@ -87,0 +88,0 @@ done(e) |
{ | ||
"name": "logiload", | ||
"version": "0.0.0", | ||
"version": "0.0.1", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "lib", |
11
run.js
@@ -42,7 +42,5 @@ var logger = require('log4js') | ||
var runner = require('./lib/runner') | ||
, format = require('util').format | ||
, path = require('path') | ||
, fs = require('fs') | ||
, macro = path.join( process.cwd(), args.macro ) | ||
, csv = fs.createWriteStream(args.csv, {'flags': 'a'}) | ||
; | ||
@@ -57,14 +55,7 @@ | ||
csv.write("agent-id,step-name,req-id-in-step,dur,status-code,url,hard-error,start-time,end-time\n"); | ||
macro.total = args.total; | ||
macro.csv = args.csv; | ||
macro.onResult = function(rslt) { | ||
csv.write( format("%s,%s,%s,%s,%s,%s,%s,%s,%s\n", rslt.aid, rslt.step, rslt.rid, rslt.dur, rslt.statusCode, rslt.url, rslt.error, rslt.starttime, rslt.endtime) ); | ||
} | ||
runner(macro, function(e) { | ||
//TODO final stats | ||
csv.end(); | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14101
10
318
4
1