From this commit and a few hours into the future ScriptEngine will be unstable:

* Speeding up ScriptEngine shutdown
* Sharing threads so that minimum total thread count for any amount of regions will be 2. (1 maintenance, 1 script execution)
You can choose more script exec threads if you want of course.
In this commit: Sharing maintenance thread between all regions.
afrisby-rexmerge
Tedd Hansen 2008-02-22 12:50:24 +00:00
parent ff12395a3d
commit a040008cb9
5 changed files with 87 additions and 79 deletions

View File

@ -452,14 +452,14 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
} }
#endregion #endregion
/// <summary> ///// <summary>
/// If set to true then threads and stuff should try to make a graceful exit ///// If set to true then threads and stuff should try to make a graceful exit
/// </summary> ///// </summary>
public bool PleaseShutdown //public bool PleaseShutdown
{ //{
get { return _PleaseShutdown; } // get { return _PleaseShutdown; }
set { _PleaseShutdown = value; } // set { _PleaseShutdown = value; }
} //}
private bool _PleaseShutdown = false; //private bool _PleaseShutdown = false;
} }
} }

View File

@ -38,12 +38,12 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
/// </summary> /// </summary>
public class MaintenanceThread : iScriptEngineFunctionModule public class MaintenanceThread : iScriptEngineFunctionModule
{ {
public ScriptEngine m_ScriptEngine; //public ScriptEngine m_ScriptEngine;
private int MaintenanceLoopms; private int MaintenanceLoopms;
public MaintenanceThread(ScriptEngine _ScriptEngine) public MaintenanceThread()
{ {
m_ScriptEngine = _ScriptEngine; //m_ScriptEngine = _ScriptEngine;
ReadConfig(); ReadConfig();
@ -95,9 +95,9 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
try try
{ {
if (MaintenanceThreadThread != null && MaintenanceThreadThread.IsAlive) if (MaintenanceThreadThread != null && MaintenanceThreadThread.IsAlive)
{ {
MaintenanceThreadThread.Abort(); MaintenanceThreadThread.Abort();
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -105,14 +105,15 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
} }
} }
private ScriptEngine lastScriptEngine; // Keep track of what ScriptEngine instance we are at so we can give exception
/// <summary> /// <summary>
/// A thread should run in this loop and check all running scripts /// A thread should run in this loop and check all running scripts
/// </summary> /// </summary>
public void MaintenanceLoop() public void MaintenanceLoop()
{ {
if (m_ScriptEngine.m_EventQueueManager.maxFunctionExecutionTimens < MaintenanceLoopms) //if (m_ScriptEngine.m_EventQueueManager.maxFunctionExecutionTimens < MaintenanceLoopms)
m_ScriptEngine.Log.Warn("[" + m_ScriptEngine.ScriptEngineName + "]: " + // m_ScriptEngine.Log.Warn("[" + m_ScriptEngine.ScriptEngineName + "]: " +
"Configuration error: MaxEventExecutionTimeMs is less than MaintenanceLoopms. The Maintenance Loop will only check scripts once per run."); // "Configuration error: MaxEventExecutionTimeMs is less than MaintenanceLoopms. The Maintenance Loop will only check scripts once per run.");
long Last_maxFunctionExecutionTimens = 0; // DateTime.Now.Ticks; long Last_maxFunctionExecutionTimens = 0; // DateTime.Now.Ticks;
long Last_ReReadConfigFilens = DateTime.Now.Ticks; long Last_ReReadConfigFilens = DateTime.Now.Ticks;
@ -126,35 +127,41 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
if (PleaseShutdown) if (PleaseShutdown)
return; return;
if (m_ScriptEngine != null) foreach (ScriptEngine m_ScriptEngine in ScriptEngine.ScriptEngines)
{ {
// Re-reading config every x seconds lastScriptEngine = m_ScriptEngine;
if (m_ScriptEngine.RefreshConfigFilens > 0) if (m_ScriptEngine != null)
{ {
// Check if its time to re-read config // Re-reading config every x seconds
if (DateTime.Now.Ticks - Last_ReReadConfigFilens > m_ScriptEngine.RefreshConfigFilens) if (m_ScriptEngine.RefreshConfigFilens > 0)
{ {
//Console.WriteLine("Time passed: " + (DateTime.Now.Ticks - Last_ReReadConfigFilens) + ">" + m_ScriptEngine.RefreshConfigFilens ); // Check if its time to re-read config
// Its time to re-read config file if (DateTime.Now.Ticks - Last_ReReadConfigFilens >
m_ScriptEngine.ReadConfig(); m_ScriptEngine.RefreshConfigFilens)
Last_ReReadConfigFilens = DateTime.Now.Ticks; // Reset time {
//Console.WriteLine("Time passed: " + (DateTime.Now.Ticks - Last_ReReadConfigFilens) + ">" + m_ScriptEngine.RefreshConfigFilens );
// Its time to re-read config file
m_ScriptEngine.ReadConfig();
Last_ReReadConfigFilens = DateTime.Now.Ticks; // Reset time
}
} }
}
// Adjust number of running script threads if not correct // Adjust number of running script threads if not correct
if (m_ScriptEngine.m_EventQueueManager != null) if (m_ScriptEngine.m_EventQueueManager != null)
m_ScriptEngine.m_EventQueueManager.AdjustNumberOfScriptThreads(); m_ScriptEngine.m_EventQueueManager.AdjustNumberOfScriptThreads();
// Check if any script has exceeded its max execution time // Check if any script has exceeded its max execution time
if (m_ScriptEngine.m_EventQueueManager != null && m_ScriptEngine.m_EventQueueManager.EnforceMaxExecutionTime) if (m_ScriptEngine.m_EventQueueManager != null &&
{ m_ScriptEngine.m_EventQueueManager.EnforceMaxExecutionTime)
// We are enforcing execution time
if (DateTime.Now.Ticks - Last_maxFunctionExecutionTimens >
m_ScriptEngine.m_EventQueueManager.maxFunctionExecutionTimens)
{ {
// Its time to check again // We are enforcing execution time
m_ScriptEngine.m_EventQueueManager.CheckScriptMaxExecTime(); // Do check if (DateTime.Now.Ticks - Last_maxFunctionExecutionTimens >
Last_maxFunctionExecutionTimens = DateTime.Now.Ticks; // Reset time m_ScriptEngine.m_EventQueueManager.maxFunctionExecutionTimens)
{
// Its time to check again
m_ScriptEngine.m_EventQueueManager.CheckScriptMaxExecTime(); // Do check
Last_maxFunctionExecutionTimens = DateTime.Now.Ticks; // Reset time
}
} }
} }
} }
@ -162,7 +169,7 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
} }
catch (Exception ex) catch (Exception ex)
{ {
m_ScriptEngine.Log.Error("[" + m_ScriptEngine.ScriptEngineName + "]: Exception in MaintenanceLoopThread. Thread will recover after 5 sec throttle. Exception: " + ex.ToString()); ScriptEngine.Log.Error("[" + lastScriptEngine.ScriptEngineName + "]: Exception in MaintenanceLoopThread. Thread will recover after 5 sec throttle. Exception: " + ex.ToString());
Thread.Sleep(5000); Thread.Sleep(5000);
} }
} }

View File

@ -27,6 +27,7 @@
*/ */
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using Nini.Config; using Nini.Config;
using OpenSim.Framework.Console; using OpenSim.Framework.Console;
@ -46,13 +47,14 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
{ {
private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public static List<ScriptEngine> ScriptEngines = new List<ScriptEngine>();
public Scene World; public Scene World;
public EventManager m_EventManager; // Handles and queues incoming events from OpenSim public EventManager m_EventManager; // Handles and queues incoming events from OpenSim
public EventQueueManager m_EventQueueManager; // Executes events, handles script threads public EventQueueManager m_EventQueueManager; // Executes events, handles script threads
public ScriptManager m_ScriptManager; // Load, unload and execute scripts public ScriptManager m_ScriptManager; // Load, unload and execute scripts
public AppDomainManager m_AppDomainManager; // Handles loading/unloading of scripts into AppDomains public AppDomainManager m_AppDomainManager; // Handles loading/unloading of scripts into AppDomains
public AsyncLSLCommandManager m_ASYNCLSLCommandManager; // Asyncronous LSL commands (commands that returns with an event) public AsyncLSLCommandManager m_ASYNCLSLCommandManager; // Asyncronous LSL commands (commands that returns with an event)
public MaintenanceThread m_MaintenanceThread; // Thread that does different kinds of maintenance, for example refreshing config and killing scripts that has been running too long public static MaintenanceThread m_MaintenanceThread; // Thread that does different kinds of maintenance, for example refreshing config and killing scripts that has been running too long
public IConfigSource ConfigSource; public IConfigSource ConfigSource;
public IConfig ScriptConfigSource; public IConfig ScriptConfigSource;
@ -74,15 +76,15 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
public abstract ScriptManager _GetScriptManager(); public abstract ScriptManager _GetScriptManager();
public log4net.ILog Log public static log4net.ILog Log
{ {
get { return m_log; } get { return m_log; }
} }
public ScriptEngine() public ScriptEngine()
{ {
//Common.SendToDebug("ScriptEngine Object Initialized"); Common.mySE = this; // For logging, just need any instance, doesn't matter
Common.mySE = this; ScriptEngines.Add(this); // Keep a list of ScriptEngines for shared threads to process all instances
} }
public void InitializeEngine(Scene Sceneworld, IConfigSource config, bool HookUpToServer, ScriptManager newScriptManager) public void InitializeEngine(Scene Sceneworld, IConfigSource config, bool HookUpToServer, ScriptManager newScriptManager)
@ -106,7 +108,8 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
m_ScriptManager = newScriptManager; m_ScriptManager = newScriptManager;
m_AppDomainManager = new AppDomainManager(this); m_AppDomainManager = new AppDomainManager(this);
m_ASYNCLSLCommandManager = new AsyncLSLCommandManager(this); m_ASYNCLSLCommandManager = new AsyncLSLCommandManager(this);
m_MaintenanceThread = new MaintenanceThread(this); if (m_MaintenanceThread == null)
m_MaintenanceThread = new MaintenanceThread();
m_log.Info("[" + ScriptEngineName + "]: Reading configuration from config section \"" + ScriptEngineName + "\""); m_log.Info("[" + ScriptEngineName + "]: Reading configuration from config section \"" + ScriptEngineName + "\"");
ReadConfig(); ReadConfig();
@ -118,6 +121,7 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
public void Shutdown() public void Shutdown()
{ {
// We are shutting down // We are shutting down
ScriptEngines.Remove(this);
} }
ScriptServerInterfaces.RemoteEvents ScriptServerInterfaces.ScriptEngine.EventManager() ScriptServerInterfaces.RemoteEvents ScriptServerInterfaces.ScriptEngine.EventManager()
@ -178,12 +182,12 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
/// <summary> /// <summary>
/// If set to true then threads and stuff should try to make a graceful exit /// If set to true then threads and stuff should try to make a graceful exit
/// </summary> /// </summary>
public bool PleaseShutdown //public bool PleaseShutdown
{ //{
get { return _PleaseShutdown; } // get { return _PleaseShutdown; }
set { _PleaseShutdown = value; } // set { _PleaseShutdown = value; }
} //}
private bool _PleaseShutdown = false; //private bool _PleaseShutdown = false;
} }
} }

