0

After my application was running @ 400%+ CPU usage in a dockerised app, I decided to try using @google-cloud/profiler. The setup was easy enough but I am disappointed with what I see in the UI:

enter image description here

As you can see, what is consuming the most resources, I can't seem to look into as there's no info about it. It's labelled as "(external)" & no file. I am very new to Google Cloud CPU Profiler but it seems quite out of the box. My application is a multi-process one & it is the child process' that are causing the high CPU load so I invoke the CPU profiler on the entry of these child process'

src/cluster/worker/index.js

module.exports = async function() {
    try {
        await require('@google-cloud/profiler').start({
            projectId: process.env.GOOGLE_PROJECT_ID,
            serviceContext: {
                service: process.env.GOOGLE_SERVICE || 'app',
                version: process.env.GOOGLE_VERSION || '1.0.0'
            },
            // want to disable logging to the console
            logLevel: 0
        })

        ...
    } catch(err) {
        ...
    }
}

There are many child process' running (5 ish) so could this be the issue? Also, when I select to view the history of the profile, I get this:

enter image description here

As mentioned, I am new to Google Cloud & CPU profiling in general so any help would be appreciated. Sadly, I cannot find any help in Google forums & no one has raised any similar issues on the NPM package itself.

wmash
  • 4,032
  • 3
  • 31
  • 69

1 Answers1

0

The process in which you're starting Cloud Profiler has no visibility into any (other) processes that the process may spawn.

I'm unsure whether there's even a Linux-level concept of "subprocess" or whether these are a programming language concept that map to regular processes.

Each process has its own stack and heap and so profilers (not just Cloud Profiler) that profile stacks and heaps are, by definition, per process.

The CPU is a resource shared by many processes.

To gain a comprehensive view you would need to have each process export profiles to Cloud Profiler and, if you're invoking 3rd-party binaries, this may not be possible.

Generally (!) invoking "subprocesses" is problematic. As you've experienced, it hinders visibility (no coherent profiling, tracing or logging), error handling is lacking and integration between processes is restricted to untyped pipes.

DazWilkin
  • 32,823
  • 5
  • 47
  • 88