Sitelet https://github.com/nodejs/node/issues/41589
Skip to content

Give a name to a Worker (for debugging purpose) #41589

Description

@shayyzhakov

What is the problem this feature will solve?

While debugging my Node.js app in VS Code, I've been trying to figure out which of the workers that are running is responsible for what, but found it hard to follow the flow as the workers were named Worker ${index} instead of having a more descriptive name. Since I'm heavily depending on workers and passing them any heavy job I encounter from time to time, I want to be able to track which of them is active at the moment during runtime.

image

What is the feature you are proposing to solve the problem?

It would be great if you could allow passing an optional param to specify a name/title for the worker, so we can later on use to track which of the workers are running (by name and not by a random number).

What alternatives have you considered?

No response

Activity

  1. targos commented on Jan 19, 2022

    @targos
    Member

    @nodejs/workers

  2. benjamingr commented on Jan 19, 2022

    @benjamingr
    Member

    First of all - this ask sounds very reasonable to me.

    Currently it just does:

      static std::string BuildWorkerTitle(int id) {
        return "Worker " + std::to_string(id);
      }

    cc @eugeneo @addaleax

  3. added
    workerIssues and PRs related to the worker_threads module and Worker API.
    on Jan 19, 2022
  4. targos commented on Jan 19, 2022

    @targos
    Member

    I wonder why the process.title and --title APis are explicitly not supported for workers.

  5. addaleax commented on Jan 19, 2022

    @addaleax
    Member

    @targos @benjamingr I don’t think we ever specifically thought about Worker names in the context of the inspector. #32434 also has a bunch of information about why we did not implement other kinds of APIs for naming Workers (yet).

  6. moved this to Pending Triage in Node.js feature requestson Apr 4, 2022
  7. github-actions commented on Jul 19, 2022

    @github-actions
    Contributor

    There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment.

    For more information on how the project manages feature requests, please consult the feature request management document.

  8. added
    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.
    on Jul 19, 2022
  9. gireeshpunathil commented on Jul 19, 2022

    @gireeshpunathil
    Member

    I still believe adding name to the worker object rather than the worker's native thread (that suffers from portability issues) will be useful to some class of user scenarios - for example the tools (such as report, llnode etc.) can be taught to retrieve and display the worker names. Also, having a standard way of doing this such as in the worker constructor as opposed to the programmer explicitly adding it as a property makes the observability much more consistent.

  10. removed
    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.
    on Jul 20, 2022
  11. github-actions commented on Jan 17, 2023

    @github-actions
    Contributor

    There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment.

    For more information on how the project manages feature requests, please consult the feature request management document.

  12. added
    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.
    on Jan 17, 2023
  13. flipswitchingmonkey commented on Jan 20, 2023

    @flipswitchingmonkey

    Can we not just get an optional 'WorkerPrefix' parameter that falls back to 'Worker'? That seems like a rather simple change to me?

  14. removed
    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.
    on Jan 21, 2023
  15. bnoordhuis commented on Jan 22, 2023

    @bnoordhuis
    Member

    @flipswitchingmonkey I don't think there are any major objections, it just needs someone to do the work. Pull request welcome.

    I'm inclined to say it should be an inspector module method but open to being convinced otherwise.

  16. flipswitchingmonkey commented on Jan 22, 2023

    @flipswitchingmonkey

    My c++ is half a decade out of use, but I might have a look...

    A quick glance at the code shows me that at

    std::string name = "WorkerThread ";
    we are also setting a name for the Worker thread, again hardcoded (this time to WorkerThread +id), so it would probably make sense to somehow combine those into a single customisable prefix?

  17. bnoordhuis commented on Jan 22, 2023

    @bnoordhuis
    Member

    That's used for tracing. The inspector name is generated here:

    info_(BuildWorkerTitle(id), url, worker_thread),

    Of course it'd be good to have them be consistent. Perhaps the trace name can be computed from WorkerInfo::title or the other way around.

  18. moved this from Awaiting Triage to Done in Node.js feature requestson Jun 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues requesting new Node.js features.workerIssues and PRs related to the worker_threads module and Worker API.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions