Comparing version 0.1.5 to 0.1.6
@@ -25,2 +25,3 @@ 'use strict'; | ||
}; | ||
var SHOW_INTERVAL_MS = 5000; | ||
@@ -33,10 +34,3 @@ | ||
* - running: if the operation is running or not. | ||
* Params is an object which may contain: | ||
* - url: destination URL (mandatory). | ||
* - method: HTTP method (default GET). | ||
* - payload: contents of request (default empty). | ||
* - maxRequests: stop sending requests after this global limit is reached. | ||
* - requestsPerSecond: limit requests per second to send. | ||
* - maxSeconds: stop receiving requests after this number of seconds. | ||
* - noAgent: if true, do not use connection keep-alive (default false). | ||
* Params is an object with the same options as exports.loadTest. | ||
*/ | ||
@@ -51,4 +45,15 @@ function HttpClient(operation, params) | ||
var lastCall; | ||
var timer; | ||
var requestTimer; | ||
var id; | ||
// init | ||
if (params.agentKeepAlive) | ||
{ | ||
var keepalive = require('agentkeepalive'); | ||
var keepAliveAgent = new keepalive({ | ||
maxSockets: params.concurrency, | ||
maxKeepAliveRequests: 0, // max requests per keepalive socket, default is 0, no limit | ||
maxKeepAliveTime: 3000 // keepalive for 30 seconds | ||
}); | ||
} | ||
@@ -65,3 +70,3 @@ /** | ||
var interval = Math.round(1000 / params.requestsPerSecond); | ||
timer = new timing.HighResolutionTimer(interval, self.makeRequest); | ||
requestTimer = new timing.HighResolutionTimer(interval, self.makeRequest); | ||
} | ||
@@ -74,7 +79,6 @@ | ||
{ | ||
if (!timer) | ||
if (requestTimer) | ||
{ | ||
return; | ||
requestTimer.stop(); | ||
} | ||
timer.stop(); | ||
} | ||
@@ -97,2 +101,6 @@ | ||
} | ||
if (params.agentKeepAlive) | ||
{ | ||
options.agent = keepAliveAgent; | ||
} | ||
if (params.method) | ||
@@ -171,3 +179,2 @@ { | ||
callback('Connection ' + id + ' failed: ' + error); | ||
}); | ||
@@ -195,2 +202,3 @@ connection.on('end', function(result) | ||
* - agent: if true, then use connection keep-alive and http agents. | ||
* - agentKeepAlive: if true, then use a special agent with keep-alive. | ||
* - quiet: do not log any messages. | ||
@@ -242,2 +250,4 @@ * An optional callback will be called if/when the test finishes. | ||
var requests = 0; | ||
var errors = 0; | ||
var showTimer; | ||
@@ -255,2 +265,3 @@ /** | ||
} | ||
showTimer = new timing.HighResolutionTimer(SHOW_INTERVAL_MS, showPartial); | ||
} | ||
@@ -264,2 +275,6 @@ | ||
requests += 1; | ||
if (error) | ||
{ | ||
errors += 1; | ||
} | ||
if (options.maxRequests) | ||
@@ -314,2 +329,6 @@ { | ||
{ | ||
if (showTimer) | ||
{ | ||
showTimer.stop(); | ||
} | ||
self.running = false; | ||
@@ -325,2 +344,15 @@ for (var index in clients) | ||
} | ||
/** | ||
* Show partial results. | ||
*/ | ||
function showPartial() | ||
{ | ||
self.latency.showPartial(); | ||
if (errors) | ||
{ | ||
var percent = Math.round(10 * errors / requests) / 10; | ||
log.info('Errors: %s, %s% of total requests', errors, percent); | ||
} | ||
} | ||
} | ||
@@ -345,2 +377,3 @@ | ||
console.log(' --agent Use http agent (Connection: keep-alive)'); | ||
console.log(' --keepalive Use a specialized keep-alive http agent (agentkeepalive)'); | ||
console.log(' --index param Replace the value of param with an index in the URL'); | ||
@@ -387,2 +420,5 @@ } | ||
return true; | ||
case '--keepalive': | ||
options.agentKeepAlive = true; | ||
return true; | ||
} | ||
@@ -389,0 +425,0 @@ console.error('Unknown option %s', argument); |
@@ -22,4 +22,2 @@ 'use strict'; | ||
* Latency measurements. Options can be: | ||
* - showSeconds: how many seconds to measure before showing latency. | ||
* - showRequests: how many requests to make, alternative to seconds. | ||
* - maxRequests: max number of requests to measure before stopping. | ||
@@ -38,3 +36,2 @@ * - maxSeconds: max seconds, alternative to max requests. | ||
var requests = {}; | ||
var showSeconds = options.showSeconds || 5; | ||
var partialRequests = 0; | ||
@@ -106,3 +103,2 @@ var partialTime = 0; | ||
histogramMs[rounded] += 1; | ||
showPartial(); | ||
if (isFinished()) | ||
@@ -115,16 +111,7 @@ { | ||
/** | ||
* Check out if enough seconds have elapsed, or enough requests were received. | ||
* If so, show latency for partial requests. | ||
* Show latency for partial requests. | ||
*/ | ||
function showPartial() | ||
self.showPartial = function() | ||
{ | ||
if (options.showRequests && partialRequests < options.showRequests) | ||
{ | ||
return; | ||
} | ||
var elapsedSeconds = (microtime.now() - lastShown) / 1000000; | ||
if (elapsedSeconds < showSeconds) | ||
{ | ||
return; | ||
} | ||
var meanTime = partialTime / partialRequests; | ||
@@ -143,10 +130,3 @@ var results = { | ||
partialRequests = 0; | ||
if (elapsedSeconds > 2 * showSeconds) | ||
{ | ||
lastShown = microtime.now(); | ||
} | ||
else | ||
{ | ||
lastShown += showSeconds * 1000000; | ||
} | ||
lastShown = microtime.now(); | ||
} | ||
@@ -153,0 +133,0 @@ |
{ | ||
"name": "loadtest", | ||
"version": "0.1.5", | ||
"version": "0.1.6", | ||
"description": "Load test scripts.", | ||
@@ -17,2 +17,3 @@ "homepage": "http://milliearth.org/", | ||
"testing": "*", | ||
"agentkeepalive": "*", | ||
"log": "*" | ||
@@ -19,0 +20,0 @@ }, |
@@ -0,1 +1,4 @@ | ||
[![Build Status](https://secure.travis-ci.org/alexfernandez/loadtest.png)](http://travis-ci.org/alexfernandez/loadtest) | ||
# loadtest | ||
@@ -16,5 +19,7 @@ | ||
Install globally as root: | ||
# npm install -g loadtest | ||
On Ubuntu or Mac OS X systems install using sudo: | ||
$ sudo install -g loadtest | ||
@@ -41,3 +46,3 @@ | ||
Add your own values for concurrency and requests per second: | ||
Add your own values for requests and concurrency: | ||
@@ -61,2 +66,6 @@ $ loadtest [-n requests] [-c concurrency] ... | ||
#### -r | ||
Recover from errors. Always active: loadtest does not stop on errors. | ||
#### --rps requestsPerSecond | ||
@@ -63,0 +72,0 @@ |
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
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
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
39773
14
1381
204
5
5
+ Addedagentkeepalive@*
+ Addedagentkeepalive@4.5.0(transitive)
+ Addedhumanize-ms@1.2.1(transitive)
+ Addedms@2.1.3(transitive)