CPU Profiling in Production Node.js Applications

January 30, 2018

Post

There are multiple reasons why a program will consume more CPU resources than excepted. For a highly computationally complex algorithm, the amount of data it operates on will drive the CPU usage. For I/O-intensive programs, data processing may be the bottleneck. Garbage collection activity is another usual suspect.

To optimize or troubleshoot an application’s consumption of CPU resources, a CPU profiler is necessary. Without it, it would take a lot of guesswork, code modifications and diagnostics to localize the CPU hot spots, i.e. the lines of code where the most of the CPU is being used.

The challenge of profiling production and cloud applications

The profilers that are traditionally used in development environment are not suitable for modern cloud applications. One reason is that the data is usually not available offline for debugging or problem reproduction purposes. Think of machine learning algorithms or other data-intensive applications. Another reason is the difference between production and development environments in terms of configuration, infrastructure, types of possible errors, etc. Last but not least, the development profiler’s overhead is typically very high.

The missing profile history

Another problem is irregular or on-demand one-off profiling. For the apps that are constantly running in production it is important to know the dynamics of the hot spots with associated historical context (e.g. an application release version, runtime version or other metrics).

In other words, it is equally important to understand when the problem started and why.

Using Instana AutoProfile™ for continuous CPU profiling

Instana is designed for profiling and monitoring both production and development environments. It completely automates the collection of CPU profiles. The Instana AutoProfile agent is initialized in the application. It records and reports regular CPU profiles to the Dashboard.

It’s simple to add the agent to your application. You will need an Instana license, which is available as a two-week trial.

To enable AutoProfile™, add autoProfile: true option when initializing the collector (or set the environment variable INSTANA_AUTO_PROFILE=true). This feature requires @instana/[email protected] or later and at least Node.js 6.4.0.

require('@instana/collector')({
  autoProfile: true
});

See Node.js Collector Configuration for more information.

After restarting/deploying the application, the profiles will be available in the Dashboard in a historically comparable form with context information for each profile.

Play with Instana’s APM Observability Sandbox

Profiling
There are multiple reasons why a program will consume more CPU resources than excepted. In the case of a high computational complexity of an algorithm, the amount of data it operates on...
|
Announcement, Developer, Product
PHP profiling is used by developers to identify performance issues or bottlenecks in their code. Profilers enable developers to drill into individual lines of code to ascertain which ones are running slow...
|
Announcement, Product
As you may have already heard from us back in December 2019, Instana has acquired StackImpact. During the last few months, we were working hard integrating StackImpact’s continuous profiling functionality to Instana,...
|

Start your FREE TRIAL today!

As the leading provider of Automatic Application Performance Monitoring (APM) solutions for microservices, Instana has developed the automatic monitoring and AI-based analysis DevOps needs to manage the performance of modern applications. Instana is the only APM solution that automatically discovers, maps and visualizes microservice applications without continuous additional engineering. Customers using Instana achieve operational excellence and deliver better software faster. Visit https://www.instana.com to learn more.