1.0.0 • Published 8 years ago
eventloop-latency v1.0.0
eventloop-latency
This lib is part of Bronitor project. It counts eventloop latency using process.hrtime
Requirements
Code written using ECMAScript 2015. It tested on node >= 4
Use babel if, you want to use it on node < 4
Installation
$ npm i eventloop-latency --production
Usage
const EL = require('eventloop-latency'),
interval = 5000,
hrInterval = 10,
monitoring = new EL(interval, hrInterval);
monitoring.start(true);
monitoring.on('data', (data) => {
console.log(data); // [49, 27, ..., 144, 923]
});
monitoring.stop();
monitoring.start();
setInterval(() => {
console.log(monitoring.countLatency()); // [149, 7, ..., 14, 92]
}, 1000)
Docs
- monitoring - main object, eventemitter, takes two options:
- iterval - interval in ms for emitting 'data' event, optional, defaults to 5000 ms
- hrIntreval - interval in ms using to count latency, should be in range 10-100, optional, defaults to 10 ms
- start() - function, that start monitoring, takes option:
- enableEmit - if true, monitoring will emit "data" event, else function countLatency() is used to get latency info
- stop() - function, that stop monitoring
- countLatency() - function, that return array with latency
- "data" event - returns array of latency in µs(microseconds, 10e-6 s) during the interval
Examples
You can see small example in demos/server.js. Run it:
$ npm run-script demo
Tests
To run the test suite, first install the dependencies, then run npm test
:
$ npm install
$ npm test
License
1.0.0
8 years ago