The StrongLoop Arc Profiler (released previously) enables you to gather and view CPU profiling and heap memory snapshot data for Node applications. With this release, the Profiler just became smarter! This blog post is intentionally written tutorial style and will show you how to take advantage of the new Smart Profiling support.
What is Smart Profiling?
Profiling is an important part of optimizing and troubleshooting any Node.js application. However, profiling an application has a couple of issues. It often causes significant overhead, making it difficult to use outside of testing environments. Also, many performance issues are intermittent, and require running the profiler for an extended period of time. This can make it difficult to isolate profiling information for the actual issue from the general background noise of running the profiler for so long.
Smart Profiling attempts to improve these two issues. It works by allowing you to specify a minimum threshold that the event loop must stall, before the profiler will capture any performance data for that event. This helps to reduce the amount of noise captured in the profile, and also dramatically reduces the overhead of running the profiler.
Let’s look at an example scenario where using Smart Profiling could be a useful tool.
In our first scenario, we are going to assume you have an application deployed which is having an intermittent issue. Certain API calls are taking far longer to process than they should. Despite significant attempts to reproduce it in a test environment, the issue only seems to show up on the production system.
Normally, running the profiler on all workers would cause excessive slow down, which would be unacceptable on your production deployment. However, by using Smart Profiling, we can set the profiler running across all workers, without having to worry about causing excessive load on the process manager (PM).
Of course you may not have a problem in Production and still want to evaluate Smart Profiling. In which case you may choose to use our example application found here: https://github.com/strongloop/smartprofiling-example-app
Step 1 – Connect to the PM
Navigate to the Profiler module within Arc, and select your PM’s hostname from the drop down menu and click ‘Load’.
Tip: If you haven’t already, you’ll need to add your PM host to the Process Manager screen in Arc. Check out the documentation for how to do so.
After a few seconds, Arc will show the available worker processes on the PM, and a “Profile Settings” option that appears next to the host selector.
NOTE: If you do not see the Profile Settings option, then your PM does not support Smart Profiling. Please check the usage notes at the bottom of this post or refer to StrongLoop documentation.
Step 2 – Set up the profiler settings
Next we need to set up the values for the Smart Profiler. Click on “Profiler Settings”, and you’ll see an options dialog with a few values. You have a mode switch, to toggle between Smart and Full profiling.
When using Smart Profiling, there a couple of other options you can select.
The “Event Loop Execution Threshold” is the amount of time (measured in milliseconds) that the event loop on the server must execute a request before any profiling data is captured. This acts as a filter, to reduce noise from typical requests and focus the profiler on requests that take longer than is expected. In other words, how long do you want to wait to assume the event loop is blocked?
The second configurable value is “Max Samples”. This is how many times the Smart Profiler will trigger before it automatically turns off profiling for that particular worker, and makes the profiler data available for viewing.
Step 3 – Start Profiling
Next we need to select the worker processes that we want to profile. Because Smart Profiling doesn’t load down the processes, you can select multiple processes to profile when using Smart Profiling. Click to select the processes from the process list, and you’ll see their PIDs be added to the list in the main profiler control area.
After you have selected all the processes you want to profile, click start and Arc will set the profiling request to the PM. After a few seconds, you’ll see the processes’ status change to ‘Profiling’
If you are using our example app, after a few moments, the requests going through will trigger the profiler enough to max out the cycles counter, and the process will go back into the “Running” state. You’ll also see the profiles with the profiler data appear on the menu on the left. (Note that for your own production applications these profiles may not appear quite so fast!)
Go ahead and click on one of these profiles to download and view the profile data. If you’re not sure how to read a CPU profile, check out Shubhra Kar’s blog post on profiling!
- Smart Profiling from within Arc is supported for Strong PM version 5.0 and higher.
- Currently, Smart Profiling is only supported on the PM when it’s running on Linux. We are working hard to release similar and enhanced profiling functionality when running on Mac OS.
- Full profiling is supported on all platforms.
- To use Smart Profiling we’ll need to unlock the feature inside of StrongLoop Arc. Please email email@example.com to get a trial license and speak with a solutions architect.