eventloop-latency

1.0.0 • Public • Published

eventloop-latency

Build Status Coverage Status Code Climate Issue Count

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

MIT

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.0
    58
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.0
    58

Package Sidebar

Install

npm i eventloop-latency

Weekly Downloads

58

Version

1.0.0

License

MIT

Last publish

Collaborators

  • korzhev