PowerShell Workflow Thread Limit -


i have powershell workflow looks this, except each foo function different:

function foo1 {     "foo1 : {0:hh}:{0:mm}:{0:ss}" -f (get-date)     start-sleep 2 }  function foo2 {     "foo2 : {0:hh}:{0:mm}:{0:ss}" -f (get-date)     start-sleep 2 }  function foo3 {     "foo3 : {0:hh}:{0:mm}:{0:ss}" -f (get-date)     start-sleep 2 }  function foo4 {     "foo4 : {0:hh}:{0:mm}:{0:ss}" -f (get-date)     start-sleep 2 }  function foo5 {     "foo5 : {0:hh}:{0:mm}:{0:ss}" -f (get-date)     start-sleep 2 }  function foo6 {     "foo6 : {0:hh}:{0:mm}:{0:ss}" -f (get-date)     start-sleep 2 }  workflow invoke-workflow {     parallel     {         foo1         foo2         foo3         foo4         foo5         foo6     } }  invoke-workflow 

the output of is:

foo1 : 10:28:43

foo2 : 10:28:43

foo3 : 10:28:44

foo5 : 10:28:44

foo4 : 10:28:44

foo6 : 10:28:46

showing first 5 run immediately, , 6th item has wait 1 of previous items finish.

i see lot of documentation shows how increase number of parallel executions in foreach loop. how increase number of items run in parallel block?

there doesn't appear way increase number of threads used in parallel block, or if there is, it's difficult find. workaround use start-job command. can use

start-job -scriptblock {#do stuff here}

or, if more code want have inline, can have run script:

start-job -filepath "c:\temp\job.ps1" -argumentlist 1

it takes time each job spin up, don't start simultaneously. ran loop run start-job commands , log time started. each job had 30 second sleep wouldn't die (and try force number of jobs running hit limit of threads). results varied somewhat, testing 20 showed able run at least many simultaneously. in results below, started 28 seconds after first ones, remember first ones still running due 30 second sleep. didn't start rapid fire, there 20 running @ once.

#1 started @ 5/29/2015 2:17:25 pm #2 started @ 5/29/2015 2:17:25 pm #3 started @ 5/29/2015 2:17:26 pm #4 started @ 5/29/2015 2:17:26 pm #5 started @ 5/29/2015 2:17:27 pm #7 started @ 5/29/2015 2:17:28 pm #6 started @ 5/29/2015 2:17:28 pm #8 started @ 5/29/2015 2:17:31 pm #9 started @ 5/29/2015 2:17:37 pm #10 started @ 5/29/2015 2:17:47 pm #12 started @ 5/29/2015 2:17:53 pm #13 started @ 5/29/2015 2:17:53 pm #15 started @ 5/29/2015 2:17:53 pm #18 started @ 5/29/2015 2:17:53 pm #11 started @ 5/29/2015 2:17:53 pm #20 started @ 5/29/2015 2:17:53 pm #14 started @ 5/29/2015 2:17:53 pm #16 started @ 5/29/2015 2:17:53 pm #17 started @ 5/29/2015 2:17:53 pm #19 started @ 5/29/2015 2:17:53 pm 

i did run across couple of other methods multi-threading powershell, easiest understand , demonstrate. not best.


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -