GithubHelp home page GithubHelp logo

Comments (3)

RamblingCookieMonster avatar RamblingCookieMonster commented on August 21, 2024

Ahh, cool idea!

Looking at verbose output, the actual runtime is ~ .08 seconds for each. It looks like the hangup is when we call begininvoke():

$temp.Runspace = $powershell.BeginInvoke()

If I step through manually, I can reproduce this.

#Set things up
    $Throttle = 20
    $ScriptBlock = $ExecutionContext.InvokeCommand.NewScriptBlock("param(`$_, `$parameter)`r`n" + {$_.invoke()}.ToString()) 
    $object = {start-sleep -Seconds 10; "boo!"}

    $sessionstate = [System.Management.Automation.Runspaces.InitialSessionState]::CreateDefault()
    $runspacepool = [runspacefactory]::CreateRunspacePool(1, $Throttle, $sessionstate, $Host)
    $runspacepool.Open() 

    $powershell = [powershell]::Create()
    [void]$PowerShell.AddScript($ScriptBlock).AddArgument($object).AddArgument($parameter)
    $powershell.RunspacePool = $runspacepool

#I get a delay here...
    $rs = $powershell.BeginInvoke()

from invoke-parallel.

RamblingCookieMonster avatar RamblingCookieMonster commented on August 21, 2024

This is a bit out of my wheelhouse, but this might help identify the root cause:

Measure-command { @({sleep 5; 1}, {sleep 5; 2}, {sleep 5; 3}) | Invoke-Parallel { [scriptblock]::Create( $_ ).invoke() } }

Returns in expected ~ 5 seconds.

Measure-command { @({sleep 5; 1}, {sleep 5; 2}, {sleep 5; 3}) | Invoke-Parallel {  $x = $_.psobject.copy(); $x.invoke() } }

Returns in unexpected ~ 15 seconds.

from invoke-parallel.

vors avatar vors commented on August 21, 2024

@lzybkr comment:
If you call [ScriptBlock]::Create - the script block doesn't know it's runspace.
If you use { } - then it does, and will always run on that runspace.

from invoke-parallel.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.