Skip to content

Commit

Permalink
added change log and handling concurrency
Browse files Browse the repository at this point in the history
  • Loading branch information
Saurabh Singh authored and Saurabh Singh committed May 23, 2024
1 parent 473f29c commit cbe29f3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ project adheres to [Semantic Versioning](http://semver.org/).
### Breaking

### Changed
- Changes for cluster mode
- Removed `byLabels` Grouper in `metricAggregators.js` file and created a global Map to avoid Map creation on every request for the metrics
- Moved hashing of labels from master to worker to distribute the cpu bound hashing among workers
- Workers to write metrics in tmp file and send the file name to master to read metrics from rather than sending on IPC to keep IPC congestion free. (change in `cluster.js`)

### Added

Expand Down
3 changes: 2 additions & 1 deletion lib/cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ function addListeners() {
value["hash"] = key;

Check failure on line 219 in lib/cluster.js

View workflow job for this annotation

GitHub Actions / Test on Node.js v16.x and OS ubuntu-latest

Replace `"hash"` with `'hash'`

Check failure on line 219 in lib/cluster.js

View workflow job for this annotation

GitHub Actions / Test on Node.js v16.x and OS ubuntu-latest

["hash"] is better written in dot notation

Check failure on line 219 in lib/cluster.js

View workflow job for this annotation

GitHub Actions / Test on Node.js v20.x and OS ubuntu-latest

Replace `"hash"` with `'hash'`

Check failure on line 219 in lib/cluster.js

View workflow job for this annotation

GitHub Actions / Test on Node.js v20.x and OS ubuntu-latest

["hash"] is better written in dot notation

Check failure on line 219 in lib/cluster.js

View workflow job for this annotation

GitHub Actions / Test on Node.js v16.x and OS macOS-latest

Replace `"hash"` with `'hash'`

Check failure on line 219 in lib/cluster.js

View workflow job for this annotation

GitHub Actions / Test on Node.js v16.x and OS macOS-latest

["hash"] is better written in dot notation

Check failure on line 219 in lib/cluster.js

View workflow job for this annotation

GitHub Actions / Test on Node.js v18.x and OS ubuntu-latest

Replace `"hash"` with `'hash'`

Check failure on line 219 in lib/cluster.js

View workflow job for this annotation

GitHub Actions / Test on Node.js v18.x and OS ubuntu-latest

["hash"] is better written in dot notation

Check failure on line 219 in lib/cluster.js

View workflow job for this annotation

GitHub Actions / Test on Node.js v21.x and OS ubuntu-latest

Replace `"hash"` with `'hash'`

Check failure on line 219 in lib/cluster.js

View workflow job for this annotation

GitHub Actions / Test on Node.js v21.x and OS ubuntu-latest

["hash"] is better written in dot notation

Check failure on line 219 in lib/cluster.js

View workflow job for this annotation

GitHub Actions / Test on Node.js v20.x and OS macOS-latest

Replace `"hash"` with `'hash'`

Check failure on line 219 in lib/cluster.js

View workflow job for this annotation

GitHub Actions / Test on Node.js v20.x and OS macOS-latest

["hash"] is better written in dot notation

Check failure on line 219 in lib/cluster.js

View workflow job for this annotation

GitHub Actions / Test on Node.js v18.x and OS macOS-latest

Replace `"hash"` with `'hash'`

Check failure on line 219 in lib/cluster.js

View workflow job for this annotation

GitHub Actions / Test on Node.js v18.x and OS macOS-latest

["hash"] is better written in dot notation

Check failure on line 219 in lib/cluster.js

View workflow job for this annotation

GitHub Actions / Test on Node.js v21.x and OS macOS-latest

Replace `"hash"` with `'hash'`

Check failure on line 219 in lib/cluster.js

View workflow job for this annotation

GitHub Actions / Test on Node.js v21.x and OS macOS-latest

["hash"] is better written in dot notation

Check failure on line 219 in lib/cluster.js

View workflow job for this annotation

GitHub Actions / Test on Node.js v16.x and OS windows-latest

Replace `"hash"` with `'hash'`

Check failure on line 219 in lib/cluster.js

View workflow job for this annotation

GitHub Actions / Test on Node.js v16.x and OS windows-latest

["hash"] is better written in dot notation

Check failure on line 219 in lib/cluster.js

View workflow job for this annotation

GitHub Actions / Test on Node.js v21.x and OS windows-latest

Replace `"hash"` with `'hash'`

Check failure on line 219 in lib/cluster.js

View workflow job for this annotation

GitHub Actions / Test on Node.js v21.x and OS windows-latest

["hash"] is better written in dot notation

Check failure on line 219 in lib/cluster.js

View workflow job for this annotation

GitHub Actions / Test on Node.js v20.x and OS windows-latest

Replace `"hash"` with `'hash'`

Check failure on line 219 in lib/cluster.js

View workflow job for this annotation

GitHub Actions / Test on Node.js v20.x and OS windows-latest

["hash"] is better written in dot notation

Check failure on line 219 in lib/cluster.js

View workflow job for this annotation

GitHub Actions / Test on Node.js v18.x and OS windows-latest

Replace `"hash"` with `'hash'`

Check failure on line 219 in lib/cluster.js

View workflow job for this annotation

GitHub Actions / Test on Node.js v18.x and OS windows-latest

["hash"] is better written in dot notation
});
});
const filename = path.join(os.tmpdir(), `metrics-${process.pid}}.json`);
// adding request id in file path to handle concurrency
const filename = path.join(os.tmpdir(), `metrics-${process.pid}-${message.requestId}.json`);

Check failure on line 223 in lib/cluster.js

View workflow job for this annotation

GitHub Actions / Test on Node.js v16.x and OS ubuntu-latest

Replace `os.tmpdir(),·`metrics-${process.pid}-${message.requestId}.json`` with `⏎↹↹↹↹↹↹↹os.tmpdir(),⏎↹↹↹↹↹↹↹`metrics-${process.pid}-${message.requestId}.json`,⏎↹↹↹↹↹↹`

Check failure on line 223 in lib/cluster.js

View workflow job for this annotation

GitHub Actions / Test on Node.js v20.x and OS ubuntu-latest

Replace `os.tmpdir(),·`metrics-${process.pid}-${message.requestId}.json`` with `⏎↹↹↹↹↹↹↹os.tmpdir(),⏎↹↹↹↹↹↹↹`metrics-${process.pid}-${message.requestId}.json`,⏎↹↹↹↹↹↹`

Check failure on line 223 in lib/cluster.js

View workflow job for this annotation

GitHub Actions / Test on Node.js v16.x and OS macOS-latest

Replace `os.tmpdir(),·`metrics-${process.pid}-${message.requestId}.json`` with `⏎↹↹↹↹↹↹↹os.tmpdir(),⏎↹↹↹↹↹↹↹`metrics-${process.pid}-${message.requestId}.json`,⏎↹↹↹↹↹↹`

Check failure on line 223 in lib/cluster.js

View workflow job for this annotation

GitHub Actions / Test on Node.js v18.x and OS ubuntu-latest

Replace `os.tmpdir(),·`metrics-${process.pid}-${message.requestId}.json`` with `⏎↹↹↹↹↹↹↹os.tmpdir(),⏎↹↹↹↹↹↹↹`metrics-${process.pid}-${message.requestId}.json`,⏎↹↹↹↹↹↹`

Check failure on line 223 in lib/cluster.js

View workflow job for this annotation

GitHub Actions / Test on Node.js v21.x and OS ubuntu-latest

Replace `os.tmpdir(),·`metrics-${process.pid}-${message.requestId}.json`` with `⏎↹↹↹↹↹↹↹os.tmpdir(),⏎↹↹↹↹↹↹↹`metrics-${process.pid}-${message.requestId}.json`,⏎↹↹↹↹↹↹`

Check failure on line 223 in lib/cluster.js

View workflow job for this annotation

GitHub Actions / Test on Node.js v20.x and OS macOS-latest

Replace `os.tmpdir(),·`metrics-${process.pid}-${message.requestId}.json`` with `⏎↹↹↹↹↹↹↹os.tmpdir(),⏎↹↹↹↹↹↹↹`metrics-${process.pid}-${message.requestId}.json`,⏎↹↹↹↹↹↹`

Check failure on line 223 in lib/cluster.js

View workflow job for this annotation

GitHub Actions / Test on Node.js v18.x and OS macOS-latest

Replace `os.tmpdir(),·`metrics-${process.pid}-${message.requestId}.json`` with `⏎↹↹↹↹↹↹↹os.tmpdir(),⏎↹↹↹↹↹↹↹`metrics-${process.pid}-${message.requestId}.json`,⏎↹↹↹↹↹↹`

Check failure on line 223 in lib/cluster.js

View workflow job for this annotation

GitHub Actions / Test on Node.js v21.x and OS macOS-latest

Replace `os.tmpdir(),·`metrics-${process.pid}-${message.requestId}.json`` with `⏎↹↹↹↹↹↹↹os.tmpdir(),⏎↹↹↹↹↹↹↹`metrics-${process.pid}-${message.requestId}.json`,⏎↹↹↹↹↹↹`

Check failure on line 223 in lib/cluster.js

View workflow job for this annotation

GitHub Actions / Test on Node.js v16.x and OS windows-latest

Replace `os.tmpdir(),·`metrics-${process.pid}-${message.requestId}.json`` with `⏎↹↹↹↹↹↹↹os.tmpdir(),⏎↹↹↹↹↹↹↹`metrics-${process.pid}-${message.requestId}.json`,⏎↹↹↹↹↹↹`

Check failure on line 223 in lib/cluster.js

View workflow job for this annotation

GitHub Actions / Test on Node.js v21.x and OS windows-latest

Replace `os.tmpdir(),·`metrics-${process.pid}-${message.requestId}.json`` with `⏎↹↹↹↹↹↹↹os.tmpdir(),⏎↹↹↹↹↹↹↹`metrics-${process.pid}-${message.requestId}.json`,⏎↹↹↹↹↹↹`

Check failure on line 223 in lib/cluster.js

View workflow job for this annotation

GitHub Actions / Test on Node.js v20.x and OS windows-latest

Replace `os.tmpdir(),·`metrics-${process.pid}-${message.requestId}.json`` with `⏎↹↹↹↹↹↹↹os.tmpdir(),⏎↹↹↹↹↹↹↹`metrics-${process.pid}-${message.requestId}.json`,⏎↹↹↹↹↹↹`

Check failure on line 223 in lib/cluster.js

View workflow job for this annotation

GitHub Actions / Test on Node.js v18.x and OS windows-latest

Replace `os.tmpdir(),·`metrics-${process.pid}-${message.requestId}.json`` with `⏎↹↹↹↹↹↹↹os.tmpdir(),⏎↹↹↹↹↹↹↹`metrics-${process.pid}-${message.requestId}.json`,⏎↹↹↹↹↹↹`
fs.writeFile(filename, JSON.stringify(metrics), (err) => {

Check failure on line 224 in lib/cluster.js

View workflow job for this annotation

GitHub Actions / Test on Node.js v16.x and OS ubuntu-latest

Replace `(err)` with `err`

Check failure on line 224 in lib/cluster.js

View workflow job for this annotation

GitHub Actions / Test on Node.js v20.x and OS ubuntu-latest

Replace `(err)` with `err`

Check failure on line 224 in lib/cluster.js

View workflow job for this annotation

GitHub Actions / Test on Node.js v16.x and OS macOS-latest

Replace `(err)` with `err`

Check failure on line 224 in lib/cluster.js

View workflow job for this annotation

GitHub Actions / Test on Node.js v18.x and OS ubuntu-latest

Replace `(err)` with `err`

Check failure on line 224 in lib/cluster.js

View workflow job for this annotation

GitHub Actions / Test on Node.js v21.x and OS ubuntu-latest

Replace `(err)` with `err`

Check failure on line 224 in lib/cluster.js

View workflow job for this annotation

GitHub Actions / Test on Node.js v20.x and OS macOS-latest

Replace `(err)` with `err`

Check failure on line 224 in lib/cluster.js

View workflow job for this annotation

GitHub Actions / Test on Node.js v18.x and OS macOS-latest

Replace `(err)` with `err`

Check failure on line 224 in lib/cluster.js

View workflow job for this annotation

GitHub Actions / Test on Node.js v21.x and OS macOS-latest

Replace `(err)` with `err`

Check failure on line 224 in lib/cluster.js

View workflow job for this annotation

GitHub Actions / Test on Node.js v16.x and OS windows-latest

Replace `(err)` with `err`

Check failure on line 224 in lib/cluster.js

View workflow job for this annotation

GitHub Actions / Test on Node.js v21.x and OS windows-latest

Replace `(err)` with `err`

Check failure on line 224 in lib/cluster.js

View workflow job for this annotation

GitHub Actions / Test on Node.js v20.x and OS windows-latest

Replace `(err)` with `err`

Check failure on line 224 in lib/cluster.js

View workflow job for this annotation

GitHub Actions / Test on Node.js v18.x and OS windows-latest

Replace `(err)` with `err`
if(err) {
process.send({
Expand Down

0 comments on commit cbe29f3

Please sign in to comment.