header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Getting the most from Powershell...
Last Post 30 Jun 2010 04:53 AM by George Howarth. 5 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages Not Resolved
JamesUser is Offline
Basic Member
Basic Member
Posts:374
Avatar

--
29 Jun 2010 05:35 AM
    Hello,

    We have a terminal server box which does not do anything but allow people  to logon and do basic tasks with AD and Exchange...

    Its only used rarely for things like password resets or adding aliases to users within exchange. However when we come to do bulk stuff within AD we use scripts and run them on the TS box so we dont cripple the actual servers with other load.

    I am wondering that is there a way to dedicate the two processors to powershell.exe while it runs certain scripts or just any script?

    I realise its probably going to be a no but hey worth asking....

    Many Thanks

    James
    George HowarthUser is Offline
    Basic Member
    Basic Member
    Posts:360
    Avatar

    --
    29 Jun 2010 06:52 AM
    Are you looking to do this programatically?
    PoSherLifeUser is Offline
    Basic Member
    Basic Member
    Posts:364
    Avatar

    --
    29 Jun 2010 07:16 AM
    When at first you don't succeed Step-Into

    http://theposherlife.blogspot.com
    http://www.jandctravels.com

    JamesUser is Offline
    Basic Member
    Basic Member
    Posts:374
    Avatar

    --
    29 Jun 2010 07:54 AM
    Well I am looking at doing it anyway its possible if it even is! :)

    I will check out the link now.

    Many Thanks for your replies!

    James
    JamesUser is Offline
    Basic Member
    Basic Member
    Posts:374
    Avatar

    --
    29 Jun 2010 08:00 AM
    Hello,

    From the link... I am not too sure what its saying about the following:

    $calcSet = Get-Process -ProcessName "calc"
    foreach ($calc in $calcSet) {$calc.ProcessorAffinity=0xF}

    Would that allow calc.exe to use the two processors in the box at the same time for more processing power?

    So for example if we have 2x 1GHZ processors instead of using 1GHZ it would use 2GHZ with the use of the two processors?

    Many Thanks

    James
    George HowarthUser is Offline
    Basic Member
    Basic Member
    Posts:360
    Avatar

    --
    30 Jun 2010 04:53 AM

    I think you have the idea of processor affinity wrong here. He's a snippet from the MSDN:


    Assign processor affinity to better use CPU caching

    To efficiently use CPU caches on multiprocessor servers, you can configure application pools to establish affinity between worker processes and the processors. Processor affinity forces worker processes to run on a specific microprocessor or CPU, and applies to all worker processes serving a particular application pool. You can also use processor affinity with Web gardens that run on multiprocessor computers where clusters of CPUs are dedicated to specific application pools.

    Controlling processor affinity can improve performance by reducing the number of processor cache flushes as threads move from one processor to another. For example, you might be able to reduce cache flushes for dedicated servers by assigning processor affinity. However, the performance trade-off is that dedicating a program to a particular processor might prevent other program threads from migrating to the least-busy processor.


    By default, a process' affinity is set to all available CPUs, so if you dedicate a particular CPU to a particular potentially-complex process, can you improve performance because the CPU cache is not reset as often for that process as it would be if its threads were permitted to move from one core to another.

    If you run this script in ISE, you will notice that the affinity for the powershell_ise.exe process is set to CPU01 (assuming you have a multi-core processor). You will also notice that if you spawn new instances of powershell.exe, the affinities for those processes are also set to CPU01:

    function Main
    {
        Wait-Event -SourceIdentifier ManagementEventWatcher.EventArrived
           
        Main
    }

    $type = @"
    using System;

    [Flags]
    public enum CpuCores
    {
        Zero = 1,
        One,
        Two,
        Three,
        Four,
        Five,
        Six,
        Seven
    }
    "@

    Add-Type -TypeDefinition $type

    $processorAffinity = [IntPtr][Int32]([CpuCores]::One) # Set your processor affinity here

    [System.Diagnostics.Process]::GetCurrentProcess().ProcessorAffinity = $processorAffinity

    $eventClassName = "__InstanceCreationEvent"
    $withinInterval = New-Timespan -Seconds 1
    $condition = "TargetInstance ISA 'Win32_Process' AND TargetInstance.Name='powershell.exe'"

    $query = New-Object System.Management.WqlEventQuery -ArgumentList $eventClassName, $withinInterval, $condition

    $processWatcher = New-Object System.Management.ManagementEventWatcher -ArgumentList $query

    Register-ObjectEvent -InputObject $processWatcher -EventName EventArrived -SourceIdentifier ManagementEventWatcher.EventArrived -Action {
        param (
            [System.Object]$sender,
            [System.Management.EventArrivedEventArgs]$e
        )

        New-Event -SourceIdentifier PowerShellProcess.Created -Sender $sender -EventArguments $e.NewEvent.TargetInstance
    } | Out-Null

    Register-EngineEvent -SourceIdentifier PowerShellProcess.Created -Action {
        param (
            [System.Object]$sender
        )
       
        $process = Get-Process -Id $sender.ProcessId
        $process.ProcessorAffinity = $processorAffinity
    } | Out-Null

    Main

    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer