“Profiling” as in stereotyping is not a good practice.  However, when it comes to node.js it is a very good practice to “profile” your code.  Using Profiling techniques it is possible to generate views of CPU and memory utilization for your applications, detect memory leaks and/or CPU issues and then take action to optimize your code.

Profiling your node.js code can help improve execution making your code faster and managing your memory consumption better, even more efficiently than the virtual machine can. Through Profiling you can look inside the execution of your code.  JavaScript, is a powerful language with advanced features. Therefore the behavior of the JavaScript engine is quite sophisticated, and there are cases when you really need to go deep into the details of how the engine works. Some of the code patterns you use need to be tweaked to allow the JavaScript optimizer to do its work.


There are several tools to help you profile your node.js code.  The purpose of this blog is to help gather pointers to the tools together into a single place.

Where to begin?  How about with the profiler that is built into Node itself!  Node.js provides a built in capability to find CPU and memory
bottlenecks.  The built-in profiler uses the profiler inside JavaScript which samples the CPU and memory utilization at regular intervals during program execution. It records the results of these samples, and provides tools to help interpret the results.  Instructions and examples demonstrating the use of the built in profiler can be found at https://nodejs.org/en/docs/guides/simple-profiling/.   Node modules can be found on GitHub for the V8 profiler bindings and the node heap dump at the following urls:


StrongLoop Arc and slc are no longer under active development, and will soon be deprecated. Arc’s features are being included in the IBM API Connect Developer Toolkit which is what should be used for these functions.  However there are a few StrongLoop urls that provide good information on profiling that we have included:

Google has also provided Chrome DevTools to assist with debugging CPU and memory issues in JavaScript.
  The CPU profiling tool (https://developers.google.com/web/tools/chrome-devtools/rendering-tools/js-execution) allows you to record a CPU profile during execution and then tailor the view, zoom in on specific parts of the execution and view details on the parts of the application that are causing issues.  The equivalent tool for memory issues (https://developers.google.com/web/tools/chrome-devtools/memory-problems/heap-snapshots#view_snapshots) supports taking JavaScript heap snapshots, manages the snapshots, compares snapshots before and after potential issues and helps identify memory leaks.

WebStorm is a lightweight yet powerful Integrated Development Environment for client-side and server-side development with Node.js that also provides a GUI profiler tool (https://www.jetbrains.com/help/webstorm/2016.2/v8-cpu-and-memory-profiling.html).  The GUI tool provides an easy to use interface providing both CPU and memory profiling capability.

Richard Chamberlain (IBM) provided a blog “NodeReport – first failure data capture for Node.js” describing how to implement first failure data capture (FFDC) using the NodeReport npm module.  The blog describes how to install and configure the NodeReport capability.  With FFDC debugging is always on, but has minimal impact to performance.  This allows the capturing of sufficient data on the first instance of failure rather than post-processing error conditions which may be difficult to recreate.

Finally, IBM supplies a Health center that can assist with profiling node.js.  The health center was originally provided for Java and has been extended to support node as well.  Stewart Addison wrote a blog “Monitoring your Node.js application with the (free) IBM Health Center” describing how to install and execute the health center capabilities to profile your node.js application.

IBM API Connect is IBM’s complete foundation to Create, Run, Manage, and Secure APIs.  You can find more information about IBM API Connect at the API Connect website.  And you can also experience a trial version of API Connect.

If you have questions, please let me know.  Connect with me through comments here or via twitter @cyberfeng to continue the discussion.

Join The Discussion

Your email address will not be published. Required fields are marked *