JSS site is running in integrated mode on Sitecore 9.1
I have problem with the SSR node process, it's hanging around 18 min on load tests and results in error 500 for site.
For blind solution I turned cache for GraphQL queries on SSR side, which is not a good option but good for start. Only change was node hangs around 20 min of stress tests.
My findings:
- When I turned off GraphQL, there was is no problem.
- In Sitecore logs, GraphQL queries executes fast, since they are cached. Only from time to time they take 1s, mostly it's 50 - 200 ms.
So I decided to profile this piece, but:
- How can I turn on profiling on the node process for Sitecore SSR? Normally it's is allowed by start with
--prof
parameter i.e.node --prof server.js
- Any other ideas how to profile node SSR?
Best Regards
Update
Solution provided by @Adam Weber works like charm. Thanks, you saved me a lot of time :)
I have tuned your code a bit to make arguments configurable by NODE_ENV_ARGUMENTS
variable:
class CustomHttpNodeInstance : HttpNodeInstance
{
public CustomHttpNodeInstance(NodeServicesOptions options, int port = 0) : base(options, port)
{
}
protected override ProcessStartInfo PrepareNodeProcessStartInfo(string entryPointFilename, string projectPath, string commandLineArguments,
IDictionary<string, string> environmentVars, bool launchWithDebugging, int debuggingPort)
{
var startInfo = base.PrepareNodeProcessStartInfo(entryPointFilename, projectPath, commandLineArguments,
environmentVars, launchWithDebugging, debuggingPort);
Log.Debug(GetType().Name + " environmentVars: " + string.Join("; ", environmentVars.Select(kv => $"{kv.Key}={kv.Value}")), this);
var arguments = string.Empty;
if (environmentVars.TryGetValue("NODE_ENV_ARGUMENTS", out arguments) && !string.IsNullOrEmpty(arguments))
{
startInfo.Arguments = arguments + " " + startInfo.Arguments;
}
return startInfo;
}
}
Patch file:
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<javaScriptServices>
<renderEngines>
<renderEngine name="nodejs" >
<instance>
<EnvironmentVariables>
<var name="NODE_ENV_ARGUMENTS" value="--prof" />
</EnvironmentVariables>
</instance>
</renderEngine>
</renderEngines>
</javaScriptServices>
</sitecore>
</configuration>