Difference between revisions of "Resource Impact Calculator"

From Second Life Wiki
Jump to navigation Jump to search
(Created page with "{{LSL Header}} ====Resource Impact Calculator==== <lsl> /* Sim resource impact calculator. Call impactCPU(uuid) or/and impactRAM(uuid) to get the percentage of allowed resour…")
 
m (<lsl> tag to <source>)
 
(7 intermediate revisions by one other user not shown)
Line 1: Line 1:
{{LSL Header}}
{{LSL Header}}
====Resource Impact Calculator====
====Resource Impact Calculator caused by Avatars====
Use to control the lag caused by avatars, maximizing sim's performance.


Takes into account how many avatars are in the sim, for proper load balancing,
which means that if the sim is empty, all RAM/CPU is allowed for use for a single avatar, since it wont cause an impact on performance.


<lsl>
<source lang="lsl2">
/*
/*
  Sim resource impact calculator.
  Sim resource impact calculator  
  Call impactCPU(uuid) or/and impactRAM(uuid) to get the percentage of allowed resources the avatar is using.
  Call impactCPU(uuid) or/and impactRAM(uuid) to get the percentage of allowed resources the avatar is using.
  Data returned is integer type [0-100].
  Data returned is integer type [0-100].
*/
*/
integer maxRAM=200000000; // 200MB server RAM is usually what simulators use for scripting
integer maxRAM=209715200; //bytes- 200MB server RAM is usually what simulators use for scripting
float maxload=0.040;// Maximum allowed latency in miliseconds due scripting load on the simulator, 40-80ms is normal.
float maxload=0.040;//seconds- Maximum allowed latency in miliseconds due scripting load on the simulator, 40-80ms is normal.
integer maxavi=100;// Avatars the simulator can host.


integer impactCPU(key id){
integer impactCPU(key id){
return (integer)(llList2Float(llGetObjectDetails(id, [OBJECT_SCRIPT_TIME]), 0)/(maxload/maxavi*maxavi/llGetRegionAgentCount())*100);
return (integer)(llList2Float(llGetObjectDetails(id, [OBJECT_SCRIPT_TIME]), 0)/(maxload/llGetRegionAgentCount())*100);
}
}
integer impactRAM(key id){
integer impactRAM(key id){
return (integer)(llList2Float(llGetObjectDetails(id, [OBJECT_SCRIPT_MEMORY]), 0)/(maxRAM/maxavi*maxavi/llGetRegionAgentCount())*100);
return (integer)(llList2Float(llGetObjectDetails(id, [OBJECT_SCRIPT_MEMORY]), 0)/(maxRAM/llGetRegionAgentCount())*100);
}
}


Line 23: Line 25:
default
default
{
{
   
   touch_start(integer num_detected) {
   touch_start(integer num_detected) {
     key id=llDetectedKey(0);
     key id=llDetectedKey(0);
Line 29: Line 31:
     llInstantMessage(id,"RAM usage: "+(string)(impactRAM(id))+"%");//example of informational message
     llInstantMessage(id,"RAM usage: "+(string)(impactRAM(id))+"%");//example of informational message
     if(impactRAM(id)>100)llInstantMessage(id,"You've hit the memory usage limit."); //example of warning message
     if(impactRAM(id)>100)llInstantMessage(id,"You've hit the memory usage limit."); //example of warning message
  if(impactCPU(id)>100)llInstantMessage(id,"You've hit the CPU usage limit.");  
      if(impactCPU(id)>100)llInstantMessage(id,"You've hit the CPU usage limit.");  
      
      
     }
     }
}
}
</lsl>
</source>


[[Category:LSL Examples]]
[[Category:LSL Examples]]

Latest revision as of 17:44, 24 January 2015

Resource Impact Calculator caused by Avatars

Use to control the lag caused by avatars, maximizing sim's performance.

Takes into account how many avatars are in the sim, for proper load balancing, which means that if the sim is empty, all RAM/CPU is allowed for use for a single avatar, since it wont cause an impact on performance.

/*
 Sim resource impact calculator 
 Call impactCPU(uuid) or/and impactRAM(uuid) to get the percentage of allowed resources the avatar is using.
 Data returned is integer type [0-100].
*/
integer maxRAM=209715200; //bytes- 200MB server RAM is usually what simulators use for scripting
float maxload=0.040;//seconds- Maximum allowed latency in miliseconds due scripting load on the simulator, 40-80ms is normal.

integer impactCPU(key id){
return (integer)(llList2Float(llGetObjectDetails(id, [OBJECT_SCRIPT_TIME]), 0)/(maxload/llGetRegionAgentCount())*100);
}
integer impactRAM(key id){
return (integer)(llList2Float(llGetObjectDetails(id, [OBJECT_SCRIPT_MEMORY]), 0)/(maxRAM/llGetRegionAgentCount())*100);
}


default
{
    
   touch_start(integer num_detected) {
    key id=llDetectedKey(0);
    llInstantMessage(id,"CPU usage: "+(string)(impactCPU(id))+"%");
    llInstantMessage(id,"RAM usage: "+(string)(impactRAM(id))+"%");//example of informational message
    if(impactRAM(id)>100)llInstantMessage(id,"You've hit the memory usage limit."); //example of warning message
      if(impactCPU(id)>100)llInstantMessage(id,"You've hit the CPU usage limit."); 
    
    }
}