View File

@ -169,15 +169,12 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
// Abort load/unload thread // Abort load/unload thread
try try
{ {
PleaseShutdown = true; //PleaseShutdown = true;
Thread.Sleep(100); //Thread.Sleep(100);
if (scriptLoadUnloadThread != null) if (scriptLoadUnloadThread != null && scriptLoadUnloadThread.IsAlive == true)
{ {
if (scriptLoadUnloadThread.IsAlive == true) scriptLoadUnloadThread.Abort();
{ //scriptLoadUnloadThread.Join();
scriptLoadUnloadThread.Abort();
scriptLoadUnloadThread.Join();
}
} }
} }
catch catch
@ -282,7 +279,7 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
public abstract void _StartScript(uint localID, LLUUID itemID, string Script); public abstract void _StartScript(uint localID, LLUUID itemID, string Script);
public abstract void _StopScript(uint localID, LLUUID itemID); public abstract void _StopScript(uint localID, LLUUID itemID);
#endregion #endregion
@ -297,10 +294,10 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
/// <param name="args">Arguments to pass to function</param> /// <param name="args">Arguments to pass to function</param>
internal void ExecuteEvent(uint localID, LLUUID itemID, string FunctionName, EventQueueManager.Queue_llDetectParams_Struct qParams, object[] args) internal void ExecuteEvent(uint localID, LLUUID itemID, string FunctionName, EventQueueManager.Queue_llDetectParams_Struct qParams, object[] args)
{ {
//cfk 2-7-08 dont need this right now and the default Linux build has DEBUG defined //cfk 2-7-08 dont need this right now and the default Linux build has DEBUG defined
///#if DEBUG ///#if DEBUG
/// Console.WriteLine("ScriptEngine: Inside ExecuteEvent for event " + FunctionName); /// Console.WriteLine("ScriptEngine: Inside ExecuteEvent for event " + FunctionName);
///#endif ///#endif
// Execute a function in the script // Execute a function in the script
//m_scriptEngine.Log.Info("[" + ScriptEngineName + "]: Executing Function localID: " + localID + ", itemID: " + itemID + ", FunctionName: " + FunctionName); //m_scriptEngine.Log.Info("[" + ScriptEngineName + "]: Executing Function localID: " + localID + ", itemID: " + itemID + ", FunctionName: " + FunctionName);
//ScriptBaseInterface Script = (ScriptBaseInterface)GetScript(localID, itemID); //ScriptBaseInterface Script = (ScriptBaseInterface)GetScript(localID, itemID);
@ -309,10 +306,10 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
{ {
return; return;
} }
//cfk 2-7-08 dont need this right now and the default Linux build has DEBUG defined //cfk 2-7-08 dont need this right now and the default Linux build has DEBUG defined
///#if DEBUG ///#if DEBUG
/// Console.WriteLine("ScriptEngine: Executing event: " + FunctionName); /// Console.WriteLine("ScriptEngine: Executing event: " + FunctionName);
///#endif ///#endif
// Must be done in correct AppDomain, so leaving it up to the script itself // Must be done in correct AppDomain, so leaving it up to the script itself
Script.llDetectParams = qParams; Script.llDetectParams = qParams;
Script.Exec.ExecuteEvent(FunctionName, args); Script.Exec.ExecuteEvent(FunctionName, args);
@ -418,15 +415,15 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
#endregion #endregion
/// <summary> ///// <summary>
/// If set to true then threads and stuff should try to make a graceful exit ///// If set to true then threads and stuff should try to make a graceful exit
/// </summary> ///// </summary>
public bool PleaseShutdown //public bool PleaseShutdown
{ //{
get { return _PleaseShutdown; } // get { return _PleaseShutdown; }
set { _PleaseShutdown = value; } // set { _PleaseShutdown = value; }
} //}
private bool _PleaseShutdown = false; //private bool _PleaseShutdown = false;
} }
} }

View File

@ -35,6 +35,6 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
public interface iScriptEngineFunctionModule public interface iScriptEngineFunctionModule
{ {
void ReadConfig(); void ReadConfig();
bool PleaseShutdown { get; set; } // bool PleaseShutdown { get; set; }
} }
} }