Answer the question
In order to leave comments, you need to log in
How to overcome performance issues?
The problem consists in the following - wrote a script on PS for control of user activity with EDMS. Its essence is that we expect the appearance of EDMS processes on the client machine, after that, on the advice of comrade azarij , using this thing https://wasp.codeplex.com/ , we catch active windows (processes) and take, let's say, certain actions based on some conditions) The problem is that the script "eats a lot" - up to 250MB of OP and up to 90!!! CPU on Piggy (1 core 2GHz 1024MB RAM) and up to 700!!!(wtf?)MB OP and up to 50 CPU on my 10k (4 cores 8GB RAM). This is all of course with a peak load. The question of your own is how you can overcome it (optimize).
I ask you not to scold too much for the code - I met PS 2 months ago, and coded for the last time about 3 years ago)
Main functions:
function Directumchk {
Write-log "Waiting for Directum processes" -type Default
for ($i = 0; (-not (ps | ? { $_.ProcessName -eq $SBRte })) -or (-not ( ps | ? { $_.ProcessName -eq $SBLogon })) ; $i++)
{
sleep 3
}
do {
sleep 1
$SBRtehandle = (ps ($SBRte)).mainwindowhandle
}
until ($SBRtehandle -ne 0)
$global :SBRteID = (ps ($SBRte)).ID
Write-log "Directum processes will be found" -type "Complete"
ActWinStr
}
function ActWinStr {
Write-log "Check user activity" -type Default
for (;;){
$ Answer = $null
if (-not(ps|?{$_.ProcessName -eq $SBRte})){
if (gjb|?{$_.Name -eq "STimer"}){Remove-Job -Name STimer -Force}
Write-log "Directum closed by user" -type "Complete"
Directumchk}
else{
if (([PInvoke .Win32.UserInput]::IdleTime).Minutes -ge $CountTime){
if (gjb|?{$_.Name -eq "STimer"}){Remove-Job -Name STimer -Force}
Write-log "Idle time left" -type "Warning"
$Answer = GUITimer
UserChoice -Answer $Answer
}
else{
$Act = Select-Window -ActiveWindow
if ($Act.ProcessName -eq $SBRte){
if (gjb|?{$_.Name - eq "STimer"}){Remove-Job -Name STimer -Force}
}
else{
$ParentID = gwmi win32_process | ? -FilterScript {$_.ProcessId -eq $Act.ProcessID} | % {$_.parentprocessid}
if ($ParentID -ne $global:SBRteID){
if (gjb|?{$_.Name -eq "STimer"}){
if ($Timer.state -eq "Completed"){
Remove-Job -Name STimer -Force
Write-log "User don't work in Directum" -type "Warning"
$Answer = GUITimer
UserChoice -Answer $Answer
}
}
else{$Timer = Start-Job -Name STimer -ScriptBlock { for ($x = 900;$x -gt 0;$x--){sleep 1}}}
}
else {if (gjb|?{$_.Name -eq "STimer"
Answer the question
In order to leave comments, you need to log in
I never liked jobs and scripts that are constantly running. I understand correctly that the script does its job, and then sleeps for 900 seconds and so on in a circle?
if so, does it immediately survive the memory, or immediately after starting everything is OK, and over time it eats more and more memory?
can run this business on a schedule through the task scheduler? started, did what it needed, turned off.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question