Skip to content

feat: support aggregating metrics across workers in a Node.js worker_… - #403

Closed
rafixer wants to merge 3 commits into
prometheus:mainfrom
rafixer:worker_threads_support
Closed

rafixer wants to merge 3 commits into
prometheus:mainfrom
rafixer:worker_threads_support

Conversation

@rafixer

@rafixer rafixer commented Oct 15, 2020 •

Copy link
Copy Markdown

…threads

this PR is connected with this issue: #401 (comment)

@zbjornson zbjornson linked an issue Jan 23, 2021 that may be closed by this pull request

@zbjornson zbjornson left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for opening this and sorry it took forever to get reviewed. A few comments below, plus:

  • Looks like Node.js 10 breaks - drop support
  • Needs a changelog update
  • Please add tests

Comment thread lib/cluster.js Resolved
Comment thread lib/cluster.js Resolved
@bgalek

bgalek commented May 5, 2021 •

Copy link
Copy Markdown

@zbjornson node 10 met its EOL https://nodejs.org/en/about/releases/ maybe we should not test against it anymore? worker features are available from node 11.0.0

@SimenB

SimenB commented May 12, 2021

Copy link
Copy Markdown
Contributor

Dropping node 10 must be done in a major release, but we can probably do one of those?

@alec-benson

Copy link
Copy Markdown

any chance we could push this along? I am using worker threads on a project and this would help a lot.

@bgalek

bgalek commented Jul 23, 2021

Copy link
Copy Markdown

@rafixer @zbjornson? :)

@zbjornson

Copy link
Copy Markdown
Contributor

This looks good.

We have two other PRs staged for a semver-major release. Let's drop v10 support in that release and land this PR with it.

(I can add the changelog and fix the merge conflict if @rafixer doesn't get to it.)

@bgalek

bgalek commented Feb 18, 2022 •

Copy link
Copy Markdown

@zbjornson any chances for new major? :) deprecation fix for node 16+ is also "ready to release" - it would be great if new release comes some time soon ;)

@bgalek

bgalek commented Feb 28, 2022

Copy link
Copy Markdown

@zbjornson? :)

@Zagorodnyi

Zagorodnyi commented Jun 2, 2022 •

Copy link
Copy Markdown

@zbjornson Any news about this feature?

@rafixer

rafixer commented Jun 2, 2022

Copy link
Copy Markdown
Author

Sorry for no action about this PR. I will back to this on next week!

@rafixer
rafixer force-pushed the worker_threads_support branch from c3a1be5 to 2bb230a Compare October 14, 2022 10:17

@SimenB SimenB left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry about the slow response! can you update the documentation?

Comment thread lib/workerThreads.js Resolved
Comment thread lib/workerThreads.js Resolved
@SimenB
SimenB changed the base branch from master to next January 17, 2023 13:58
@rafixer

rafixer commented Jan 17, 2023

Copy link
Copy Markdown
Author

sorry about the slow response! can you update the documentation?

also, I will check why currently tests cases are failing

@SimenB

SimenB commented Jan 17, 2023

Copy link
Copy Markdown
Contributor

there's a syntax error. Miiight be the merge? ee05476 (#403). I didn't get any merge conflicts, tho

@SimenB

SimenB commented Jan 17, 2023

Copy link
Copy Markdown
Contributor

Fixing the syntax error gives a bunch of lint errors, so I dunno 😅

@rafixer

rafixer commented Jan 17, 2023

Copy link
Copy Markdown
Author

as I remember, I tried to refactor the implementation - I will bring back the previous one

@rafixer

rafixer commented Jan 17, 2023

Copy link
Copy Markdown
Author

but still, I'm worried that implementation might not be efficient - because it depends on communication between parent < - > child, especially when using a nested tree of workers/processes. Maybe the better idea will be to create a separate process and try to communicate with him via IPC

@SimenB

SimenB commented Jan 17, 2023

Copy link
Copy Markdown
Contributor

thread communication shouldn't be any slower than separate process, should it?

@SimenB
SimenB force-pushed the next branch 6 times, most recently from 3f25c32 to 47441a0 Compare March 9, 2023 11:52
@SimenB

SimenB commented Mar 13, 2023

Copy link
Copy Markdown
Contributor

@rafixer could you target master with this (and resolve conflicts)?

@rafixer
rafixer changed the base branch from next to master March 13, 2023 14:45
@rafixer

rafixer commented Mar 13, 2023

Copy link
Copy Markdown
Author

@rafixer could you target master with this (and resolve conflicts)?

Target changed , resolving conflicts in progress!

@rafixer
rafixer force-pushed the worker_threads_support branch from 6aad6b5 to e2e185b Compare March 14, 2023 09:17
@rafixer
rafixer force-pushed the worker_threads_support branch from e2e185b to 7e1fc1f Compare March 14, 2023 09:25
@infloop

infloop commented Jun 26, 2023

Copy link
Copy Markdown

@SimenB @zbjornson Are there any updates yet? Does this need any help?

@iamyamakin

Copy link
Copy Markdown

@SimenB @zbjornson are you waiting for tests and changes for readme.md? How can we help you?

@mt-bt

mt-bt commented Jul 8, 2024

Copy link
Copy Markdown

@SimenB @zbjornson Any update on this? Anything we can do to push this through?

@nrathi

nrathi commented Jul 25, 2024

Copy link
Copy Markdown

+1, this would really help me as well!

@SimenB SimenB left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to write tests for this? Probably by spinning up some process which emulates this and making requests against it?

I can't speak to the feature itself as I've never used the cluster mode

Comment thread lib/cluster.js
cluster().on('message', (worker, message) => {
if (message.type === GET_METRICS_RES) {
const request = requests.get(message.requestId);
request.pending += message.workerRequests || 0;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
request.pending += message.workerRequests || 0;
if (message.workerRequests) {
request.pending += message.workerRequests;
}

Comment thread lib/cluster.js
if (message.type === GET_METRICS_REQ) {
let workerRequests = 0;
workersQueue.forEach(worker => {
if (worker && worker instanceof Worker) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (worker && worker instanceof Worker) {
if (worker instanceof Worker) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we check this when instantiating/pushing into workersQueue rather than when receiving messages? We should probably throw

Comment thread lib/cluster.js
process.on('message', message => {
if (message.type === GET_METRICS_REQ) {
let workerRequests = 0;
workersQueue.forEach(worker => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use for-of instead of forEach

Comment thread lib/cluster.js
parentPort.on('message', ({ type, requestId, port } = {}) => {
if (type === GET_METRICS_REQ) {
Promise.all(registries.map(r => r.getMetricsAsJSON()))
.then(metrics => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use async-await rather than .then and .catch?

@jdmarshall

Copy link
Copy Markdown
Contributor

Covered by #693

@jdmarshall jdmarshall closed this Jul 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for worker_threads module