Page 1 of 2 12>
Topic Options
#84940 - 2002-01-24 02:44 AM How do I throttle back the CPU on a script?
cj Offline
MM club member
*****

Registered: 2000-04-06
Posts: 1102
Loc: Brisbane, Australia
Here is the code:

code:

$dirs=dirplus("\\@wksta\users$$", "*.*", 1, 0)

for each $sFilename in $dirs

; $sFilename=$oDirFile.ReadLine() ; read filename from list
$oFile=$oFS.GetFile($sFilename) ; get time/date of this file
if not @error
$sDate=split($oFile.DateLastAccessed(), " ")[0] ; capture the date part of this time/date info
$saDate=split($sDate, "/") ; split the date into it's parts for checker
if DateMath(@date, $saDate[2]+"/"+$saDate[1]+"/"+$saDate[0])>$iCheckAge ; check date against today
$sUser=split($sFilename, "\")[4] ; capture the user name from the path
$sFilename="H:\"+right($sFilename, len($sFilename)-len($sUser)-17) ; capture the filename
$sDate "," $sUser "," $sFilename ? ; display to screen > csv file
endif
endif
next


Here is the DIRPLUS UDF

The UDF averages 50% cpu then when the For Each kicks in, bang 100% flat line. I could put a sleep 1 in there, sure, but when are looking at 115000 array elements, that would make this 2 hour script take an extra 32 hours!

I would be happy to make it take 4 hours if it would keep to 50% CPU.

Any ideas?

cj

Top
#84941 - 2002-01-24 08:27 AM Re: How do I throttle back the CPU on a script?
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Hey ceej,

one could if one could delay his loops for just an msec (enough to keep to keep nowadays CPUs stress-free, on the other side short enough to be acceptable)

Forget about udf delays as they are a CPU time killer , BUT :

Ruud promised to enable the good old SLEEP command to accept miliseconds ...

here is an excerpt from one of his last mails (hope you don't mind Ruud ?)

quote:

As for delay(): this is on the list for the next update after 4.02 (if all goes well, Sleep should be able to accept a floating point number, allowing you guys to sleep (your scripts ;-) for as little as a millisecond... ;-)

J.

_________________________



Top
#84942 - 2002-01-24 08:41 AM Re: How do I throttle back the CPU on a script?
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
115000 array elements ????

WOW .. that would result in a delay of about 2 minutes

J.

_________________________



Top
#84943 - 2002-01-24 02:04 PM Re: How do I throttle back the CPU on a script?
Alex.H Offline
Seasoned Scripter

Registered: 2001-04-10
Posts: 406
Loc: France
cj,
maybe try to run this one with :
start /low /wait Kix32.exe ....
Even if cpu is to the max, other process will got everything they need
_________________________
? getobject(Kixtart.org.Signature)

Top
#84944 - 2002-01-24 02:46 PM Re: How do I throttle back the CPU on a script?
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
I agree with alex...
Why cpu should be idle when script does need the power. when process priority is low you let other processes the chance to take their bite from the cake.
_________________________
!

download KiXnet

Top
#84945 - 2002-01-24 02:58 PM Re: How do I throttle back the CPU on a script?
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
NAHHH,

running 2 or 3 scripts simultaneously but having other applications in foreground (Yes lads and lassies, this is sometimes inevitable if one uses KiX for administrative purposes !) shouldn't by default eat up CPU in loops !!!

But hey, the step from having SLEEP accepting floating point numbers to real floating point math support (double precision ? ) isn't that big , eh Ruud ??

J.

_________________________



Top
#84946 - 2002-01-24 03:12 PM Re: How do I throttle back the CPU on a script?
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
In CJs example reducing the priority of the process is probably the best solution.

However, sometimes you do want to (politely) give up CPU cycles because you don't need them. There are two reasons for this:
1) You are waiting on an event
I've got a set of UDF's for enhanced keyboard input. There is a loop which waits for a keypress, and as there is no way of giving up CPU cycles this incredibly tight little loop uses huge amounts of CPU it doesn't need. This is bad enough on a single user machine, but can be fatal on a multi-user platform like Windows Terminal Server.
2) Process scheduling
I don't know about MS Windows so much, but operating systems like Unix have a scheduler to deal with running process. The timeslice given to a running process varies depending on how busy the process has been in the past. The scheduler (not unreasonably) will give CPU hungry processes a larger processor timeslice, to the detriment of other processes, i.e. their share of the resources will degrade.

For this reason it used to be common for programmers to give up their timeslice (quorum? - can't remember) in batch type programs to ensure that the program would not hog the CPU.

One way to guarantee sleeping in milliseconds is to have your friends staying over with their new baby...

Top
#84947 - 2002-01-24 03:13 PM Re: How do I throttle back the CPU on a script?
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
jpols, open up word/access/excel and leave it in the background without any tasks.
check out cpu and you can see that it's eaten totally by these not so usefull processes.
eating idle power is the thing that comes to my mind when speaking of multiprocessing.
_________________________
!

download KiXnet

Top
#84948 - 2002-01-25 02:17 AM Re: How do I throttle back the CPU on a script?
cj Offline
MM club member
*****

Registered: 2000-04-06
Posts: 1102
Loc: Brisbane, Australia
Thanks for the ideas! I will try the START one and let you know how it goes. We have monitoring tools on these servers that alert us if a process eats large CPU for an extended period. I have put kix.exe in the "exclusions list" for the time being so alarms are not raised, but this means the script could go nova and we would not know until the users go "hey, what's happening?!"

cj

Top
#84949 - 2002-01-25 03:42 AM Re: How do I throttle back the CPU on a script?
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
I may be wrong... but did not someone come up with a mil sec delay in a DLL a while back?

I think Shawn did when I was making that tetris kix script....

just a thought.
Bryce

Top
#84950 - 2002-01-25 08:14 AM Re: How do I throttle back the CPU on a script?
cj Offline
MM club member
*****

Registered: 2000-04-06
Posts: 1102
Loc: Brisbane, Australia
I think jpols made a Millisecond delay routine, but it was CPU intensive.

cj

Top
#84951 - 2002-01-25 11:04 AM Re: How do I throttle back the CPU on a script?
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
I quess bryce ment something like: http://kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic&f=2&t=002030

as, in bgi.ticks()

but don't know if this is what he really ment...
but as I see it, this could be easily included in kix-dll's

cheers,

_________________________
!

download KiXnet

Top
#84952 - 2002-01-25 11:11 AM Re: How do I throttle back the CPU on a script?
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
... it was :

$kixlib.sleep("1") or
$Kixbgi.delay(1)

within one of the next releases of KiXtart I assume it to be :

SLEEP 0.001

J.

_________________________



Top
#84953 - 2002-01-25 11:28 AM Re: How do I throttle back the CPU on a script?
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
or will it be mSleep()
then would not have need for execution in script where the sleep needs to be calculated first...
_________________________
!

download KiXnet

Top
#84954 - 2002-01-25 11:53 AM Re: How do I throttle back the CPU on a script?
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
just tried with:
rundll32.exe kernel32.dll,Sleep

got an application exception on win98-box, but this func is there according to
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/prothred_7j xs.asp
maybe I just don't know how to use this feature...

_________________________
!

download KiXnet

Top
#84955 - 2002-01-25 01:49 PM Re: How do I throttle back the CPU on a script?
Alex.H Offline
Seasoned Scripter

Registered: 2001-04-10
Posts: 406
Loc: France
Lonkero,
This one is an API command, and so can't be called from command line.
On the other hand, maybe it's the one Ruud use actually, but with dwMilliseconds * 1000
_________________________
? getobject(Kixtart.org.Signature)

Top
#84956 - 2002-01-28 03:20 PM Re: How do I throttle back the CPU on a script?
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
alex, I know what you mean that it can't be called from commandline.
but api's can be called anyway.
the problem is just that from commandline I can't give it parameter it needs.

as, "rundll32.exe user.exe,ExitWindows" is a api call, isn't it?

_________________________
!

download KiXnet

Top
#84957 - 2002-02-05 09:23 AM Re: How do I throttle back the CPU on a script?
cj Offline
MM club member
*****

Registered: 2000-04-06
Posts: 1102
Loc: Brisbane, Australia
I tried START /LOW and START /LOW /WAIT and both don't work - in that the CPU still hits 100% and stays there.

cj

Top
#84958 - 2002-02-05 10:22 AM Re: How do I throttle back the CPU on a script?
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
CJ,
Don't forget that you are adjusting the priority of the task, not how much CPU it uses.

All it means is that higher priority tasks will get either a larger timeslice of CPU activity, or (more properly) get more frequent timeslices. For example this might mean that for each time a low priority job gets queued to run on your CPU a medium priority job will get run twice, and a high priority job three times.

Your CPU should *never* be idle if there is work to be done. I'll stop now, I'm beginning to sound like my mother

Top
#84959 - 2002-02-05 01:57 PM Re: How do I throttle back the CPU on a script?
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
Lonkero,

It is a pseudo API call. Meaning that you are attempting to call a function within a dll from the rundll program.

This link will explain why you can't call it from a command line.

The Win32 Rundll and Rundll32 Interface

Note the line that says:
you can not use these utility programs to call the Win32 API (Application Programming Interface) calls exported from the system DLLs

However, this should be VERY easy to implement within the KIX executable from everything I see on the net.

Hope this helps

[ 05 February 2002: Message edited by: NTDOC ]

Top
Page 1 of 2 12>


Moderator:  Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 476 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.072 seconds in which 0.025 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org