From a43bb10000ca0b58af2f33750ea17cb94bfbad7d Mon Sep 17 00:00:00 2001 From: Tedd Hansen Date: Fri, 22 Feb 2008 14:09:38 +0000 Subject: Execution threads are now shared between regions too. Default thread count regardless of number of regions is now 3. This will save you around 33 threads for a normal 3x3 region server. But, this is totally completely untested. So it probably won't work for another patch or five. --- .../Common/ScriptEngineBase/EventQueueManager.cs | 64 ++++++---------------- 1 file changed, 18 insertions(+), 46 deletions(-) (limited to 'OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/EventQueueManager.cs') diff --git a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/EventQueueManager.cs b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/EventQueueManager.cs index e3d448c..581c7a0 100644 --- a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/EventQueueManager.cs +++ b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/EventQueueManager.cs @@ -45,7 +45,7 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase public class EventQueueManager : iScriptEngineFunctionModule { // - // Class is instanced in "ScriptEngine" and used by "EventManager" also instanced in "ScriptEngine". + // Class is instanced in "ScriptEngine" and used by "EventManager" which is also instanced in "ScriptEngine". // // Class purpose is to queue and execute functions that are received by "EventManager": // - allowing "EventManager" to release its event thread immediately, thus not interrupting server execution. @@ -68,25 +68,25 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase /// List of threads (classes) processing event queue /// Note that this may or may not be a reference to a static object depending on PrivateRegionThreads config setting. /// - internal List eventQueueThreads; // Thread pool that we work on + internal static List eventQueueThreads; // Thread pool that we work on /// /// Locking access to eventQueueThreads AND staticGlobalEventQueueThreads. /// // private object eventQueueThreadsLock = new object(); // Static objects for referencing the objects above if we don't have private threads: - internal static List staticEventQueueThreads; // A static reference used if we don't use private threads + //internal static List staticEventQueueThreads; // A static reference used if we don't use private threads // internal static object staticEventQueueThreadsLock; // Statick lock object reference for same reason /// /// Global static list of all threads (classes) processing event queue -- used by max enforcment thread /// - private List staticGlobalEventQueueThreads = new List(); + //private List staticGlobalEventQueueThreads = new List(); /// /// Used internally to specify how many threads should exit gracefully /// - public int ThreadsToExit; - public object ThreadsToExitLock = new object(); + public static int ThreadsToExit; + public static object ThreadsToExitLock = new object(); //public object queueLock = new object(); // Mutex lock object @@ -94,14 +94,14 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase /// /// How many threads to process queue with /// - internal int numberOfThreads; + internal static int numberOfThreads; internal static int EventExecutionMaxQueueSize; /// /// Maximum time one function can use for execution before we perform a thread kill. /// - private int maxFunctionExecutionTimems + private static int maxFunctionExecutionTimems { get { return (int)(maxFunctionExecutionTimens / 10000); } set { maxFunctionExecutionTimens = value * 10000; } @@ -111,15 +111,15 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase /// Contains nanoseconds version of maxFunctionExecutionTimems so that it matches time calculations better (performance reasons). /// WARNING! ONLY UPDATE maxFunctionExecutionTimems, NEVER THIS DIRECTLY. /// - public long maxFunctionExecutionTimens; + public static long maxFunctionExecutionTimens; /// /// Enforce max execution time /// - public bool EnforceMaxExecutionTime; + public static bool EnforceMaxExecutionTime; /// /// Kill script (unload) when it exceeds execution time /// - private bool KillScriptOnMaxFunctionExecutionTime; + private static bool KillScriptOnMaxFunctionExecutionTime; /// /// List of localID locks for mutex processing of script events @@ -172,33 +172,8 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase { m_ScriptEngine = _ScriptEngine; - // TODO: We need to move from single EventQueueManager to list of it in to share threads - bool PrivateRegionThreads = true; // m_ScriptEngine.ScriptConfigSource.GetBoolean("PrivateRegionThreads", false); - - // Create thread pool list and lock object - // Determine from config if threads should be dedicated to regions or shared - if (PrivateRegionThreads) - { - // PRIVATE THREAD POOL PER REGION - eventQueueThreads = new List(); - // eventQueueThreadsLock = new object(); - } - else - { - // SHARED THREAD POOL - // Crate the static objects - if (staticEventQueueThreads == null) - staticEventQueueThreads = new List(); - // if (staticEventQueueThreadsLock == null) - // staticEventQueueThreadsLock = new object(); - - // Now reference our locals to them - eventQueueThreads = staticEventQueueThreads; - //eventQueueThreadsLock = staticEventQueueThreadsLock; - } - + eventQueueThreads = new List(); ReadConfig(); - } public void ReadConfig() @@ -230,18 +205,18 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase private void Stop() { - if (eventQueueThreads != null && eventQueueThreads != null) + if (eventQueueThreads != null) { // Kill worker threads - //lock (eventQueueThreads) - //{ + lock (eventQueueThreads) + { foreach (EventQueueThreadClass EventQueueThread in new ArrayList(eventQueueThreads)) { AbortThreadClass(EventQueueThread); } //eventQueueThreads.Clear(); //staticGlobalEventQueueThreads.Clear(); - //} + } } // Remove all entries from our event queue @@ -256,9 +231,8 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase #region " Start / stop script execution threads (ThreadClasses) " private void StartNewThreadClass() { - EventQueueThreadClass eqtc = new EventQueueThreadClass(this); + EventQueueThreadClass eqtc = new EventQueueThreadClass(); eventQueueThreads.Add(eqtc); - staticGlobalEventQueueThreads.Add(eqtc); m_ScriptEngine.Log.Debug("[" + m_ScriptEngine.ScriptEngineName + "]: Started new script execution thread. Current thread count: " + eventQueueThreads.Count); } @@ -266,8 +240,6 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase { if (eventQueueThreads.Contains(threadClass)) eventQueueThreads.Remove(threadClass); - if (staticGlobalEventQueueThreads.Contains(threadClass)) - staticGlobalEventQueueThreads.Remove(threadClass); try { @@ -426,7 +398,7 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase // Iterate through all ScriptThreadClasses and check how long their current function has been executing lock (eventQueueThreads) { - foreach (EventQueueThreadClass EventQueueThread in staticGlobalEventQueueThreads) + foreach (EventQueueThreadClass EventQueueThread in eventQueueThreads) { // Is thread currently executing anything? if (EventQueueThread.InExecution) -- cgit v1.1