Forcing a workstation to run slower sometimes - xharbour
This is a discussion on Forcing a workstation to run slower sometimes - xharbour ; Here's a question I never thought I'd want to ask:
We run a LAN. At any given instant, 4 or 5 people will be doing
something that uses 1-2% of the server's CPU. Certain jobs, such as
looping down through ...
-
Forcing a workstation to run slower sometimes
Here's a question I never thought I'd want to ask:
We run a LAN. At any given instant, 4 or 5 people will be doing
something that uses 1-2% of the server's CPU. Certain jobs, such as
looping down through many records, may cause that to jump to 7-12% for a
period of time. When that happens everyone else slows down.
Is there any way, other than inkey(0.01) on every record, that I can
slow down - slightly - a particular section of code.
inkey() doesn't seem to work with any number smaller than 0.01, and
that's a little too slow. Inkey(0.0075) just stops altogether as if I
had used inkey(0)
Thanks
-
Re: Forcing a workstation to run slower sometimes
Just an idea:
local nRest:=0, nMaxRest:=500
.....
do while .......
if nRest >= nMaxRest
nRest:=0
SecondsSleep( 0.01 )
else
nRest++
endif
.......
enddo
Ella
"Tim Jacob" <tjacob@nospam.jollyfarmer.com> wrote in message
news:49106d51$0$5460$9a566e8b@news.aliant.net...
> Here's a question I never thought I'd want to ask:
>
> We run a LAN. At any given instant, 4 or 5 people will be doing something
> that uses 1-2% of the server's CPU. Certain jobs, such as looping down
> through many records, may cause that to jump to 7-12% for a period of
> time. When that happens everyone else slows down.
>
> Is there any way, other than inkey(0.01) on every record, that I can slow
> down - slightly - a particular section of code.
>
> inkey() doesn't seem to work with any number smaller than 0.01, and that's
> a little too slow. Inkey(0.0075) just stops altogether as if I had used
> inkey(0)
>
> Thanks
-
Re: Forcing a workstation to run slower sometimes
Dear Tim Jacob:
"Tim Jacob" <tjacob@nospam.jollyfarmer.com> wrote in message
news:49106d51$0$5460$9a566e8b@news.aliant.net...
> Is there any way, other than inkey(0.01) on every
> record, that I can slow down - slightly - a particular
> section of code.
Untested, call this with the number of seconds you want to delay.
Don't feed it zero since smoke will come out without guard code.
If you call it with 0.005 seconds, it will call inkey with 0.01
every other invocation. If you call it with 0.001 seconds it
will call inkey with 0.01 on every 10th invocation. I don't know
how to retain values for nBits and nHits between invocations, so
if someone wants to *repair* this and post it here...
local nBits := 0 && does this work out here?
local nHits := 0
function MyInkey
parameters nSeconds
if 0.01 / nSeconds <= 1
inkey( nSeconds)
else
if nBits <> int( 0.01 / nSeconds + 0.5)
nBits := int( 0.01 / nSeconds + 0.5)
nHits := 0
inkey( 0.01 )
else
++nHits
if nHits = nBits
nHits := 0
inkey(0.01)
endif
endif
endif
return .T.
David A. Smith
-
Re: Forcing a workstation to run slower sometimes
N:dlzc D:aol T:com (dlzc) wrote:
> Dear Tim Jacob:
>
> "Tim Jacob" <tjacob@nospam.jollyfarmer.com> wrote in message
> news:49106d51$0$5460$9a566e8b@news.aliant.net...
>
>> Is there any way, other than inkey(0.01) on every
>> record, that I can slow down - slightly - a particular
>> section of code.
>
> Untested, call this with the number of seconds you want to delay.
> Don't feed it zero since smoke will come out without guard code.
> If you call it with 0.005 seconds, it will call inkey with 0.01
> every other invocation. If you call it with 0.001 seconds it
> will call inkey with 0.01 on every 10th invocation. I don't know
> how to retain values for nBits and nHits between invocations, so
> if someone wants to *repair* this and post it here...
>
> local nBits := 0 && does this work out here?
> local nHits := 0
> function MyInkey
> parameters nSeconds
> if 0.01 / nSeconds <= 1
> inkey( nSeconds)
> else
> if nBits <> int( 0.01 / nSeconds + 0.5)
> nBits := int( 0.01 / nSeconds + 0.5)
> nHits := 0
> inkey( 0.01 )
> else
> ++nHits
> if nHits = nBits
> nHits := 0
> inkey(0.01)
> endif
> endif
> endif
> return .T.
>
> David A. Smith
>
>
Here's my slightly modified version which does appear to work.
Declaring those 2 variables as static makes them retain their values.
Putting in a check for a zero value at the beginning prevents the crash
and burn.
Thanks a lot.
static ;
nBits := 0, ;
nHits := 0
FUNCTION MyInkey(nSeconds)
If nSeconds <> 0
if 0.01 / nSeconds <= 1
inkey( nSeconds)
else
if nBits <> int( 0.01 / nSeconds + 0.5)
nBits := int( 0.01 / nSeconds + 0.5)
nHits := 0
inkey( 0.01 )
else
++nHits
if nHits = nBits
nHits := 0
inkey(0.01)
endif
endif
endif
endif
return .T.
-
Re: Forcing a workstation to run slower sometimes
Ella Stern wrote:
> Just an idea:
>
> local nRest:=0, nMaxRest:=500
> ....
> do while .......
> if nRest >= nMaxRest
> nRest:=0
> SecondsSleep( 0.01 )
> else
> nRest++
> endif
> ......
> enddo
>
> Ella
>
> "Tim Jacob" <tjacob@nospam.jollyfarmer.com> wrote in message
> news:49106d51$0$5460$9a566e8b@news.aliant.net...
>> Here's a question I never thought I'd want to ask:
>>
>> We run a LAN. At any given instant, 4 or 5 people will be doing something
>> that uses 1-2% of the server's CPU. Certain jobs, such as looping down
>> through many records, may cause that to jump to 7-12% for a period of
>> time. When that happens everyone else slows down.
>>
>> Is there any way, other than inkey(0.01) on every record, that I can slow
>> down - slightly - a particular section of code.
>>
>> inkey() doesn't seem to work with any number smaller than 0.01, and that's
>> a little too slow. Inkey(0.0075) just stops altogether as if I had used
>> inkey(0)
>>
>> Thanks
>
>
Thanks Ella,
I prefer David's solution, as it gives me the ability the more easily
adjust the timing.