Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the Node --inspect flag have any notable performance impact?

Tags:

node.js

Not much to expand on beyond the title. I'm considering leaving the --inspect flag on my Node EC2 instances for debugging purposes at will, and I just want to check if there are any notable performance concerns (or security holes) from doing so.

like image 531
Ryan Spicer Avatar asked Jul 28 '17 17:07

Ryan Spicer


1 Answers

I believe the accepted answer does not fully address all possible use cases and is a bit misleading.

Lets divide the question into two.

Does --inspect flag without a debugger attached have any notable performance impact?
  • No
Does --inspect flag with a debugger attached have any notable performance impact?
  • Yes

TLTR:

When you use --inspect flag, you tell your nodejs process to listen for a specific port (9229 by default) and accept remote connections of a debugging client via ws protocol. Until you have a connection to this port, your nodejs performance stays the same as if you don't have this flag.

This was not always the case though. In 2019 this issue was raised https://github.com/nodejs/node/issues/28741 stating that having --inspect-brk flag raises CPU usage to 100%.

This commit by Eugene Ostroukhov fixed the issue https://github.com/nodejs/node/commit/49144ab64d3c5810f70585c2ccb0c90539fec116 and affected this releases: v17.4.0 v17.3.1 v17.3.0 v17.2.0 v17.1.0 v17.0.1 v17.0.0 v16.13.2 v16.13.1 v16.13.0 v16.12.0 v16.11.1 v16.11.0 v16.10.0 v16.9.1 v16.9.0 v16.8.0 v16.7.0 v16.6.2 v16.6.1 v16.6.0 v16.5.0 v16.4.2 v16.4.1 v16.4.0 v16.3.0 v16.2.0 v16.1.0 v16.0.0 v15.14.0 v15.13.0 v15.12.0 v15.11.0 v15.10.0 v15.9.0 v15.8.0 v15.7.0 v15.6.0 v15.5.1 v15.5.0 v15.4.0 v15.3.0 v15.2.1 v15.2.0 v15.1.0 v15.0.1 v15.0.0 v14.19.0 v14.18.3 v14.18.2 v14.18.1 v14.18.0 v14.17.6 v14.17.5 v14.17.4 v14.17.3 v14.17.2 v14.17.1 v14.17.0 v14.16.1 v14.16.0 v14.15.5 v14.15.4 v14.15.3 v14.15.2 v14.15.1 v14.15.0 v14.14.0 v14.13.1 v14.13.0 v14.12.0 v14.11.0 v14.10.1 v14.10.0 v14.9.0 v14.8.0 v14.7.0 v14.6.0 v14.5.0 v14.4.0 v14.3.0 v14.2.0 v14.1.0 v14.0.0 v13.14.0 v13.13.0 v13.12.0 v13.11.0 v13.10.1 v13.10.0 v13.9.0 v13.8.0 v13.7.0 v13.6.0 v13.5.0 v13.4.0 v13.3.0 v13.2.0 v13.1.0 v13.0.1 v13.0.0

Finally, it was fixed in ^v12.7.0 with this pull request: https://github.com/nodejs/node/pull/28817

Now, what if we have a debugger client connected?

If we have a connected debugger client you will experience huge performance impact, estimate CPU intensive code to be about 100-300 times slower. I/O related code is not impacted though.

debugger keyword.

This keyword is not related to --inspect flag directly. It works when you run your node process with inspect argument and opens debugging client in the REPL. https://nodejs.org/api/debugger.html

WARNING

This keyword affects the performance even if you don't have any debugging session running e.g. you started your application normally with node my-app.js.

like image 120
ZuzEL Avatar answered Nov 06 '22 15:11

ZuzEL