Universal.Server High CPU/Memory

Product: PowerShell Universal
Version: 2.8.2 and 2.8.3

I’ve upgraded our Powershell Universal version to 2.8.2 and started experiencing high CPU and memory usage. I upgraded to the latest nightly for 2.8.3 and am still experiencing this issue. I saw another topic in the forums where someone else was experiencing this on 2.7.x and the 2.8 update resolved it for them. Any advice on a direction to start troubleshooting this?
image

I’m also having an issue where all of the scripts aren’t being displayed at startup. If I make a change to scripts.ps1 and save the file, it tries again and will successfully load the rest of the scripts. Looking for some advice on this issue too. Here’s the error in the logs for this issue:

2022-02-18 12:02:08.780 -05:00 [ERR] Failed to read configuration file. scripts.ps1
System.InvalidCastException: Unable to cast object of type ‘System.Management.Automation.Language.TypeConstraintAst’ to type ‘System.Management.Automation.Language.AttributeAst’.
at System.Linq.Enumerable.CastIterator[TResult](IEnumerable source)+MoveNext()
at System.Linq.Enumerable.Any[TSource](IEnumerable1 source) at UniversalAutomation.ScriptParameterParser.GetParameters(ScriptBlock scriptBlock)+MoveNext() in D:\a\universal\universal\src\Universal.Server\Utilities\ScriptParameterParser.cs:line 107 at System.Collections.Generic.List1…ctor(IEnumerable1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source)
at UniversalAutomation.Services.ScriptsConfigurationScript.UpdateScript(Script script) in D:\a\universal\universal\src\Universal.Server\Services\Configuration\Scripts.cs:line 171
at UniversalAutomation.Services.ScriptsConfigurationScript.OnReadAfterUpdateAsync(Script script) in D:\a\universal\universal\src\Universal.Server\Services\Configuration\Scripts.cs:line 239
at UniversalAutomation.Services.ConfigurationScript`1.ReadAsync(Boolean initialSync) in D:\a\universal\universal\src\Universal.Server\Services\Configuration\ConfigurationScript.cs:line 236

Would you mind upload a memory dump to dropbox so I can review it?

As for the scripts failing, it looks like something is happening while we are attempting to parse parameters. If I had to guess, you have a script that has a [Parameter] attribute without the parathesis.

For example:

param([Parameter]$Parameter1)

Instead of

param([Parameter()]$Parameter1)

The other thing I was thinking about is that you could try to use some of the new profiling tools to see if anything stands out as being slow.

For example, you can drill down into slow requests.

We don’t profile everything but might be a place to look.

Hi Adam, I’ve uploaded the memory dump for the process. In the meantime, I’ll take a look profiling tools and see if anything stands out. Thanks!

1 Like

@jared.pannell - The high memory usage was partially due to the profiler storing all the timings. We’ve included a switch in appsettings.json to turn it on and it is now off by default in PSU v2.8.3 and later.

The high CPU usage may be partially due to implicit remoting happening. I noticed that there was a Windows Compat session opened by PowerShell in your instance.

Thanks Adam. I updated to 2.8.3 earlier this week and it seems to have resolved both cpu and memory issues.

2 Likes