Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/korzhev/eventloop-latency
Counting node.js eventloop latency.
https://github.com/korzhev/eventloop-latency
event-loop eventloop latency node nodejs
Last synced: about 1 month ago
JSON representation
Counting node.js eventloop latency.
- Host: GitHub
- URL: https://github.com/korzhev/eventloop-latency
- Owner: korzhev
- License: mit
- Created: 2016-02-22T10:30:53.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2016-04-16T13:56:52.000Z (over 8 years ago)
- Last Synced: 2024-10-07T11:45:43.343Z (2 months ago)
- Topics: event-loop, eventloop, latency, node, nodejs
- Language: JavaScript
- Homepage:
- Size: 18.6 KB
- Stars: 5
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-github-star - eventloop-latency
README
# eventloop-latency
[![Build Status](https://travis-ci.org/korzhev/eventloop-latency.svg?branch=master)](https://travis-ci.org/korzhev/eventloop-latency)
[![Coverage Status](https://coveralls.io/repos/github/korzhev/eventloop-latency/badge.svg?branch=master)](https://coveralls.io/github/korzhev/eventloop-latency?branch=master)
[![Code Climate](https://codeclimate.com/github/korzhev/eventloop-latency/badges/gpa.svg)](https://codeclimate.com/github/korzhev/eventloop-latency)
[![Issue Count](https://codeclimate.com/github/korzhev/eventloop-latency/badges/issue_count.svg)](https://codeclimate.com/github/korzhev/eventloop-latency)This lib is part of [Bronitor](https://github.com/korzhev/bronitor) project. It counts eventloop latency using [process.hrtime](https://nodejs.org/dist/latest-v4.x/docs/api/process.html#process_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
```bash
$ npm i eventloop-latency --production
```## Usage
```js
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:
```bash
$ npm run-script demo
```## Tests
To run the test suite, first install the dependencies, then run `npm test`:
```bash
$ npm install
$ npm test
```## License
[MIT](LICENSE)