Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module did not self-register: Worker Threads #257

Open
en-tcelvi opened this issue Jul 17, 2023 · 2 comments
Open

Module did not self-register: Worker Threads #257

en-tcelvi opened this issue Jul 17, 2023 · 2 comments

Comments

@en-tcelvi
Copy link

en-tcelvi commented Jul 17, 2023

Please answer these questions before submitting your issue. Thanks!

What version of pprof are you using?
3.2.0

What operating system and processor architecture are you using?
MacOS Ventura 13.4.1 (M1 Chip)
Alpine Linux 16

What did you do?
We run the Cloud Profiler product for Google Cloud in production. We wanted to move some operations into worker threads. These operations are currently ones we would like to profile.

What did you expect to see?
I expected everything to work fine when running our code inside a worker thread, and that pulling in this dependency would be no problem.

What did you see instead?
On Linux: Module did not self-register: /opt/crdt/node_modules/pprof/build/node-v108-linux-x64-musl/pprof.node
On Mac: node_modules/pprof/build/node-v108-darwin-arm64-unknown/pprof.node

Additional Information
Once we remove the Cloud Profiler tool (which uses pprof) from the dependency chain, our worker thread starts up with no problems. Perhaps this helps? https://github.com/nodejs/node/blob/main/doc/api/addons.md#context-aware-addons

Referred to this repository from: google/pprof#788

@theanarkh
Copy link

theanarkh commented Aug 4, 2023

I think we can not use pprof in both the main thread and the worker thread, but we can use it in worker thread as follows.

const { Worker, isMainThread } = require('worker_threads');
// Can not be loaded in both the main thread and the worker thread
// const profile = require('pprof');

if (isMainThread) {
    new Worker(__filename)
} else {
    const profile = require('pprof');
    // Removing this will cause a crash
    process._stopProfilerIdleNotifier = process._startProfilerIdleNotifier = () => {};
    profile.time.profile({
        durationMillis: 1000,
    });
}

@dmitryuk
Copy link

  1. node_modules/pprof/profiles.cc I have changed NODE_MODULE(google_cloud_profiler, InitAll); to NAN_MODULE_WORKER_ENABLED(google_cloud_profiler, InitAll);
  2. cd node_modules/pprof/build && make
  3. as @theanarkh said before calling profile I've added this line process._stopProfilerIdleNotifier = process._startProfilerIdleNotifier = () => {};

Worker profiling totally working now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants