Almost done WIP: Script Lag Monitor

EDIT: So what happened? This got delayed due to a bad LOD on the mesh I’m using for the text. Other people have given me free replacements (thank you for that) – but now I have to rewrite these lines:

    while(++i)
    {
        charA = (96 + llSubStringIndex(charset,llGetSubString(s,(faces + i) * 2,(faces + i) * 2))) % 96; //unfound chars will use the last char(DEL) in the charset as a replacement, null strings with use the first char(space) in the charset
        charB = (96 + llSubStringIndex(charset,llGetSubString(s,((faces + i) * 2) + 1,((faces + i) * 2) + 1))) % 96;
        integer column = ((96 * charA) + charB) % 85; //85 = (1024 pixel texture width / (6 pixel char width * 2 chars per set)
        integer row = ((96 * charA) + charB) / 85;
        PARAMS = (PARAMS = []) + PARAMS + [PRIM_TEXTURE,faces + i,"5e947299-739e-1c42-fb30-64e04bc0510d",<1.0,1.0,0.0>
,<(float)column * (12.0 / 1024.0),(float)row * -(8.0 / 1024.0),0.0>
,0.0];
    }

To apply text to things with a different UV map than the mesh I had used. And that is proving more complex than I expected.

I’ve been working on a new scripting project for the past few days:

This thing will monitor a region defined as either your parcel, all parcels you own in the sim, or the whole sim – and report back the top 8 laggiest avatars as defined in order of the ‘script time’ they are using.

Script Time is defined as:

the average CPU time (in seconds) used by scripts in an object or agent. Like top scripts, the time reported is the average script time per frame for the last 30 minutes for all scripts on the object. If the object has been in the region for less than 30 minutes, the number reported will be the average time per frame since the object entered the region.

It is getting it’s values from llGetObjectDetails: http://wiki.secondlife.com/wiki/LlGetObjectDetails

There has long been debate about the value of all these metrics in relation to ‘lag’. A lot of that revolves around people who are too picky over the definition of lag. Insisting on a technical definition rather than a ‘common use’ definition.

The common use definition is easy:

‘This stuff is slowing me down. Things are slow.’

The technical definition wants different words for:

  • The server is slow
  • My connection is slow
  • My computer is slow
  • My own butt is too slow clicking them keys
  • 27,372 different other things that most people just define as “this crap is freaking slow”.

All I care about is “this crap is slow”.

– That is how I define lag… I know that according to a computer science manual this makes me the equivalent of an Amish from the year 3702 B.C. who doesn’t even know what a stone axe is (ps: Amish didn’t exist back then. I know). Fine… But that’s what most people mean when they say “SL is laggy”. The mean their experience is slow.

So…

In the world of “this crap is slow” all of these metrics matter to some degree. They each indicate something different – but it all adds up to “WTF is wrong with my SL?”

The most important one of them though – the one that actually says “Yo… you, yeah you… WTF is you doing? Cut it out already!” is Script Time.

– This one is saying that person’s scripts are using up a measurable amount of CPU time…

Now we can argue about “the sim will still get everything done because scripts come after other resources and so your stuff will be done…”

But I want my stuff done now… I don’t want to have to step into the Tardis and have the Doctor take me to the end of the Universe to finish my ‘sit in chair’ action…

Sure it will get done… the CPU just pushes it off…

Kinda like Congress…

Push it off to after the next election… and again… and again… because it doesn’t want to pay that ‘time’ yet…

Even the people who say ‘Script Time is meaningless’ say so in terms of “because someday, long after the sun has exploded and we’ve moved to Earth 9 and the Face of Boe has passed away… (and even CW has run out ways to bring him back for the next season of Arrow) that crap will be done… so it’s not actually lag, because it does happen eventually…”

… Well even in that we’re admitting that “this crap is freaking slow”.

So…

I sort this meter by Script Time because it’s a concrete measure.

I show total scripts – that’s more a human curiosity thing.

Let’s say I’m running one beastly script that eats up 90% of a sim’s resources and you’re running 103 tiny little scripts that don’t do much of anything… who’s the bigger problem in that? Me. So ‘Total Scripts’ is great for drama but doesn’t mean much by itself.

Still I probably couldn’t pass around a meter unless I had that value on it…

Memory…

Script memory does mean something. But it is allocation rather than use. Allocation is more important than people think though…

Let’s say you have a nice closet rack with 72 clothing hangers on it. I say “I reserve these 64 hangers for me, you get the rest”

I put up 3 dresses. You’re standing there with 20… You put up your first 8 and then reach for the 9th hanger and I slap your hand away saying “that hanger is mine.”

– I only used 3… but I allocated 64.

This is why allocation matters.

Because you now have to keep swapping 11 dresses in your hand with the 8 on the rack and juggling that mess… because I’ve been a jerk and reserved the other 64 for myself and walked away.

There are tools in SL’s coding language to ‘change your allocation based on what you used’… to look at the rack after I put up 3 dresses and say “oh hey… I only used 3, you can use the other 61 now”…
– But most SL script makers don’t use this code… it’s why almost everything in SL, when you look at the script usage:

Shows a 16 or a 64, or some multiple of those numbers… There’s a reason I picked 64 hangers… SL’s mono language only sells hangers in packs of 64… then lets you tell the closet how many you used and let other people use the rest. The older LSL pre-mono system sold them in packs of 16 and made you use them all, and if you had 17 dresses… tough.

So… Script Memory usage is useful… but also kinda tricky… and it’s subject to a massive amount of drama among the community because of the issue of it being allocation and not usage and questions on ‘what’s that mean’.

So I report it… but I sort by Script Time instead.

Arc…

This is the old metric that was used before ‘Avatar Complexity’. There actually two versions of ARC in SL, and one was total junk, the second one was almost good, but not really good. I have no idea which one SL’s code reports – but neither is the current system.

However SL code has no way that I could find to get ‘Avatar Complexity’, and again a lot of meters report this value. While it is not accurate, it IS still useful to see in terms of sort order… the higher someone is on, the more laggy they “probably are” to those around them – in terms of more stuff to have to deal with when that person is around you… but it’s hard to say at what point is there an issue… and with modern graphics some people might be easier to ‘render’ (see) who have higher numbers than others… So Arc is only “sometimes useful”. We definitely do NOT want to sort the list based on, nor take action or warn people based on values in it.

If we had ‘Avatar Complexity’ that wold be different – it is possibly even more useful than Script Time for telling you if someone around you will cause you ‘lag’ (as in “slow your SL down” – you people who want technical definitions of the word lag can stuff it).

Finally we get to ‘Download Weight’ – I don’t think anyone else reports this, it was a curious metric I found in the LSL code:

http://wiki.secondlife.com/wiki/OBJECT_STREAMING_COST

http://wiki.secondlife.com/wiki/Mesh/Mesh_Streaming_Cost

I am calling it ‘Download Weight’ – what it is referred to in the second article, rather than ‘Streaming Cost’ because this isn’t your Netflix bill…

Here’s some techie mumbo-jumbo to make this more confusing:

“The streaming and rendering cost of a Mesh is directly related to the number of bytes in a Mesh asset LOD slot, and the likelihood that a given LOD will be downloaded and displayed can be computed based on the size of the object. Imagine a set of 3 concentric circles centered on an object where each circle represents the transition boundary between LODs. The streaming/rendering cost of that object can be determined by examining the size of those circles vs the number of bytes in the relevant LODs. Uploading a high LOD only will result in the load of the high lod being applied to the entire 256m, while uploading appropriate LODs will result in the lion’s share of 256m being applied to the lowest LOD. ”

Confused yet?

This one basically means… ‘ya’ll gots some stuff that is taking time to download and render’.

Um so… yeah… Is that important? How much is too much? If I am at 31 and you are at 753 does that matter?

This one looked interesting to mentally note and observe… but it is too vague to use for determining ‘who’s naughty and who’s nice’…

So the end of all that blathering is that this meter sorts on and warns on Script Time only.

It is basically the only metric we can have an objective opinion about that says “that person over there with a high script time is causing a problem for the sim”.

How much is high?

I dunno…

Yeah… that’s right. I don’t know. No one really does. So I made it a setting you can adjust in the config notecard.

– This is one of the major reasons critics of these meters don’t like them. “We don’t know how fast is too fast to drive on the freeway so there should be no speed limit and I’mma gonna go do 372 mph next to a school zone. da’freak with any kids I run over.”

I think it’s better to just say “you know… most people seem to be under this… so why don’t I double it, and set my gauge there…”

There’s actually a lot that I made configurable in this thing.

Here’s the config notecard:

# warn and then take action above this number, the value is in miliseconds.
scriptMemThreshold = 0.25

# Rerun the region scan every ‘scanHowOften’ seconds. Don’t slow your sim down scanning too often.
# The scan itself takes from 5-10 seconds to process all the data and send out warnings / take action, so
# any faster than 20 risks the script tripping over itself.
# This is protected against values below 20. Any values below that will be treated as 20.
scanHowOften = 30

# countToAction
# This number is how many warnings a person will get before action is taken against them.
# This is protected against being set below one. Values below that will be treated as 1.
countToAction = 3

# graceCount
# This is the number of scans to do before giving any warnings.
# When an avatar enters a sim, that sim has to load in everything about that avatar’s current status: the things you see, the scripts,
# and various assorted bits of data. All of this causes avatars to ‘spike’ on their lag reports for as much as a minute after appearing on sim.
# For this reason we don’t pester people who just popped in. If you find that people you know are low on lag and getting ‘warned’ by this monitor,
# up the value of this setting a little bit and have them test out teleporting in and out until you “find the sweet spot” for your sim.
# New avatars will still show on the monitor when they first join, just not get spammed, so you can watch the monitor to see how long it takes
# your sim to ‘load them in’ and bring their numbers down. And if it’s taking seriously long… see about asking somebody for a sim restart, or
# look into what’s going on with slowing your sim down… (some years ago I had to delete an entire line of furniture I had stuffed into a temp-rezzer
# because it will killing my sim – this was the day that convinced me to stop using temp-rezzers, and to update my brands of furniture…). I had
# thought it was laggy avatars, but as soon as I cleared that junk out, my sim was oiled-up and ready for action.
# For every step of this value, the monitor will wait ‘scanHowOften’ seconds before sending warnings.
# This value is protected against going below 1. Any value below 1 will be treated as 1.
# furthermore, for most sims, 1 is actually the right value to use.
graceCount = 1

