MantisBT - opensim
View Issue Details
0003862opensim[REGION] Scripting Enginepublic2009-07-03 09:152009-08-08 06:41
jfhopkin 
 
normalmajoralways
feedbackopen 
 
 
Grid (Multiple Regions per Sim)
ODE
Mono / Linux32
2.2
0003862: Script timer events badly inaccurate over a period
The timer isn't dependable enough over a given period. This makes some functions in SL unusable in OpenSim. For example, swing scripts which rely on coordinating llTargetOmega() rotation with timer() events, work fine in SL but are unusable in OpenSim. Even a clock which ticks every second sounds noticeably arrhythmic in OpenSim but fine in SL.

Note that some inaccuracy in the execution individual timer events is perfectly understandable; however, over time these inaccuracies should start to average close to zero. Instead, they compound.

See Additional Information for a comparative test between OS and SL.

P4/3.6GHz/2GB
Ubuntu Jaunty
Mono 2.2
XEngine
Drop this in a prim:

default
{
    state_entry()
    {
        llSetTimerEvent(10.0) ;
    }
    timer()
    {
        llSay(0, (string)llGetTime()) ;
    }
}

Result in OpenSim:

[07:53] Primitive: 10.165108
[07:53] Primitive: 20.195535
[07:53] Primitive: 30.234698
[07:53] Primitive: 40.281795
[07:53] Primitive: 50.375598
[07:54] Primitive: 60.420302
[07:54] Primitive: 70.451000
[07:54] Primitive: 80.507164
[07:54] Primitive: 90.571056
[07:54] Primitive: 100.603898
[07:54] Primitive: 110.702383
[07:55] Primitive: 120.745550
[07:55] Primitive: 130.787046
[07:55] Primitive: 140.816682
[07:55] Primitive: 150.864184
[07:55] Primitive: 160.946772
[07:55] Primitive: 170.982877
[07:56] Primitive: 181.015696

Showing a net gain of nearly a second in 3 minutes.

By contrast, in SL:

[9:03] Object: 10.224720
[9:03] Object: 20.130380
[9:04] Object: 30.152020
[9:04] Object: 40.153270
[9:04] Object: 50.169860
[9:04] Object: 60.173560
[9:04] Object: 70.191370
[9:04] Object: 80.217800
[9:05] Object: 90.218410
[9:05] Object: 100.221700
[9:05] Object: 110.236800
[9:05] Object: 120.254100
[9:05] Object: 130.268400
[9:05] Object: 140.267700
[9:06] Object: 150.295500
[9:06] Object: 160.273300
[9:06] Object: 170.301800
[9:06] Object: 180.298100

Showing barely a significant difference.
No tags attached.
Issue History
2009-07-03 09:15jfhopkinNew Issue
2009-07-03 09:15jfhopkinSVN Revision => 9943
2009-07-03 09:15jfhopkinRun Mode => Grid (Multiple Regions per Sim)
2009-07-03 09:15jfhopkinPhysics Engine => ODE
2009-07-03 09:15jfhopkinEnvironment => Mono / Linux32
2009-07-03 09:15jfhopkinMono Version => 2.2
2009-07-03 19:30GodfreyNote Added: 0012320
2009-07-04 10:21jfhopkinNote Added: 0012322
2009-07-04 11:17melanieNote Added: 0012323
2009-07-05 02:56jfhopkinNote Added: 0012325
2009-08-08 06:41Fly-Man-Statusnew => feedback

Notes
(0012320)
Godfrey   
2009-07-03 19:30   
How many threads are you using for script execution, what's your minimum timer interval set to, and how many other scripts are running in the regions?

In my OpenSim.ini, I've got NumberOfScriptThreads=10 and MinTimerInterval=0.04, and I get these results on a region with 525 active scripts:

[18:16] Primitive: 10.199426
[18:16] Primitive: 20.207934
[18:17] Primitive: 30.218435
[18:17] Primitive: 40.306709
[18:17] Primitive: 50.316242
[18:17] Primitive: 60.324550
[18:17] Primitive: 70.333489
[18:17] Primitive: 80.342190
[18:18] Primitive: 90.350817
[18:18] Primitive: 100.444205
[18:18] Primitive: 110.458541
[18:18] Primitive: 120.472739
[18:18] Primitive: 130.485798
[18:18] Primitive: 140.494710
[18:19] Primitive: 150.503225
[18:19] Primitive: 160.592832
[18:19] Primitive: 170.607614
[18:19] Primitive: 180.621921

And on a region with 25 active scripts, I get:

[18:22] Primitive: 10.174351
[18:22] Primitive: 20.204337
[18:22] Primitive: 30.211862
[18:22] Primitive: 40.219029
[18:23] Primitive: 50.249916
[18:23] Primitive: 60.256769
[18:23] Primitive: 70.287368
[18:23] Primitive: 80.293985
[18:23] Primitive: 90.300427
[18:23] Primitive: 100.331021
[18:24] Primitive: 110.337854
[18:24] Primitive: 120.344467
[18:24] Primitive: 130.374882
[18:24] Primitive: 140.381355
[18:24] Primitive: 150.387708
[18:24] Primitive: 160.417977
[18:25] Primitive: 170.424480
[18:25] Primitive: 180.436992

Obviously, still not terribly precise - but quite a bit closer to SL's timing. Those are running on two different machines, by the way, since script threads are shared amongst all regions running in the same instance. I don't have a realtime kernel installed on either of those machines, if it matters.

Also, just as an aside - instead of using a timer for clock ticks, it's much more efficient to use a soundfile that's exactly a second long (or multiples thereof) and play it looped.
(0012322)
jfhopkin   
2009-07-04 10:21   
On the region I'm using for testing, there are 27 scripts according to the "top scripts" panel. The total by the same measure is about 58 scripts; I'm pretty certain this is an underestimate. Is there a better measure?

Anyway, I added entries for:

NumberOfScriptThreads = 10
MinTimerInterval = 0.04

into the XEngine section of OpenSim.ini (an assumption - only the first exists i the example, and that's in the DotNetEngine section), rebooted the sim, and got:

[08:43] Primitive: 10.264934
[08:43] Primitive: 20.296376
[08:43] Primitive: 30.362051
[08:43] Primitive: 40.391368
[08:43] Primitive: 50.419698
[08:44] Primitive: 60.423383
[08:44] Primitive: 70.457891
[08:44] Primitive: 80.485201
[08:44] Primitive: 90.533604
[08:44] Primitive: 100.562185
[08:44] Primitive: 110.602805
[08:45] Primitive: 120.644673
[08:45] Primitive: 130.691793
[08:45] Primitive: 140.736173
[08:45] Primitive: 150.763696
[08:45] Primitive: 160.816368
[08:45] Primitive: 170.876923
[08:46] Primitive: 180.925256

Still creeping forward, but a little less so than before, which I guess could be a side-effect of restarting the sim, or due to the additional parameters.
(0012323)
melanie   
2009-07-04 11:17   
XEngine doesn't use NumberOfScriptThreads and the MinTimerInterval has no bearing on this. Script timers are by definition not accurate and not dependable either short or long term. Please do not depend on them.
I realize this is a legitimate concern and therefore I'm not closing the Mantis, but unless and untl we have microthreading, it will not be possible to make them as accurate as you would wish. I would suggest using the *UnixTimestamp functionality to get a wallclock timebase for longer timers.
(0012325)
jfhopkin   
2009-07-05 02:56   
Understood, Melanie. Thanks for your help.