Open fflaten opened 2 years ago
Foreach-Object -Parallel
also use the 10MB DefaultPipelineStackSizeAny reason why the same limit isn't used for jobs and remote sessions?
I think it makes sense to have the same limit.
/cc @PaulHigin
@WG-Remoting
Remote execution of commands and script is more complex than with the local pipeline case. By default the remoting endpoint will run commands/script on the same thread the remoting message is processed on, to save the overhead of generating extra threads. In the Start-Job case, these are .Net threadpool threads and you cannot change the stack size on them AFAIK.
There is a mechanism to change this default behavior and specify a PSThreadOptions.UseNewThread
which will cause the remoting endpoint to execute the command/script in a new PS pipeline thread, which will automatically get the 10MB stack size. However, this is not currently exposed through Start-Job
, but is something that could be added.
I still believe this is worth a fix to provide a consistent environment for users regardless of how they invoke their code.
@iSazonov Could we please reopen this? Still relevant and I don't like duplicating issues 🙂
By default the remoting endpoint will run commands/script on the same thread the remoting message is processed on, to save the overhead of generating extra threads.
@PaulHigin Thanks for the previous answer. Adding an option to Start-Job
would definitely help.
Could you elaborate a little about the overhead with using an extra thread for remote sessions? Is it a <1sec delayed session start? Higher memory usage?
Or maybe easier, why the default thread for remote processing can't have increased stack size itself?
Prerequisites
Steps to reproduce
Example 1:
Start-Job { function recurse([int]$i) { $i; recurse ($i+1) }; recurse 0 } | Receive-Job -Wait
function recurse([int]$i) { $i; recurse ($i+1) }; recurse 0
Example 2 on Windows: Run the following block directly in Powershell session and then inside a job
Expected behavior
Actual behavior
Error details
No response
Environment data
Visuals
No response