Avatar Script Use Patterns in Secondlife

INTRODUCTION

There are many factors that contribute to sever side lag in SecondLife.  One of them is the amount of time consumed executing all the scripts in the region.  It’s not unusual for scripts to take up half of the total processing time, most of it from scripts in static or moving objects rezzed in the region.

As you may know, the sim attempts to run at 45 frames per second.  This means that each frame has 22.2 milliseconds to execute all that it can in that time slice.  If there is too much for the sim to get done during that time, it slows down apparent time to give itself more time.  This is measured by time dilation in the statistics panel (Ctrl-shft-1).  A time dilation of 0.75 means that one second of real time looks like ¾ second in SecondLife.  SecondLife is going slower than real life.

It’s not unusual for scripts to take up close to half of the 22.2 milliseconds in a frame.  Sim and land owners can reduce this by minimizing the number of objects with scripts and also minimizing the time used by them.

Region owners have also become more conscious recently about reducing the scripts used in the attachments of all the avatars in the region.  It’s fairly common these days for most attachments to have resizer or texture changing scripts.  This can contribute significantly to script time that must be processed by the sim. 

I’ve become interested in this and decided to study it.  I’ll break my study into 2 separate blog entries.  This one covers the results of a study I did on typical patterns of script use in attachments worn by avatars.  The second entry will focus more on what to do to reduce script time use.

Many people focus on the NUMBER of scripts in attachments worn by avatars in a region.  There is some correlation between number of scripts and the time used. The more scripts the more likely more time will be used.

SL scripts are event based.  They mostly sit around waiting for an event to occur which triggers the execution of a snippet of code.  Each script carries a base use time just to monitor if events are happening so the number of scripts does matter somewhat. 

However, the important thing is really what those scripts are doing    Although there is overhead in monitoring for events, most of the time used by a scripts comes from what the script does when an event is triggered.  It’s the time spent in code execution that matters.  One can have many scripts that are just sitting around that will use less time than a few scripts executing a lot of code.

THE METHODOLOGY (The geek stuff)

So for this study, I wanted to monitor the script time used by the attachments worn by each avatar in a region.  My aim was to get a valid sample of how much time is typically used and how that varies.

The SL scripting language provides a function called llGetObjectDetails which allows someone to monitor all the avatars in a region and get the number of scripts they are wearing, how much memory they are using and how much average execution time are they taking.  I made a HUD, that when activated, would measure average script time per frame for each avatar in a region, making sure to only count an avatar no more than once a day.  The owner of the HUD was excluded from measurement.

My aim was to produce a histogram or frequency distribution.  I broke up the range from 0 to 1.275 milliseconds into 50 slices and had the HUD count the number of avatars whose script time fell into each slice.  For example, the time slice labeled 0.025 held that number of avatars whose script time fell between 0.0 and 0.025 milliseconds within the first 3 minutes they were encountered in a given day.  No avatar was counted more than once a day and the HUD owner was excluded from the count.

I asked 16 people plus myself to wear it around for about a week and send me the results.  All total, I ended up with a sample of 6284.  

RESULTS (More geek stuff)

The results are in the following table:

Image

     

Table 1

The first column represents 50 times slices that will make up the X axis of the charts below.  A given row represents the time slice (in micro seconds, thousandths of a millisecond) between that time and the one below it.  For example, the row labeled 100 will contain data between 75 and 100 microseconds (0.075 – 0.100 milliseconds).  The second column is the percent of the sample that fell within the particular range.  The third column represents the cumulative percent, the percent of the sample falling at that value and below.

The next 2 graphs are the plots of the data in column 2 and 3 respectively using column 1 as the X axis. 

Image 

                                                                                Figure 1

 Image

                                                                                Figure 2

INTERPRETATION

Figure 1 is a frequency distribution.  Each bar represents the percent of avatars within that range.  It is skewed in a way that is typical of statistics that measure time.  Most avatars have fairly low script times.  A few have high script times.

Figure 2 is a cumulative frequency distribution.  Each bar represents the percent of avatars in that range and below.  The cumulative statistics are more useful for our purposes.

Here are a few useful points to focus on:

About 50 % of avatars have script use times at or below 0.075 millseconds.  This is the median time.

About 80% of avatars have script use times at or below 0.175 milliseconds.  If we wanted to advise people about high script use, a common practice would be to focus on the 20% who have the highest times.  We could send out notices to everyone above 0.175 milliseconds to catch that top 20 %.

If we wanted to be a bit more forgiving and focus on the top 10%, we would pick 0.250 milliseconds as the threshold.

The top 5% falls at the 0.350 millisecond threshold.

The top 1% falls at the 0.625 millisecond threshold.

By the way, the average time in this study was 0.129 milliseconds.  So on a sim with 50 avatars, we could expect that 50 * 0.129 = 6.45 milliseconds of script time would be used by the attachments worn by avatars during each sim frame.  This could represent a third to a half of all the script time being used on the sim.

In my next installment, I’ll focus on how people can find out what their script use is, and what are the common offenders in typical attachments worn.  Using these statistics, I also plan to create an object that will monitor script use on a sim and optionally advise people who are high users and perhaps even eject them from the region.  More to come …

Advertisements

~ by monicabalut on November 18, 2012.

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

 
%d bloggers like this: