More performance improvements to XEngine script loading

0.6.8-post-fixes
John Hurliman 2009-10-29 06:42:40 -07:00
parent dd13fa361b
commit ec7fd8b1f8
2 changed files with 37 additions and 54 deletions

View File

@ -74,27 +74,27 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
private string m_PrimName; private string m_PrimName;
private string m_ScriptName; private string m_ScriptName;
private string m_Assembly; private string m_Assembly;
private int m_StartParam = 0; private int m_StartParam;
private string m_CurrentEvent = String.Empty; private string m_CurrentEvent = String.Empty;
private bool m_InSelfDelete = false; private bool m_InSelfDelete;
private int m_MaxScriptQueue; private int m_MaxScriptQueue;
private bool m_SaveState = true; private bool m_SaveState = true;
private bool m_ShuttingDown = false; private bool m_ShuttingDown;
private int m_ControlEventsInQueue = 0; private int m_ControlEventsInQueue;
private int m_LastControlLevel = 0; private int m_LastControlLevel;
private bool m_CollisionInQueue = false; private bool m_CollisionInQueue;
private TaskInventoryItem m_thisScriptTask; private TaskInventoryItem m_thisScriptTask;
// The following is for setting a minimum delay between events // The following is for setting a minimum delay between events
private double m_minEventDelay = 0; private double m_minEventDelay;
private long m_eventDelayTicks = 0; private long m_eventDelayTicks;
private long m_nextEventTimeTicks = 0; private long m_nextEventTimeTicks;
private bool m_startOnInit = true; private bool m_startOnInit = true;
private UUID m_AttachedAvatar = UUID.Zero; private UUID m_AttachedAvatar;
private StateSource m_stateSource; private StateSource m_stateSource;
private bool m_postOnRez; private bool m_postOnRez;
private bool m_startedFromSavedState = false; private bool m_startedFromSavedState;
private UUID m_CurrentStateHash; private UUID m_CurrentStateHash;
private UUID m_RegionID = UUID.Zero; private UUID m_RegionID;
private Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> private Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>>
m_LineMap; m_LineMap;

View File

@ -50,6 +50,9 @@ using OpenSim.Region.ScriptEngine.Shared.CodeTools;
using OpenSim.Region.ScriptEngine.Shared.Instance; using OpenSim.Region.ScriptEngine.Shared.Instance;
using OpenSim.Region.ScriptEngine.Interfaces; using OpenSim.Region.ScriptEngine.Interfaces;
using ScriptCompileQueue = OpenSim.Framework.LocklessQueue<object[]>;
using Parallel = OpenSim.Framework.Parallel;
namespace OpenSim.Region.ScriptEngine.XEngine namespace OpenSim.Region.ScriptEngine.XEngine
{ {
public class XEngine : INonSharedRegionModule, IScriptModule, IScriptEngine public class XEngine : INonSharedRegionModule, IScriptModule, IScriptEngine
@ -116,7 +119,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
private Dictionary<UUID, List<UUID> > m_DomainScripts = private Dictionary<UUID, List<UUID> > m_DomainScripts =
new Dictionary<UUID, List<UUID> >(); new Dictionary<UUID, List<UUID> >();
private Queue m_CompileQueue = new Queue(100); private ScriptCompileQueue m_CompileQueue = new ScriptCompileQueue();
IWorkItemResult m_CurrentCompile = null; IWorkItemResult m_CurrentCompile = null;
public string ScriptEngineName public string ScriptEngineName
@ -486,17 +489,12 @@ namespace OpenSim.Region.ScriptEngine.XEngine
DoOnRezScript(parms); DoOnRezScript(parms);
} }
else else
{
lock (m_CompileQueue)
{ {
m_CompileQueue.Enqueue(parms); m_CompileQueue.Enqueue(parms);
if (m_CurrentCompile == null) if (m_CurrentCompile == null)
{ {
m_CurrentCompile = m_ThreadPool.QueueWorkItem( m_CurrentCompile = m_ThreadPool.QueueWorkItem(DoOnRezScriptQueue, null);
new WorkItemCallback(this.DoOnRezScriptQueue),
new Object[0]);
}
} }
} }
} }
@ -507,50 +505,35 @@ namespace OpenSim.Region.ScriptEngine.XEngine
{ {
m_InitialStartup = false; m_InitialStartup = false;
System.Threading.Thread.Sleep(15000); System.Threading.Thread.Sleep(15000);
lock (m_CompileQueue)
if (m_CompileQueue.Count == 0)
{ {
if (m_CompileQueue.Count==0)
// No scripts on region, so won't get triggered later // No scripts on region, so won't get triggered later
// by the queue becoming empty so we trigger it here // by the queue becoming empty so we trigger it here
m_Scene.EventManager.TriggerEmptyScriptCompileQueue(0, String.Empty); m_Scene.EventManager.TriggerEmptyScriptCompileQueue(0, String.Empty);
} }
} }
Object o; List<object[]> compiles = new List<object[]>();
lock (m_CompileQueue) object[] o;
while (m_CompileQueue.Dequeue(out o))
{ {
o = m_CompileQueue.Dequeue(); compiles.Add(o);
if (o == null)
{
m_CurrentCompile = null;
return null;
}
} }
DoOnRezScript(o); Parallel.For(0, compiles.Count, delegate(int i) { DoOnRezScript(compiles[i]); });
lock (m_CompileQueue)
{
if (m_CompileQueue.Count > 0)
{
m_CurrentCompile = m_ThreadPool.QueueWorkItem(
new WorkItemCallback(this.DoOnRezScriptQueue),
new Object[0]);
}
else
{
m_CurrentCompile = null; m_CurrentCompile = null;
m_Scene.EventManager.TriggerEmptyScriptCompileQueue(m_ScriptFailCount, m_Scene.EventManager.TriggerEmptyScriptCompileQueue(m_ScriptFailCount,
m_ScriptErrorMessage); m_ScriptErrorMessage);
m_ScriptFailCount = 0; m_ScriptFailCount = 0;
}
}
return null; return null;
} }
private bool DoOnRezScript(object parm) private bool DoOnRezScript(object[] parms)
{ {
Object[] p = (Object[])parm; Object[] p = parms;
uint localID = (uint)p[0]; uint localID = (uint)p[0];
UUID itemID = (UUID)p[1]; UUID itemID = (UUID)p[1];
string script =(string)p[2]; string script =(string)p[2];