Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Limit script cpu

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,2544
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Limit script cpu
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Limit script cpu - 4/1/2005 8:32:32 AM   
  wsheeUT

 

Posts: 19
Score: 0
Joined: 3/21/2005
From:
Status: offline
Is there a way to deprioritize a vbs script ? I need to put my script on a production machine, but sometimes it will spike and use all the cpu for a moment, and I was told that my script was no go unless I can rail it down. Is there a win version of unix's nice ? Thanks
 
 
Post #: 1
 
 Re: Limit script cpu - 4/1/2005 9:12:31 AM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
You can run the script using the start command, eg: start /BELOWNORMAL <command_to_run>

Alternative, you can also use vbs itself to control the priority; however, I'm not sure if you can't control its own priority. I believe you can do it though.

(in reply to wsheeUT)
 
 
Post #: 2
 
 Re: Limit script cpu - 4/1/2005 10:10:56 AM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
The following code will set priority level to below normal. The trick is to determine which process that you want to change the priority for. If you have multiple scripts running at the same time, this could be a problem. But it should get you started.

====================================================================================
set wmi = GetObject("WinMgmts:{ImpersonationLevel=Impersonate}!//./root/cimv2")
Set processes = wmi.ExecQuery("SELECT * FROM Win32_Process WHERE Name='cscript.exe'")
For Each process In processes
process.setpriority 16384
Next

(in reply to wsheeUT)
 
 
Post #: 3
 
 Re: Limit script cpu - 4/1/2005 10:17:14 AM   
  wsheeUT

 

Posts: 19
Score: 0
Joined: 3/21/2005
From:
Status: offline
quote:
set wmi = GetObject("WinMgmts:{ImpersonationLevel=Impersonate}!//./root/cimv2")
Set processes = wmi.ExecQuery("SELECT * FROM Win32_Process WHERE Name='funky1.exe.exe'")
For Each process In processes
process.setpriority 16384
Next




So if I copy cscript.exe to funky1.exe, run my vbs script
funky1 prog.vbs

I would then run this separately to deprioritize ?

Thanks

(in reply to wsheeUT)
 
 
Post #: 4
 
 Re: Limit script cpu - 4/1/2005 10:24:51 AM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
You could say that. When you run that script, it will look for a process with name equals to cscript.exe. If it is found, it will lower its process priority. Also, I noticed a typo above "funky1.exe.exe".

That sounds like a good idea to distinguish between different scripts running simultaneously though.

(in reply to wsheeUT)
 
 
Post #: 5
 
 Re: Limit script cpu - 4/2/2005 4:58:21 AM   
  didorno

 

Posts: 361
Score: 0
Joined: 2/12/2005
From:
Status: offline
That is a nice solution from you both.
My 1st thought was puting pauses (wscript.sleep)
in the script at busy places. Does that make sense ?

(in reply to wsheeUT)
 
 
Post #: 6
 
 Re: Limit script cpu - 4/2/2005 9:57:38 AM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
There are differences between use wscript.sleep to pause the entire script (nearly no CPU usage) and lower the process priority of the script. Wscript.sleep will cause the script to stop executing completely. If you stop the script at "busy" places, it is not "busy" anymore. However, when the script resumes running again, it would become busy again.

The idea of modifying the process priority is to control the amount of CPU time allocating to a specific process. By default, all process (except a few system process which has much higher priority) receives an equal amount of CPU time (CPU execution cycles) and thus shared the CPU power equally. When one process consumes more CPU cycles than others, such as when you use CPU intensitive applications or play games, others will lose their share of CPU cycles and appear slow in response time or even to an halt. While I'm not certain what causeed his script to use large amount of CPU cycles, lowering the priority of the script would make other processes running more smoothly.

(in reply to wsheeUT)
 
 
Post #: 7
 
 Re: Limit script cpu - 4/3/2005 4:53:57 AM   
  didorno

 

Posts: 361
Score: 0
Joined: 2/12/2005
From:
Status: offline
Clear explanation Token !
Thank you

(in reply to wsheeUT)
 
 
Post #: 8
 
 Re: Limit script cpu - 4/3/2005 11:39:46 AM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline

(in reply to wsheeUT)
 
 
Post #: 9
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Limit script cpu Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts