Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 4 years and 6 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Not sure if anyone else has seen this, but there's what must be a bug that occasionally causes the parent thread to hang when trying to run Start-Job and if you're starting a bunch of jobs on a loop you'll probably hit it for sure. If you're hitting this and are looking for a workaround, I have one but it's a bit complicated.
Create a new sub-thread and launch the job from there. Here's some sample code. There are probably several different ways to detect when the start-job process fails.
From there you can deal with the threads in taskList. Most of the code to deal with threads was pulled from the start-parallel module. The rest I threw together.
Using process explorer, I discovered that if I kill the sub-process that was spun up when it hung the parent thread takes off again. So it looks like it's happening during the spinning up of the Powershell instance it's creating.
Also -- I'm not really able to recreate this on a Windows 2008 box with WMF 5.1 installed. The Powershell versions are slightly different though, so not sure if there's a bug fix for this between versions or if it's completely specific to 2016.
WMF 5.1 2008 PS Version -- 5.1.14409.1005
WMF 5.1 2016 PS Version -- 5.1.14393.3053
Anyone out there with access to Windows Server 2016 that you can run some test code, please see if Powershell hangs at some point during this:
jvierra wrote: ↑Thu Oct 03, 2019 3:27 pm
Remove the following and you will begin to see the issue.
[b}-ErrorAction SilentlyContinue[/b]
No. This is not the issue.
To be more clear -- it's not the cleanup of completed jobs that's the issue. Powershell hangs on STARTING a job. I can literally run PSExec and see the hung instance sitting there doing nothing and killing it causes the parent thread to start back up. Diagnostic output shows that it hung DURING the spin-up of the job.
Use my code to understand why this is happening. When you create 500 processes they will eventually get in trouble and may seem hung but are really just not getting scheduled enough to keep them running.
No one would every crate 500 processes with PowerShell because that would exceed the session limits or create a scheduling issue. If you need hundreds of tasks then use a "RunSpaceFactory" and many "RunSpaces". These can be throttled. The easiest way to do this is to use a Workflow that runs the task in parallel.
jvierra wrote: ↑Fri Oct 04, 2019 11:06 am
Use my code to understand why this is happening.
This. Is. Not. The. Issue. Sometimes it fails at job #6, sometimes at job # 100. Most of the time I can see with PSExec there is only one child Powershell process running. I've even had this fail on the very first job.
jvierra wrote: ↑Fri Oct 04, 2019 11:06 am
The easiest way to do this is to use a Workflow that runs the task in parallel.
I haven't gotten into workflows. Is that truly multi-threaded so I can saturate the cores on a machine? The code blocks I need to run varies in runtime and the scale of operations, but I need to squeeze as much out of the system as possible.
At the end of the day I don't care how I accomplish this as long as it gets the maximum performance. But there's still something amiss with starting a bunch of jobs at least on two different 2016 machines I have here.
This is not a scripting issue if it fails on the first job. You need to fix your systems. Of course this all depends on what script is running when it fails.
I've said from the start I think it's a bug specific to Windows Server 2016 but specifically wanted to see if anyone else saw this behavior to try to figure out if it is specific to my systems.
Interestingly if I use Invoke-Command to create jobs locally but treated as remote jobs this problem doesn't happen. It's specific to Start-Job.
This topic is 4 years and 6 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.