Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Performance 性能优势-多个PowerShell与后台作业_Performance_Powershell - Fatal编程技术网

Performance 性能优势-多个PowerShell与后台作业

Performance 性能优势-多个PowerShell与后台作业,performance,powershell,Performance,Powershell,我做了一个程序,同时启动多个后台工作。目前,该过程需要几个小时(有时3小时,有时多达6小时,具体取决于文件和大小) 重写代码有什么好处吗?这样它就不会使用后台作业启动同一个Shell中的所有进程,而是为每个进程启动PowerShell?或者两者之间没有什么大的区别 $handler_button1_Click= { if ($checkBox1.Checked) { Try{ $job1 = start-jobhere {& C:\Users\moser

我做了一个程序,同时启动多个后台工作。目前,该过程需要几个小时(有时3小时,有时多达6小时,具体取决于文件和大小)

重写代码有什么好处吗?这样它就不会使用后台作业启动同一个Shell中的所有进程,而是为每个进程启动PowerShell?或者两者之间没有什么大的区别

$handler_button1_Click= 
{
    if ($checkBox1.Checked)    { 
    Try{
    $job1 = start-jobhere {& C:\Users\mosermich\Desktop\Extractor\Ressources\adp_staging.bat} -Name "ADP-DATA"
    $listBox1.Items.Add("ADP-staging läuft...")
    }catch [System.Exception]{}
    }

    if ($checkBox2.Checked)    { 
    Try{ 
    $job2 = start-jobhere {& C:\Users\mosermich\Desktop\Extractor\Ressources\kdp_staging.bat} -Name "KDP-DATA"
    $listBox1.Items.Add("KDP-staging läuft...")
    }catch [System.Exception]{}
    }

    if ($checkBox3.Checked)    { 
    Try{ 
    $job3 = start-jobhere { & C:\Users\mosermich\Desktop\Extractor\Ressources\mdp_staging.bat} -Name "MDP-DATA"
    $listBox1.Items.Add("MDP-staging läuft...")
    }catch [System.Exception]{}
    }

    if ($checkBox4.Checked)    { 
    Try{ 
    $job4 = start-jobhere { & C:\Users\mosermich\Desktop\Extractor\Ressources\zdlb_staging.bat} -Name "ZDL-B-DATA"
    $listBox1.Items.Add("ZDLB-staging läuft...")
    }catch [System.Exception]{}
    }

    if ($checkBox5.Checked)    { 
    Try{ 
    $job5 = start-jobhere { & C:\Users\mosermich\Desktop\Extractor\Ressources\zdls_staging.bat} -Name "ZDL-S-DATA"
    $listBox1.Items.Add("ZDLS-staging läuft...")
    }catch [System.Exception]{}
    }

    if ($checkBox6.Checked)    { 
    Try{ 
    $job6 = start-jobhere { & C:\Users\mosermich\Desktop\Extractor\Ressources\zub_staging.bat} -Name "ZUBOFI-DATA"
    $listBox1.Items.Add("ZUBOFI-staging läuft...")
    }catch [System.Exception]{}
    }

    if ($checkBox7.Checked)    { 
    Try{ 
    $job7 = start-jobhere { & C:\Users\mosermich\Desktop\Extractor\Ressources\adp_staging_error.bat} -Name "ADP-ERR"
    $listBox1.Items.Add("ADP-Error-staging läuft...")
    }catch [System.Exception]{}
    }

    if ($checkBox8.Checked)    { 
    Try{  
    $job8 = start-jobhere { & C:\Users\mosermich\Desktop\Extractor\Ressources\kdp_staging_error.bat} -Name "KDP-ERR"
    $listBox1.Items.Add("KDP-Error-staging läuft...")
    }catch [System.Exception]{}
    }

    if ($checkBox9.Checked)    { 
    Try{  
    $job9 = start-jobhere { & C:\Users\mosermich\Desktop\Extractor\Ressources\mdp_staging_error.bat} -Name "MDP-ERR"
    $listBox1.Items.Add("MDP-Error-staging läuft...")
    }catch [System.Exception]{}
    }

    if ($checkBox10.Checked)    { 
    Try{  
    $job10 = start-jobhere { & C:\Users\mosermich\Desktop\Extractor\Ressources\zdlb_staging_error.bat} -Name "ZDL-B-ERR"
    $listBox1.Items.Add("ZDL-B-Error-staging läuft...")
    }catch [System.Exception]{}
    }

    if ($checkBox11.Checked)    { 
    Try{  
    $job11 = start-jobhere { & C:\Users\mosermich\Desktop\Extractor\Ressources\zdls_staging_error.bat} -Name "ZDL-S-ERR"
    $listBox1.Items.Add("ZDL-S-Error-staging läuft...")
    }catch [System.Exception]{}
    }

    if ($checkBox12.Checked)    { 
    Try{  
    $job12 = start-jobhere { & C:\Users\mosermich\Desktop\Extractor\Ressources\zub_staging_error.bat} -Name "ZUBOFI-ERR"
    $listBox1.Items.Add("ZUBOFI-Error-staging läuft...")
    }catch [System.Exception]{}
    }

    if ($listBox1.Items.Count -eq 0) {
    $listBox1.Items.Add("No-Data!") 
    }

    Get-Job | Wait-Job | Where State -eq "Running"


    $listBox1.Items.Add("All Jobs have been succesfully finished")

    }else{}
(我猜)您不会看到太大的区别,因为使用
开始作业
生成后台作业或使用
-AsJob
调用Comdles实际上会创建PowerShell可执行文件的新实例-您可以通过任务管理器/process explorer等看到这一点


如果您同时创建许多后台作业,那么与实际工作负载相比,创建和调度这些作业的开销可能相当大。在这种情况下,您可能希望了解更轻量级的PowerShell运行空间。特别是,您可以看看优秀的模块,该模块使运行空间的使用看起来像是“常规”PowerShell作业。它还包括对任务进行排队的功能,这样您就不会同时执行1000个任务,而是在任何给定时间仅执行8个任务。

简短回答:这取决于具体情况。但可能不是。如果您想提高性能,您必须确定瓶颈e。G使用哪个资源。由于您暗示运行时取决于文件和大小,因此我建议查看您的脚本。可能您多次呼叫Get ChildItem。你的脚本在做什么?我在问题中提供了代码。它基本上调用不同的.bat文件,这些文件中写入了SQL代码,以从Oracle数据库表中提取数据。(我知道这段代码可能写得更短,但我最近才开始使用PowerShell。是的,您可以实现得更短;-)。然而,由于您是从oracle数据库中提取数据,您的瓶颈很可能是IO(db/文件)。您现在应该检查是否可以改进SQL…我将仔细查看我的SQL查询,感谢您的帮助。:)酷!我要看一看你建议的那些发型。非常感谢。