Some time ago we faced an issue with NodeJS slowing JSS in integrated mode significantly over time in Azure PaaS. We saw requests growing from sub-second to 3-4 seconds. Here is what you need to check as you do troubleshooting of your solution.

Configurations & Checks

Pass custom parameters to Node JS in integrated mode First of all, we tried to gather some information about NodeJS. To do that, we followed a recommendation by Adam, which you can find here: https://sitecore.stackexchange.com/questions/16257/profiling-sitecore-9-1-jss-server-side-rendering-node-server

This will allow you to run NodeJS in –profile mode and gather some profile information.

    node --prof server.bundle.js

Process profile logs After loading the site for some time you will need to go to the Azure Kudu console, kill node processes and navigate to the location of your server bundle. Next to it, you will find logs generated by the profiler. To read it you’ll need to process it with the following command:

    node --prof-process ./isolate-XXXXXXXX-v8.log > isolate-XXXXXXXX-v8.txt

**Check the version of Node in Azure **

kudu > run 'node --version'

Important to match the Azure node version and version of your prof-process Kudu > run node -p "process.arch" or node -p "process" for full info about node.

Check available versions Some of the issues might be related to older versions of node.js referenced by your application via the WEBSITE_NODE_DEFAULT_VERSION variable in the App Service configuration. To find out what versions are available got to KUDU > Runtime versions > check node.js.

Findings

After some time of trial end errors, we figured out that issue was related to the nodejs process not cleaning up memory after a significant amount of working under load. We saw that the process eating up to 750MB of RAM after load tests. We also notice that memory accumulation was significantly improved by an upgrade from nodejs v8 LST to v10 LST.

Solution

A cheap and dirty solution for us was to leverage the JSS mechanism of reloading new JS bundles. Behind the scene, JSS monitors your dist folder for updates of JS and JSON files. So we end up creating a reset.json file and updating it via Sitecore agent every hour.


As usual, follow me on Twitter @true_shoorik 😉