N|Solid is a profiling engine for NodeJS applications. You install it to replace your standard NodeJS runtime while profiling, and you provide environment variables to your process during launch to tell it where a N|Solid engine lives.
Watch this video to get a feel for how to use N|Solid to profile your applications.
[raw]
Getting started with N|Solid 1.4.0: Profiling Node.js applications like a boss! from Chariot Solutions on Vimeo.
[/raw]
As of N|Solid 1.4, there are downloadable all-in-one setup programs for Debian/Ubuntu, RHEL and CentOS, as well as MacOS X. They've combined a series of three scripts into a launcher, placed it in a commonly-found location (/usr/local/nsolid for OSX, /opt/nsolid for Linux) and even given you an environment script to source to set up your shell.
For more information, read on…
Launching your application in N|Solid
In your OS command line, you can run source /usr/local/nsolid/nsolid-env
, and then launch the N|Solid profiling engine with nsolid-server
.
Configuring your application to be monitored by N|Solid is almost too easy, provided you have the N|Solid version of node
(also called nsolid
) in your path as well. You have to add launch environment variables to the front of your startup script.
A launcher for an application fired up via node looks like this:
nsolid_APPNAME=BADAPPL NSOLID_HUB=2379 nsolid server.js
where
NSOLID_APPNAME
sends a name to the Console for your application to help you distinguish it from other NodeJS serversNSOLID_HUB
points to the process launched with./launch-N|Solid-proxy.sh
, a NodeJS engine that watches for network traffic from your application server once launched. Your NodeJS process will feed its telemetry data to that proxy portnsolid
can be replaced bynode
or any other NodeJS utility, such aspm2
if you're launching a set of clustered services
Tip – don't block the NodeJS Event Loop
How do you write code that is friendly to the event loop in NodeJS applications? In several ways: by using asynchronous external APIs, avoiding long-running processes, and writing applications that yield up time to the processor if they run for more than a few milliseconds.
Wrap-up and future articles
In the screencast above we took a tour of N|Solid, and used it to profile an application under load. We exported our reports from N|Solid to the Chrome CPU profiler.
In upcoming articles we'll focus on monitoring memory usage with snapshots, and how to run clusters to handle significant load using PM2 and stress test them with Artillery, a great load generator tool.
Resources
- A nascent badly behaving set of NodeJS code for illustrating problem code in node – Github Repository.
- N|Solid – the NodeJS server-side profiling toolkit.