Small intervals

Post here your questions about Actionscript and Java server side extensions development.

Moderators: Lapo, Bax

Post Reply
Poyz
Posts: 83
Joined: 28 Mar 2006, 14:27

Small intervals

Post by Poyz »

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. ?
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

why wouldn't the setInterval work under 250ms?
Can you explain what is the problem?
Lapo
--
gotoAndPlay()
...addicted to flash games
Poyz
Posts: 83
Joined: 28 Mar 2006, 14:27

Post by Poyz »

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
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

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:

Code: Select all

thread = null
lastTime = 0

function init()
{
	thread = setInterval("myThread", 10)
	lastTime = getTimer()
}

function myThread()
{
	trace("Interval: " + (getTimer() - lastTime))
	lastTime = getTimer()
}
p.s. = beware, at 10ms it will print results veeeery fast :D
Lapo
--
gotoAndPlay()
...addicted to flash games
Poyz
Posts: 83
Joined: 28 Mar 2006, 14:27

Post by Poyz »

with your code i get:

10 -> 15 16 15 16 15 16 constantly
50 -> 62 63 62 63 62 63 constantly

and it only gives precision when i reach 250

i guess its only me then :?
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

Just make sure you don't have another dozen of apps running in the background or that the CPU is already working alot when testing...
What kind of machine are you using? (cpu/ram)
Which OS?
Which version of SFS and Java?
Lapo
--
gotoAndPlay()
...addicted to flash games
preecep
Posts: 49
Joined: 01 Aug 2007, 10:28

Post by preecep »

Is this a problem with the timer resolution? Does linux have a higher system timer resolution than windows?
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

No, I have never seen this problem before. There can be some imprecision with very fast intervals but not like that. At least I have never seen it and I am not able to reproduce it.
Lapo
--
gotoAndPlay()
...addicted to flash games
turek
Posts: 5
Joined: 14 May 2011, 01:06

Post by turek »

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
turek
Posts: 5
Joined: 14 May 2011, 01:06

Post by turek »

i'd like to know why is it working well on one computer and not on others...
Post Reply