jsoliveir/cpu-process-tuner
ProcessTunerCLI is a tool that manages CPU priorities for processes running in a given operating system. The tool can be useful when there is a need of restricting CPUs (Cores) for processes in order to keep the operating system responsive.
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:
-
Limiting CPU cores for running processes
-
Managing CPU priorities for process that you use often
-
Improving the operating system responsiveness
A problem scenario ...
-
Given you're working with a computer machine...
-
The machine is running applications and services backed by processes ...
-
You figure out that a specifc process, for some reason, is consumming 100% of your total CPU power ...
-
You concluded that it is "burning" the machine resources and is the operating system is completly hanged.
What would you do?
-
The first approach would be to find and kill the process but, sometimes that cannot be done.
-
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 ProcessTunerImport
Import-Module ProcessTuner -ForceList
Get-Module ProcessTunerUpdate
the cleanest way
Uninstall-Module ProcessTuner -AllVersions
Remove-Module ProcessTuner
Install-Module ProcessTuner
Import-Module ProcessTuneror
Update-Module ProcessTuner -Force
Import-Module ProcessTunerCreate 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: 255CPU 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-ProcessRulesselector priority affinity
-------- -------- --------
chrome RealTime CPU0, CPU1, CPU2
code High All
.* Normal All
Apply the rules once (testing)
Get-ProcessRules | Set-ProcessRulesStart auto management (attached)
Start-ProcessTuner Start auto management (background / dettached)
Start-ProcessTuner -BackgroundExtra args
Start-ProcessTuner `
-RulesPath rules/example.yml `
-Interval 10 `
-BackgroundCheck the logs (background)
Get-Job ProcessTuner | Receive-Job -KeepAttach to the job (realtime)
Get-Job ProcessTuner | Receive-Job -WaitHide/Minimize current the console window
Set-WindowStyle -Style MINIMIZESet-WindowStyle -Style MAXIMIZESet-WindowStyle -Style SHOWDEFAULTAllowed 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