Skip to content

Latest commit

 

History

History
244 lines (158 loc) · 5.15 KB

ReadMe.md

File metadata and controls

244 lines (158 loc) · 5.15 KB

Publish

What the Process Tuner is

Powershell 5.0+ | Powershell Core 7.0+

ProcessTuner is a tool that manages CPU affinities and priorites for processes running in a given operating system.

It basically stands for:

  1. Limiting CPU cores for running processes

  2. Managing CPU priorities for process that you use often

  3. Improving the operating system responsiveness

A problem scenario ...

  1. Given you're working with a computer machine...

  2. The machine is running applications and services backed by processes ...

  3. You figure out that a specifc process, for some reason, is consumming 100% of your total CPU power ...

  4. You concluded that it is "burning" the machine resources and is the operating system is completly hanged.

What would you do?

  1. The first approach would be to find and kill the process but, sometimes that cannot be done.

  2. If the process is an Antivirus, an application running in a server you might need it running and in this case, would be really good if we could control CPU resources (priorities) for that given process.

ProcessTuner allows to set CPU affinities/priorities for processes running the the operating system. That means that you can isolate processes in specific CPU cores, making them slower, but letting the operating system responsive enough to work on more important tasks.

For the problematic scenario above, you could use this tool to create a Rule for that given process.

You would set the CPU affinity to [CPU1] and priority to [Idle]. That means that 100% of CPU power for that process will be only a small portion of your total CPU capacity.

The process will become slower but the other applications including the operating system will recover the responsiveness. :)

How to use it

Install

Install-Module ProcessTuner

Import

Import-Module ProcessTuner -Force

List

Get-Module ProcessTuner

Update

the cleanest way

Uninstall-Module ProcessTuner -AllVersions
Remove-Module ProcessTuner
Install-Module ProcessTuner
Import-Module ProcessTuner

or

Update-Module ProcessTuner -Force
Import-Module ProcessTuner

Create rules

New-ProcessRule `
  -Selector /system32 `
  -Priority High

New-ProcessRule `
   -Affinity CPU0,CPU1,CPU2 `
   -Priority BelowNormal `
   -Selector notepad  

New-ProcessRule `
   -Affinity CPU5,CPU6,CPU7 `
   -Priority AboveNormal `
   -Selector chrome  

Remove rules

Remove-ProcessRule `
   -Selector /system32

Remove-ProcessRule `
   -Priority High

Remove-ProcessRule `
   -Selector /system32 `
   -Affinity CPU0,CPU2  

Manage Rules thru the config file

Start-Process $(Get-ProcessConfigFile)

or

code $(Get-ProcessConfigFile)

Config file structure

rules:
- selector: chrome    # process or path (regex)
  priority: 2         # priority value 
  affinity: 3         # affinity mask
  
- selector: notepad
  priority: 2
  affinity: 255

CPU priority values:

/~https://github.com/jsoliveir/process-cpu-tuner/blob/master/src/Enum/CpuPriority.ps1

CPU affinity mask values:

/~https://github.com/jsoliveir/process-cpu-tuner/blob/master/src/Enum/CpuAffinity.ps1

CPU affinity mask calculator:

https://bitsum.com/tools/cpu-affinity-calculator/

Check existing rules

Get-ProcessRules
selector priority         affinity
-------- --------         --------
chrome   RealTime CPU0, CPU1, CPU2
code         High              All
.*         Normal              All

Apply the rules once (testing)

Get-ProcessRules | Set-ProcessRules

Start auto management (attached)

Start-ProcessTuner 

Start auto management (background / dettached)

Start-ProcessTuner -Background

Extra args

Start-ProcessTuner `
    -RulesPath rules/example.yml `
    -Interval 10 `
    -Background

Check the logs (background)

Get-Job ProcessTuner | Receive-Job -Keep

Attach to the job (realtime)

Get-Job ProcessTuner | Receive-Job -Wait

Hide/Minimize current the console window

Set-WindowStyle -Style MINIMIZE
Set-WindowStyle -Style MAXIMIZE
Set-WindowStyle -Style SHOWDEFAULT

Allowed Window Styles:

'FORCEMINIMIZE', 'HIDE', 'MAXIMIZE', 'MINIMIZE', 'RESTORE', 
'SHOW', 'SHOWDEFAULT', 'SHOWMAXIMIZED', 'SHOWMINIMIZED', 
'SHOWMINNOACTIVE', 'SHOWNA', 'SHOWNOACTIVATE', 'SHOWNORMAL'

Configurations

By default ProcessTuner looks for a file named by rules.yml in the current working directory.

If any configuration file could not be found ProcessTuner will look for it in the parent directories.

If the configuration is still not found the one existing in the $HOME will be used.

To see what file is being using run the following command:

Get the current config file path

 Get-ProcessConfigFile