Skip to content

No handling for non-cluster worker threads? #656

Closed

Description

@pies

Hi,

Is there a way to get multi-threaded workers to report metrics? Thanks!

I.e.

import {spawn, Worker} from 'threads';

const worker = await spawn(
      new Worker('worker-code', params as any),
      {timeout: 40 * MINUTE_IN_MS},
) as ModuleThread<any>;

Activity

  1. jdmarshall commented on Jul 11, 2025

    @jdmarshall
    Contributor

    After I finish #688 I might have time to look at this.

  2. added 2 commits that reference this issue on Jul 12, 2025
    f6bc8b7
    b26b8e6
  3. jdmarshall commented on Jul 13, 2025

    @jdmarshall
    Contributor

    I've been working in this code recently.

    I have a PoC but I may be stuck.

    I've been chatting with @zbjornson on another PR about making sure the aggregator doesn't gum up the primary thread when run in cluster mode, and it's dawned on me that rather than splitting up clusterMetrics() with setImmediates, it would be much simpler if the main thread could offload stats monitoring to a worker, which can then use all the CPU it wants.

    Problem is the Node folks didn't get the worker API right on the first or second try (see also piscina, and https://nodejs.org/api/worker_threads.html#workerpostmessagetothreadthreadid-value-transferlist-timeout which is unstable but allows you to message arbitrary workers)

  4. jdmarshall commented on Jul 14, 2025

    @jdmarshall
    Contributor

    I have a working prototype now, by using n + 1 BroadcastChannels

    But it supports autodiscovery, and shunting collection into a Worker.

  5. added a commit that references this issue on Jul 29, 2025
    9561bfd
  6. jdmarshall commented on Dec 9, 2025

    @jdmarshall
    Contributor
  7. added this to the v0.16 milestone on Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions