diff --git a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/MaintenanceThread.cs b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/MaintenanceThread.cs index 0458a50ba6..c329246df8 100644 --- a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/MaintenanceThread.cs +++ b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/MaintenanceThread.cs @@ -41,6 +41,9 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase { //public ScriptEngine m_ScriptEngine; private int MaintenanceLoopms; + private int MaintenanceLoopTicks_ScriptLoadUnload; + private int MaintenanceLoopTicks_Other; + public MaintenanceThread() { @@ -63,6 +66,9 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase foreach (ScriptEngine m_ScriptEngine in ScriptEngine.ScriptEngines) { MaintenanceLoopms = m_ScriptEngine.ScriptConfigSource.GetInt("MaintenanceLoopms", 50); + MaintenanceLoopTicks_ScriptLoadUnload = m_ScriptEngine.ScriptConfigSource.GetInt("MaintenanceLoopTicks_ScriptLoadUnload", 1); + MaintenanceLoopTicks_Other = m_ScriptEngine.ScriptConfigSource.GetInt("MaintenanceLoopTicks_Other", 10); + return; } } @@ -123,6 +129,10 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase long Last_maxFunctionExecutionTimens = 0; // DateTime.Now.Ticks; long Last_ReReadConfigFilens = DateTime.Now.Ticks; + long Last_MaintenanceRun = 0; + int MaintenanceLoopTicks_ScriptLoadUnload_Count = 0; + int MaintenanceLoopTicks_Other_Count = 0; + while (true) { try @@ -132,15 +142,20 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase System.Threading.Thread.Sleep(MaintenanceLoopms); // Sleep before next pass //if (PleaseShutdown) // return; + MaintenanceLoopTicks_ScriptLoadUnload_Count++; + MaintenanceLoopTicks_Other_Count++; + foreach (ScriptEngine m_ScriptEngine in new ArrayList(ScriptEngine.ScriptEngines)) { lastScriptEngine = m_ScriptEngine; - if (m_ScriptEngine != null) + // Re-reading config every x seconds + if (m_ScriptEngine.RefreshConfigFilens > 0) { - // Re-reading config every x seconds - if (m_ScriptEngine.RefreshConfigFilens > 0) + + if (MaintenanceLoopTicks_Other_Count >= MaintenanceLoopTicks_Other) { + MaintenanceLoopTicks_Other_Count = 0; // Check if its time to re-read config if (DateTime.Now.Ticks - Last_ReReadConfigFilens > m_ScriptEngine.RefreshConfigFilens) @@ -150,29 +165,33 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase m_ScriptEngine.ReadConfig(); Last_ReReadConfigFilens = DateTime.Now.Ticks; // Reset time } - } - // Adjust number of running script threads if not correct - if (m_ScriptEngine.m_EventQueueManager != null) - m_ScriptEngine.m_EventQueueManager.AdjustNumberOfScriptThreads(); - // Check if any script has exceeded its max execution time - if (EventQueueManager.EnforceMaxExecutionTime) - { - // We are enforcing execution time - if (DateTime.Now.Ticks - Last_maxFunctionExecutionTimens > - EventQueueManager.maxFunctionExecutionTimens) + // Adjust number of running script threads if not correct + if (m_ScriptEngine.m_EventQueueManager != null) + m_ScriptEngine.m_EventQueueManager.AdjustNumberOfScriptThreads(); + + // Check if any script has exceeded its max execution time + if (EventQueueManager.EnforceMaxExecutionTime) { - // Its time to check again - m_ScriptEngine.m_EventQueueManager.CheckScriptMaxExecTime(); // Do check - Last_maxFunctionExecutionTimens = DateTime.Now.Ticks; // Reset time + // We are enforcing execution time + if (DateTime.Now.Ticks - Last_maxFunctionExecutionTimens > + EventQueueManager.maxFunctionExecutionTimens) + { + // Its time to check again + m_ScriptEngine.m_EventQueueManager.CheckScriptMaxExecTime(); // Do check + Last_maxFunctionExecutionTimens = DateTime.Now.Ticks; // Reset time + } } } - // LOAD / UNLOAD SCRIPTS - if (m_ScriptEngine.m_ScriptManager != null) - m_ScriptEngine.m_ScriptManager.DoScriptLoadUnload(); - + if (MaintenanceLoopTicks_ScriptLoadUnload_Count >= MaintenanceLoopTicks_ScriptLoadUnload) + { + MaintenanceLoopTicks_ScriptLoadUnload_Count = 0; + // LOAD / UNLOAD SCRIPTS + if (m_ScriptEngine.m_ScriptManager != null) + m_ScriptEngine.m_ScriptManager.DoScriptLoadUnload(); + } } } } diff --git a/bin/OpenSim.ini.example b/bin/OpenSim.ini.example index 732530b76b..793fe5b3ac 100644 --- a/bin/OpenSim.ini.example +++ b/bin/OpenSim.ini.example @@ -171,8 +171,8 @@ msgformat = "PRIVMSG {0} : {3} - {1} of {2}" ; Refresh ScriptEngine config options (these settings) every xx seconds ; 0 = Do not refresh ; Set it to number of seconds between refresh, for example 30. -; Will allow you to change ScriptEngine settings while server is running just by editing this file. -; For example to increase or decrease number of threads. +; Will allow you to change ScriptEngine settings while server is running just by using "CONFIG SET" on console +; For example to increase or decrease number of threads: CONFIG SET NumberOfScriptThreads 10 ; NOTE! Disabled for now. Feature does not work. RefreshConfig=0 @@ -184,14 +184,6 @@ NumberOfScriptThreads=2 ; Valid values: Lowest, BelowNormal, Normal, AboveNormal, Highest ScriptThreadPriority=BelowNormal -; Should the script threads be private for each region? -; true: Each region will get dedicated to scripts within that region -; Number of threads will be * -; false: All regions share for all their scripts -; Note! If you run multiple script engines based on "OpenSim.Region.ScriptEngine.Common" then all of them will share the same threads. -; *** This setting will not work until you restart OpenSim -PrivateRegionThreads=false - ; How long MAX should a script event be allowed to run (per event execution)? ; Do not set this too low (like 50ms) as there are some time wasted in simply executing a function ; There is also a small speed penalty for every kill that is made @@ -222,11 +214,22 @@ ScriptsPerAppDomain=1 ; How long load/unload thread should sleep if there is nothing to do ; Higher value makes it respond slower when scripts are added/removed from prims ; But once active it will process all in queue before sleeping again -ScriptLoadUnloadLoopms=30 -; Loading and unloading of scripts is queued and processed by a separate thread. -; This thread can either be shared among all regions, or private (one thread per region) -PrivateScriptLoadUnloadThread=false + +; MaintenanceLoop +; How often to run maintenance loop +; Maintenance loop is doing: script compile/load, script unload, reload config, adjust running config and enforce max execution time +MaintenanceLoopms=50 + +; How many maintenanceloops between each of these. +; (if 2 then function will be executed every MaintenanceLoopms*2 ms) +; Script loading/unloading +MaintenanceLoopTicks_ScriptLoadUnload=1 + +; Other tasks +; check if we need to reload config, adjust running config and enforce max execution time +MaintenanceLoopTicks_Other=10 + ; Maximum number of items in load/unload queue before we start rejecting loads ; Note that we will only be rejecting load. Unloads will still be able to queue.