From ec7fd8b1f810a13e7f78448e9ef81113ed3c5bf0 Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Thu, 29 Oct 2009 06:42:40 -0700 Subject: [PATCH] More performance improvements to XEngine script loading --- .../Shared/Instance/ScriptInstance.cs | 24 +++---- .../Region/ScriptEngine/XEngine/XEngine.cs | 67 +++++++------------ 2 files changed, 37 insertions(+), 54 deletions(-) diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs index f16aefc946..549c038fc4 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs @@ -74,27 +74,27 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance private string m_PrimName; private string m_ScriptName; private string m_Assembly; - private int m_StartParam = 0; + private int m_StartParam; private string m_CurrentEvent = String.Empty; - private bool m_InSelfDelete = false; + private bool m_InSelfDelete; private int m_MaxScriptQueue; private bool m_SaveState = true; - private bool m_ShuttingDown = false; - private int m_ControlEventsInQueue = 0; - private int m_LastControlLevel = 0; - private bool m_CollisionInQueue = false; + private bool m_ShuttingDown; + private int m_ControlEventsInQueue; + private int m_LastControlLevel; + private bool m_CollisionInQueue; private TaskInventoryItem m_thisScriptTask; // The following is for setting a minimum delay between events - private double m_minEventDelay = 0; - private long m_eventDelayTicks = 0; - private long m_nextEventTimeTicks = 0; + private double m_minEventDelay; + private long m_eventDelayTicks; + private long m_nextEventTimeTicks; private bool m_startOnInit = true; - private UUID m_AttachedAvatar = UUID.Zero; + private UUID m_AttachedAvatar; private StateSource m_stateSource; private bool m_postOnRez; - private bool m_startedFromSavedState = false; + private bool m_startedFromSavedState; private UUID m_CurrentStateHash; - private UUID m_RegionID = UUID.Zero; + private UUID m_RegionID; private Dictionary, KeyValuePair> m_LineMap; diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs index b13e0de322..b0fce75112 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs @@ -50,6 +50,9 @@ using OpenSim.Region.ScriptEngine.Shared.CodeTools; using OpenSim.Region.ScriptEngine.Shared.Instance; using OpenSim.Region.ScriptEngine.Interfaces; +using ScriptCompileQueue = OpenSim.Framework.LocklessQueue; +using Parallel = OpenSim.Framework.Parallel; + namespace OpenSim.Region.ScriptEngine.XEngine { public class XEngine : INonSharedRegionModule, IScriptModule, IScriptEngine @@ -116,7 +119,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine private Dictionary > m_DomainScripts = new Dictionary >(); - private Queue m_CompileQueue = new Queue(100); + private ScriptCompileQueue m_CompileQueue = new ScriptCompileQueue(); IWorkItemResult m_CurrentCompile = null; public string ScriptEngineName @@ -487,16 +490,11 @@ namespace OpenSim.Region.ScriptEngine.XEngine } else { - lock (m_CompileQueue) - { - m_CompileQueue.Enqueue(parms); + m_CompileQueue.Enqueue(parms); - if (m_CurrentCompile == null) - { - m_CurrentCompile = m_ThreadPool.QueueWorkItem( - new WorkItemCallback(this.DoOnRezScriptQueue), - new Object[0]); - } + if (m_CurrentCompile == null) + { + m_CurrentCompile = m_ThreadPool.QueueWorkItem(DoOnRezScriptQueue, null); } } } @@ -507,50 +505,35 @@ namespace OpenSim.Region.ScriptEngine.XEngine { m_InitialStartup = false; 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 - // by the queue becoming empty so we trigger it here - m_Scene.EventManager.TriggerEmptyScriptCompileQueue(0, String.Empty); + // No scripts on region, so won't get triggered later + // by the queue becoming empty so we trigger it here + m_Scene.EventManager.TriggerEmptyScriptCompileQueue(0, String.Empty); } } - Object o; - lock (m_CompileQueue) + List compiles = new List(); + object[] o; + while (m_CompileQueue.Dequeue(out o)) { - o = m_CompileQueue.Dequeue(); - if (o == null) - { - m_CurrentCompile = null; - return null; - } + compiles.Add(o); } - DoOnRezScript(o); + Parallel.For(0, compiles.Count, delegate(int i) { DoOnRezScript(compiles[i]); }); + + m_CurrentCompile = null; + m_Scene.EventManager.TriggerEmptyScriptCompileQueue(m_ScriptFailCount, + m_ScriptErrorMessage); + m_ScriptFailCount = 0; - 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_Scene.EventManager.TriggerEmptyScriptCompileQueue(m_ScriptFailCount, - m_ScriptErrorMessage); - m_ScriptFailCount = 0; - } - } return null; } - private bool DoOnRezScript(object parm) + private bool DoOnRezScript(object[] parms) { - Object[] p = (Object[])parm; + Object[] p = parms; uint localID = (uint)p[0]; UUID itemID = (UUID)p[1]; string script =(string)p[2];