# use ban, eject, teleport, or warn. All other entries are treated like eject.
# ban: puts the avatar on the parcel ban list – use this carefully.
# eject: throws the avatar off to the nearest land not owned by the owner of the ‘ScriptMonitorZapper’. Fails to work on a region with no bordering regions.
# teleport: teleports the avatar home.
# warn: takes no action except to keep messaging the offender every 30 seconds asking them to reduce their lag.
warningAction = eject

# warningMessage
# This is the message sent to people to warn or notify them about being laggy.
# Split into parts 1 and 2, max 255 character each, in case you want an extra long message (like the example).
# This MUST include one use of both [*] twice in the message.
# The first use will report how much lag the offender is causing, the second will report the sim’s “scriptMemThreshold”.
warningMessageP1 = Your Script Time of [*]ms CPU time per frame exceeds [*]ms, which is slowing down the sim for everyone in it no matter who’s land they or you are on. Please detach some of that fine sweet lag you’re running
warningMessageP2 = around with so the rest of us can enjoy SL as much as you do.

# Avatars in parcels in this region owned by the owner of the parcel this is rezzed in.
# parcel: All avatars on this parcel.
# parcelowner: All avatars on parcels owned by the same owner/group as the land this monitor is on.
# region: All avatars in the region.
scanDistance = region

# Should the monitor report lag info privately or publicly?
# vocal: the monitor will say into local chat who is laggy – limited in distance to those near the monitor. – 20m range
# quiet: the monitor will only message laggy individuals, and not mention them publicly. mum’s the word.
# loud: the monitor will use shout to send a message about who is laggy. – 100m range
gossip = quiet

# The list of people you don’t want actions taken against. They will still get warnings when they’re laggy, but they won’t get zapped.
# Names must be full usernames, like: Pussycat Catnap or Reggae Resident. Just using Reggae would not protect that avatar.
# So again, avatars with ONLY a firstname username, like Reggae, need to have the ‘Resident’ part added in here.
avatarOnPrivelegedList = Pussycat Catnap, Reggae Resident

# The channel the monitor uses to talk to the ‘ScriptMonitorZapper’
# If you change this it will break the zapper unless you also make the value the same in the zapper’s script.
# You have to edit the zapper’s script – it does not have a notecard.
controlBoxChannel = -4902257

So right now… this meter is just on my land. I’m testing it out… I do plan to release it soon. When I do so… I am debating things like… what to charge for it… and what permissions to set.

I’ve been annoyed that none of the other meters I could find had readable scripts. I had to hack my way through LSL and the LSL wiki to figure out making this thing.

I was motivated to make it because every meter out there has half the features I want combined with a set of feature that annoy the heck out of me…

Like… spamming everyone sim wide the moment you teleport in reporting your lag…

– Well guess what? When avatars first land on a sim the sim spends a lot of resources loading them in, including all their active scripts, all the textures on them, all the mesh and prims, and an assortment of things… So when people first land on a sim they’re metrics spike up kinda high, then quickly go down to their actual usage…

  1. So that there was my first incentive… to make a meter that could track everyone on a sim, even outside of my own parcel, report people using excessive scripts to the meter, message them asking them to ‘turn down the music dude, it’s after 11pm and you’re blaring that Katey Perry like crazy all over the whole block’… and well… not do so until after they’ve been around long enough for the all the sim-loading-dogs to stop barking unless there is an actual reason to bark…
  2. The second thing that annoyed me about all of the competition was the extremely prim and texture heavy manner they used to display text… I used a full-perms solution I grabbed off of Marketplace:
    https://marketplace.secondlife.com/p/LLSLEDLCDSprite-Mesh-Text-Display-For-Developer-Use-Only/7245285- This means my entire monitor uses 3 textures:the backboard texture (512×512)
    A single texture for all of the text (1024×1024)
    The SL Library transparent textureand one more fourth texture, my logo, sits on the ‘ActionHandler’ box – the box that actually ejects, teleports, or bans people if you have configured for those options.If you display text on a board in Second Life, I highly recommend checking out this new display technology. It’s much better than the old methods…

I’m probably going to put this out soonish, and make it mod. It’s my hope that doing so will help improve it, and help other people learn SL scripting.

Advertisements

1 Comment (+add yours?)

  1. Trackback: Almost done WIP: Script Lag Monitor – thomas mcgreevy

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

%d bloggers like this: