I agree with Justin that the implementation is quite imprecise and has built in 
a lot of overhead and "jitter" to the firing of timer events. If you are 
interested in looking into the code, here is a background on what I know about 
timers in XEngine.

Timers are only checked for expiration in Timers.cs every 100ms so there is 
some "overhead" always built in. This value used to be configurable in 
OpenSim.ini using AsyncLLCommandLoopms but is has apparently been removed at 
some point.

Each time the AsyncCommandManager loops (100ms), it calls into 
CheckTimerEvents() in Timer.cs that Justin mentioned. Each elapsed timer in the 
list of timers will trigger a ScriptEngine.PostScriptEvent of type "timer" on 
the script engine. The script engine passes the event on to the specific script 
instance which may accumulate/batch events with a minimum delay. This batching 
typically does not apply to timer events but it can. It's configurable with the 
LSL command llMinEventDelay(double delay).  The script instance queues the 
timer event onto XEngine as a normal thread pool QueueWorkItem which will then 
be executed as soon as it can be scheduled.

So, the only guaranteed delay is the (up to) 100ms added by the async command 
loop in checking for expired timers. If there are lots of timers, then there 
are several linear lists of searching and processing events which can create 
additional overhead but it doesn't sound like that's what you are doing (just 1 
timer).  After that, there is possibly a minimum batching time for script 
events and 1 asyc call to QueueWorkItem. The queued work item is EventProcessor 
in ScriptInstance.cs and for a timer event, I don't think there are additional 
delays in there.

~Dan

From: Mic Bowman [mailto:[email protected]]
Sent: Friday, December 03, 2010 8:04 PM
To: [email protected]
Cc: Lake, Dan
Subject: Re: [Opensim-users] Slow LSL timers

i believe dan did some work on optimizing the timers. maybe he can give some 
insight...

--mic

On Fri, Dec 3, 2010 at 5:35 PM, Justin Clark-Casey 
<[email protected]<mailto:[email protected]>> wrote:
I'm not familiar with the this area of the code but I had a quick look since I 
was curious (the meat is in 
OpenSim/Region/ScriptEngine/Shared/Api/Plugins/Timer.cs).  The code isn't using 
C# timers so I'm not totally surprised at the behaviour that you're seeing.

I suspect addressing this would require a considerably different implementation.


On 03/12/10 17:18, Jorge Lima wrote:
Ran 100 timer events with a single if(++i>  100) inside. I suppose
decrementing and comparing to 0 might be faster, but I also
copy-pasted 100 inlined if clauses and the time to run them was
negligible.

llSetTimerEvent(0.1) ->  59 s ->  490% overhead
llSetTimerEvent(0.2) ->  59 s ->  195% overhead
llSetTimerEvent(0.5) ->  59 s ->  18% overhead
llSetTimerEvent(0.75) ->  81 s ->  8% overhead
llSetTimerEvent(1.0) ->  108 s ->  8% overhead
llSetTimerEvent(2.0) ->  209 s ->  4.5% overhead
llSetTimerEvent(4.0) ->  407 s ->  1.75% overhead

I am guessing that the overhead is, therefore, internal to the timer
implementation. I haven't tested raw C# timers as comparison but 100ms
is an eternity in modern computing, I can ping servers across the
Atlantic ocean in less than that!

I went through the code but I haven't yet found the part that handles
timers. It's not in EventManager.
Does anyone know what's going on? The code works fine in SL.
Should I be posting this in the dev list? I'd like to see if I can fix it.
Any thoughts on how to get fast timers in OpenSim?
Faster computer? (I did check and was only getting about 20% CPU usage...)
Porting them to a Real-Time operating system? :)
_______________________________________________
Opensim-users mailing list
[email protected]<mailto:[email protected]>
https://lists.berlios.de/mailman/listinfo/opensim-users

--
Justin Clark-Casey (justincc)
http://justincc.org
http://twitter.com/justincc

_______________________________________________
Opensim-users mailing list
[email protected]<mailto:[email protected]>
https://lists.berlios.de/mailman/listinfo/opensim-users

_______________________________________________
Opensim-users mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/opensim-users

Reply via email to