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
/// <summary>
/// If set to true then threads and stuff should try to make a graceful exit
/// </summary>
public bool PleaseShutdown
{
get { return _PleaseShutdown; }
set { _PleaseShutdown = value; }
}
private bool _PleaseShutdown = false;
///// <summary>
///// If set to true then threads and stuff should try to make a graceful exit
///// </summary>
//public bool PleaseShutdown
//{
// get { return _PleaseShutdown; }
// set { _PleaseShutdown = value; }
//}
//private bool _PleaseShutdown = false;
}
}

View File

@ -38,12 +38,12 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
/// </summary>
public class MaintenanceThread : iScriptEngineFunctionModule
{
public ScriptEngine m_ScriptEngine;
//public ScriptEngine m_ScriptEngine;
private int MaintenanceLoopms;
public MaintenanceThread(ScriptEngine _ScriptEngine)
public MaintenanceThread()
{
m_ScriptEngine = _ScriptEngine;
//m_ScriptEngine = _ScriptEngine;
ReadConfig();
@ -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>
/// A thread should run in this loop and check all running scripts
/// </summary>
public void MaintenanceLoop()
{
if (m_ScriptEngine.m_EventQueueManager.maxFunctionExecutionTimens < MaintenanceLoopms)
m_ScriptEngine.Log.Warn("[" + m_ScriptEngine.ScriptEngineName + "]: " +
"Configuration error: MaxEventExecutionTimeMs is less than MaintenanceLoopms. The Maintenance Loop will only check scripts once per run.");
//if (m_ScriptEngine.m_EventQueueManager.maxFunctionExecutionTimens < MaintenanceLoopms)
// m_ScriptEngine.Log.Warn("[" + m_ScriptEngine.ScriptEngineName + "]: " +
// "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_ReReadConfigFilens = DateTime.Now.Ticks;
@ -126,13 +127,17 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
if (PleaseShutdown)
return;
foreach (ScriptEngine m_ScriptEngine in ScriptEngine.ScriptEngines)
{
lastScriptEngine = m_ScriptEngine;
if (m_ScriptEngine != null)
{
// Re-reading config every x seconds
if (m_ScriptEngine.RefreshConfigFilens > 0)
{
// Check if its time to re-read config
if (DateTime.Now.Ticks - Last_ReReadConfigFilens > m_ScriptEngine.RefreshConfigFilens)
if (DateTime.Now.Ticks - Last_ReReadConfigFilens >
m_ScriptEngine.RefreshConfigFilens)
{
//Console.WriteLine("Time passed: " + (DateTime.Now.Ticks - Last_ReReadConfigFilens) + ">" + m_ScriptEngine.RefreshConfigFilens );
// Its time to re-read config file
@ -146,7 +151,8 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
m_ScriptEngine.m_EventQueueManager.AdjustNumberOfScriptThreads();
// 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 >
@ -160,9 +166,10 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
}
}
}
}
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);
}
}

View File

@ -27,6 +27,7 @@
*/
using System;
using System.Collections.Generic;
using System.IO;
using Nini.Config;
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);
public static List<ScriptEngine> ScriptEngines = new List<ScriptEngine>();
public Scene World;
public EventManager m_EventManager; // Handles and queues incoming events from OpenSim
public EventQueueManager m_EventQueueManager; // Executes events, handles script threads
public ScriptManager m_ScriptManager; // Load, unload and execute scripts
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 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 IConfig ScriptConfigSource;
@ -74,15 +76,15 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
public abstract ScriptManager _GetScriptManager();
public log4net.ILog Log
public static log4net.ILog Log
{
get { return m_log; }
}
public ScriptEngine()
{
//Common.SendToDebug("ScriptEngine Object Initialized");
Common.mySE = this;
Common.mySE = this; // For logging, just need any instance, doesn't matter
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)
@ -106,7 +108,8 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
m_ScriptManager = newScriptManager;
m_AppDomainManager = new AppDomainManager(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 + "\"");
ReadConfig();
@ -118,6 +121,7 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
public void Shutdown()
{
// We are shutting down
ScriptEngines.Remove(this);
}
ScriptServerInterfaces.RemoteEvents ScriptServerInterfaces.ScriptEngine.EventManager()
@ -178,12 +182,12 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
/// <summary>
/// If set to true then threads and stuff should try to make a graceful exit
/// </summary>
public bool PleaseShutdown
{
get { return _PleaseShutdown; }
set { _PleaseShutdown = value; }
}
private bool _PleaseShutdown = false;
//public bool PleaseShutdown
//{
// get { return _PleaseShutdown; }
// set { _PleaseShutdown = value; }
//}
//private bool _PleaseShutdown = false;
}
}

View File

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

View File

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