Comparing version
@@ -6,2 +6,3 @@ 'use strict'; | ||
var Nanotimer = require('nanotimer'); | ||
var debug = require('debug')('arrivals'); | ||
@@ -27,3 +28,5 @@ module.exports = { | ||
function UniformProcess(tickInterval, duration) { | ||
this._tickInterval = tickInterval; | ||
debug(`tickInterval = ${tickInterval}, duration = ${duration}`); | ||
this._tickInterval = Math.floor(tickInterval); | ||
debug(`this._tickInterval set to ${this._tickInterval}`); | ||
this._interval = null; | ||
@@ -39,10 +42,16 @@ this._duration = duration || null; // ms | ||
var self = this; | ||
var arrivals = 0; | ||
var maxArrivals = Infinity; | ||
if (self._duration) { | ||
maxArrivals = Math.floor(self._duration / self._tickInterval); | ||
} | ||
debug(`maxArrivals = ${maxArrivals}`); | ||
self._interval = self._timer.setInterval(function() { | ||
self.emit('arrival'); | ||
arrivals++; | ||
if (arrivals === maxArrivals) { | ||
debug(`maxArrivals reached, stopping`); | ||
self.stop(); | ||
} | ||
}, '', self._tickInterval + 'm'); | ||
if (self._duration) { | ||
self._timer.setTimeout(function() { | ||
self.stop(); | ||
}, '', (self._duration + self._tickInterval / 2) + 'm'); | ||
} | ||
return self; | ||
@@ -49,0 +58,0 @@ }; |
{ | ||
"name": "arrivals", | ||
"version": "2.0.2", | ||
"version": "2.1.0", | ||
"description": "Modeling arrival processes of events in a system.", | ||
@@ -8,3 +8,2 @@ "main": "index.js", | ||
"test": "node test/index.js", | ||
"is_formatted": "find . -name '*.js' | grep -v node_modules | grep -v coverage | xargs jscs --preset=google", | ||
"is_linted": "find . -name '*.js' | grep -v node_modules | grep -v coverage | xargs eslint", | ||
@@ -25,2 +24,3 @@ "coverage": "istanbul cover test/index.js && istanbul check-coverage" | ||
"dependencies": { | ||
"debug": "2.3.3", | ||
"nanotimer": "0.3.14" | ||
@@ -31,3 +31,2 @@ }, | ||
"istanbul": "^0.3.17", | ||
"jscs": "^3.0.3", | ||
"pre-commit": "^1.0.10", | ||
@@ -37,5 +36,4 @@ "tape": "^4.0.0" | ||
"pre-commit": [ | ||
"is_linted", | ||
"is_formatted" | ||
"is_linted" | ||
] | ||
} |
# arrivals | ||
**Purpose**: Use this library to model the arrival of events in a system. | ||
`arrivals` models arrival events in a system, e.g.: | ||
**For example**: Model the arrival of visitors to a website; incoming phone calls to | ||
an exchange; spawning of ghosts in your Pacman clone. | ||
- visitors arriving to use a website | ||
- incoming phone calls to an exchange | ||
- ghosts spawning in Pacman | ||
This library was originally developed for use in [Minigun](https://artillery.io/minigun). | ||
Minigun is a modern load-testing tool with a focus on usability. | ||
This library was originally developed for use in [Artillery](https://artillery.io/), a modern load testing toolkit. | ||
@@ -15,3 +15,3 @@ ## Usage | ||
Two models of arrival processes are available: [Poisson](http://en.wikipedia.org/wiki/Poisson_process) and Uniform. | ||
Two models of arrival processes are available: [Poisson](http://en.wikipedia.org/wiki/Poisson_process) and Uniform (arrivals at a specified constant rate). | ||
@@ -71,3 +71,3 @@ | ||
``` | ||
Copyright (c) 2015, Hassy Veldstra <h@veldstra.org> | ||
Copyright (c) 2015-2016, Hassy Veldstra <h@artillery.io> | ||
@@ -74,0 +74,0 @@ Permission to use, copy, modify, and/or distribute this software for any |
@@ -56,3 +56,3 @@ 'use strict'; | ||
p.stop(); | ||
t.assert(count === 6, 'Correct number of arrivals'); | ||
t.assert(count === 6, `Correct number of arrivals - got ${count} - 1`); | ||
t.end(); | ||
@@ -70,3 +70,3 @@ }, 2700); | ||
t.ok(true, ' got finished event'); | ||
t.assert(count === 7, 'Correct number of arrivals'); | ||
t.assert(count === 6, `Correct number of arrivals - got ${count} - 2`); | ||
t.end(); | ||
@@ -89,3 +89,4 @@ }); | ||
p.once('finished', function () { | ||
t.assert(count === arrivalCount, 'Got the expect number of arrivals'); | ||
console.log(`count = ${count}, arrivalCount = ${arrivalCount}`); | ||
t.assert(count === arrivalCount, 'Got expected number of arrivals'); | ||
t.end(); | ||
@@ -92,0 +93,0 @@ }); |
4
-20%169
6.29%9289
-13.94%2
100%7
-12.5%+ Added
+ Added
+ Added