<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:p="urn:schemas-microsoft-com:office:powerpoint" xmlns:a="urn:schemas-microsoft-com:office:access" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema" xmlns:b="urn:schemas-microsoft-com:office:publisher" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:c="urn:schemas-microsoft-com:office:component:spreadsheet" xmlns:odc="urn:schemas-microsoft-com:office:odc" xmlns:oa="urn:schemas-microsoft-com:office:activation" xmlns:html="http://www.w3.org/TR/REC-html40" xmlns:q="http://schemas.xmlsoap.org/soap/envelope/" xmlns:rtc="http://microsoft.com/officenet/conferencing" xmlns:D="DAV:" xmlns:Repl="http://schemas.microsoft.com/repl/" xmlns:mt="http://schemas.microsoft.com/sharepoint/soap/meetings/" xmlns:x2="http://schemas.microsoft.com/office/excel/2003/xml" xmlns:ppda="http://www.passport.com/NameSpace.xsd" xmlns:ois="http://schemas.microsoft.com/sharepoint/soap/ois/" xmlns:dir="http://schemas.microsoft.com/sharepoint/soap/directory/" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:dsp="http://schemas.microsoft.com/sharepoint/dsp" xmlns:udc="http://schemas.microsoft.com/data/udc" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:sub="http://schemas.microsoft.com/sharepoint/soap/2002/1/alerts/" xmlns:ec="http://www.w3.org/2001/04/xmlenc#" xmlns:sp="http://schemas.microsoft.com/sharepoint/" xmlns:sps="http://schemas.microsoft.com/sharepoint/soap/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:udcs="http://schemas.microsoft.com/data/udc/soap" xmlns:udcxf="http://schemas.microsoft.com/data/udc/xmlfile" xmlns:udcp2p="http://schemas.microsoft.com/data/udc/parttopart" xmlns:wf="http://schemas.microsoft.com/sharepoint/soap/workflow/" xmlns:dsss="http://schemas.microsoft.com/office/2006/digsig-setup" xmlns:dssi="http://schemas.microsoft.com/office/2006/digsig" xmlns:mdssi="http://schemas.openxmlformats.org/package/2006/digital-signature" xmlns:mver="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns:mrels="http://schemas.openxmlformats.org/package/2006/relationships" xmlns:spwp="http://microsoft.com/sharepoint/webpartpages" xmlns:ex12t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:ex12m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:pptsl="http://schemas.microsoft.com/sharepoint/soap/SlideLibrary/" xmlns:spsl="http://microsoft.com/webservices/SharePointPortalServer/PublishedLinksService" xmlns:Z="urn:schemas-microsoft-com:" xmlns:st="" xmlns="http://www.w3.org/TR/REC-html40">

<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<style>
<!--
 /* Font Definitions */
 @font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
-->
</style>
<!--[if gte mso 9]><xml>
 <o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
 <o:shapelayout v:ext="edit">
  <o:idmap v:ext="edit" data="1" />
 </o:shapelayout></xml><![endif]-->
</head>

<body lang=EN-US link=blue vlink=purple>

<div class=WordSection1>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>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.<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>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. <o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>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. <o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>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. <o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>~Dan<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>

<div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in'>

<p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span
style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> Mic Bowman
[mailto:cmickeyb@gmail.com] <br>
<b>Sent:</b> Friday, December 03, 2010 8:04 PM<br>
<b>To:</b> opensim-users@lists.berlios.de<br>
<b>Cc:</b> Lake, Dan<br>
<b>Subject:</b> Re: [Opensim-users] Slow LSL timers<o:p></o:p></span></p>

</div>

<p class=MsoNormal><o:p> </o:p></p>

<p class=MsoNormal style='margin-bottom:12.0pt'>i believe dan did some work on
optimizing the timers. maybe he can give some insight...<br>
<br>
--mic<br>
<br>
<o:p></o:p></p>

<div>

<p class=MsoNormal>On Fri, Dec 3, 2010 at 5:35 PM, Justin Clark-Casey <<a
href="mailto:jjustincc@googlemail.com">jjustincc@googlemail.com</a>> wrote:<o:p></o:p></p>

<p class=MsoNormal>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.<br>
<br>
I suspect addressing this would require a considerably different implementation.<o:p></o:p></p>

<div>

<div>

<p class=MsoNormal><br>
<br>
On 03/12/10 17:18, Jorge Lima wrote:<o:p></o:p></p>

<p class=MsoNormal style='margin-bottom:12.0pt'>Ran 100 timer events with a
single if(++i>  100) inside. I suppose<br>
decrementing and comparing to 0 might be faster, but I also<br>
copy-pasted 100 inlined if clauses and the time to run them was<br>
negligible.<br>
<br>
llSetTimerEvent(0.1) ->  59 s ->  490% overhead<br>
llSetTimerEvent(0.2) ->  59 s ->  195% overhead<br>
llSetTimerEvent(0.5) ->  59 s ->  18% overhead<br>
llSetTimerEvent(0.75) ->  81 s ->  8% overhead<br>
llSetTimerEvent(1.0) ->  108 s ->  8% overhead<br>
llSetTimerEvent(2.0) ->  209 s ->  4.5% overhead<br>
llSetTimerEvent(4.0) ->  407 s ->  1.75% overhead<br>
<br>
I am guessing that the overhead is, therefore, internal to the timer<br>
implementation. I haven't tested raw C# timers as comparison but 100ms<br>
is an eternity in modern computing, I can ping servers across the<br>
Atlantic ocean in less than that!<br>
<br>
I went through the code but I haven't yet found the part that handles<br>
timers. It's not in EventManager.<br>
Does anyone know what's going on? The code works fine in SL.<br>
Should I be posting this in the dev list? I'd like to see if I can fix it.<br>
Any thoughts on how to get fast timers in OpenSim?<br>
Faster computer? (I did check and was only getting about 20% CPU usage...)<br>
Porting them to a Real-Time operating system? :)<br>
_______________________________________________<br>
Opensim-users mailing list<br>
<a href="mailto:Opensim-users@lists.berlios.de" target="_blank">Opensim-users@lists.berlios.de</a><br>
<a href="https://lists.berlios.de/mailman/listinfo/opensim-users"
target="_blank">https://lists.berlios.de/mailman/listinfo/opensim-users</a><o:p></o:p></p>

<p class=MsoNormal style='margin-bottom:12.0pt'><o:p> </o:p></p>

</div>

</div>

<p class=MsoNormal><span style='color:#888888'>-- <br>
Justin Clark-Casey (justincc)<br>
<a href="http://justincc.org" target="_blank">http://justincc.org</a><br>
<a href="http://twitter.com/justincc" target="_blank">http://twitter.com/justincc</a></span><o:p></o:p></p>

<div>

<div>

<p class=MsoNormal><br>
_______________________________________________<br>
Opensim-users mailing list<br>
<a href="mailto:Opensim-users@lists.berlios.de" target="_blank">Opensim-users@lists.berlios.de</a><br>
<a href="https://lists.berlios.de/mailman/listinfo/opensim-users"
target="_blank">https://lists.berlios.de/mailman/listinfo/opensim-users</a><o:p></o:p></p>

</div>

</div>

</div>

<p class=MsoNormal><o:p> </o:p></p>

</div>

</body>

</html>