Small intervals
Small intervals
Hello everyone,
i need the server to run small intervals for a server side "intelligence". the shorter the time, the fastest would be the reaction time. in my case i would need a 50ms interval, is it possible? I searched the forums and found various topics about this. I tested setInterval but it wont work under 250ms; i read the scheduler can be inited with much shorter time, but still its not intended for "high-frequency" tasks.
Has anyone found a solution or did anything change since nov 2008 when lapo wrote: I am sorry, there's no way to use fractions of a second.
As I mentioned the Scheduler is done for tasks that recur in seconds, so it is not precise to the millisecond. ?
i need the server to run small intervals for a server side "intelligence". the shorter the time, the fastest would be the reaction time. in my case i would need a 50ms interval, is it possible? I searched the forums and found various topics about this. I tested setInterval but it wont work under 250ms; i read the scheduler can be inited with much shorter time, but still its not intended for "high-frequency" tasks.
Has anyone found a solution or did anything change since nov 2008 when lapo wrote: I am sorry, there's no way to use fractions of a second.
As I mentioned the Scheduler is done for tasks that recur in seconds, so it is not precise to the millisecond. ?
i made some tests by setting an interval and tracing the time in the callback.
if i use intervals of 250 or above, i get a regular tracing. example:
callback 250
callback 500
callback 750
etc
if i use intervals under 250 (example 50), i get something like:
callback 60
callback 124
callback 196
callback 255
etc
i was wondering if there is a way to keep it regular even with shorter times
i think i should keep in mind the possibility of an imprecision anyway, considering that the cpu could slow down for some reason and be unable to perform all the intervals
if i use intervals of 250 or above, i get a regular tracing. example:
callback 250
callback 500
callback 750
etc
if i use intervals under 250 (example 50), i get something like:
callback 60
callback 124
callback 196
callback 255
etc
i was wondering if there is a way to keep it regular even with shorter times
i think i should keep in mind the possibility of an imprecision anyway, considering that the cpu could slow down for some reason and be unable to perform all the intervals
I don't think you are measuring time correctly, or there is another problem somewhere. I get perfectly consistent intervals at 10 milliseconds, with very very little fluctuations.
I would suggest using this code to test:
p.s. = beware, at 10ms it will print results veeeery fast 
I would suggest using this code to test:
Code: Select all
thread = null
lastTime = 0
function init()
{
thread = setInterval("myThread", 10)
lastTime = getTimer()
}
function myThread()
{
trace("Interval: " + (getTimer() - lastTime))
lastTime = getTimer()
}have the same problem. i made tests with your code. i dont really know whats happening but maybe someone else does 
interval: response
1-15: 15 16 15 16 16 15 16 16 and repeat (avg 15,625 -> 64 interval/sec)
16: 16 31 16 31 31 and repeat (avg 25 -> 40 interval/sec)
17-31: 31 31 31 32 and repeat (avg 31,25 -> 32 interval/sec)
32: 32 47 46 and repeat (avg 41,66-> 24 interval/sec)
33-46: 46 47 47 47 47 47 47 47 and repeat (avg 46,875-> 21,33 interval/sec)
47: 47 47 47 47 62 and repeat (avg 50-> 20 interval/sec)
48-: 62 63 and repeat (avg 62,5-> 16 interval/sec)
i haven't continued it further but from 125 it's working fine...
i have tried it with 3 computers and got the same results
cpu P4 2,4 GHz, AMD Athlon dual 2,69 GHz, ...
ram 1GB-2GB
os windows xp
sfs 1.6.6
java 1.6.0_13
it's working fine on a
cpu amd athlonII dual 2,1GHz
ram 2GB
os win 7
sfs 1.6.6
java 1.6.0_13
interval: response
1-15: 15 16 15 16 16 15 16 16 and repeat (avg 15,625 -> 64 interval/sec)
16: 16 31 16 31 31 and repeat (avg 25 -> 40 interval/sec)
17-31: 31 31 31 32 and repeat (avg 31,25 -> 32 interval/sec)
32: 32 47 46 and repeat (avg 41,66-> 24 interval/sec)
33-46: 46 47 47 47 47 47 47 47 and repeat (avg 46,875-> 21,33 interval/sec)
47: 47 47 47 47 62 and repeat (avg 50-> 20 interval/sec)
48-: 62 63 and repeat (avg 62,5-> 16 interval/sec)
i haven't continued it further but from 125 it's working fine...
i have tried it with 3 computers and got the same results
cpu P4 2,4 GHz, AMD Athlon dual 2,69 GHz, ...
ram 1GB-2GB
os windows xp
sfs 1.6.6
java 1.6.0_13
it's working fine on a
cpu amd athlonII dual 2,1GHz
ram 2GB
os win 7
sfs 1.6.6
java 1.6.0_13