One more: Async LSL command thread is also shared now.

afrisby-rexmerge
Tedd Hansen 2008-02-22 22:24:12 +00:00
parent 9b675a6888
commit f06a6573bb
5 changed files with 289 additions and 264 deletions

View File

@ -41,28 +41,36 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
/// </summary> /// </summary>
public class AsyncLSLCommandManager : iScriptEngineFunctionModule public class AsyncLSLCommandManager : iScriptEngineFunctionModule
{ {
private Thread cmdHandlerThread; private static Thread cmdHandlerThread;
private int cmdHandlerThreadCycleSleepms; private int cmdHandlerThreadCycleSleepms;
private ScriptEngine m_ScriptEngine; private ScriptEngine m_ScriptEngine;
public AsyncLSLCommandManager(ScriptEngine _ScriptEngine) public AsyncLSLCommandManager()
{ {
m_ScriptEngine = _ScriptEngine; //m_ScriptEngine = _ScriptEngine;
ReadConfig(); ReadConfig();
StartThread();
}
private void StartThread()
{
if (cmdHandlerThread == null)
{
// Start the thread that will be doing the work // Start the thread that will be doing the work
cmdHandlerThread = new Thread(CmdHandlerThreadLoop); cmdHandlerThread = new Thread(CmdHandlerThreadLoop);
cmdHandlerThread.Name = "CmdHandlerThread"; cmdHandlerThread.Name = "AsyncLSLCmdHandlerThread";
cmdHandlerThread.Priority = ThreadPriority.BelowNormal; cmdHandlerThread.Priority = ThreadPriority.BelowNormal;
cmdHandlerThread.IsBackground = true; cmdHandlerThread.IsBackground = true;
cmdHandlerThread.Start(); cmdHandlerThread.Start();
OpenSim.Framework.ThreadTracker.Add(cmdHandlerThread); OpenSim.Framework.ThreadTracker.Add(cmdHandlerThread);
} }
}
public void ReadConfig() public void ReadConfig()
{ {
cmdHandlerThreadCycleSleepms = m_ScriptEngine.ScriptConfigSource.GetInt("AsyncLLCommandLoopms", 50); cmdHandlerThreadCycleSleepms = m_ScriptEngine.ScriptConfigSource.GetInt("AsyncLLCommandLoopms", 100);
} }
~AsyncLSLCommandManager() ~AsyncLSLCommandManager()
@ -88,29 +96,46 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
{ {
while (true) while (true)
{ {
// Check timers try
CheckTimerEvents(); {
Thread.Sleep(25); while (true)
// Check HttpRequests {
CheckHttpRequests(); Thread.Sleep(cmdHandlerThreadCycleSleepms);
Thread.Sleep(25); lock (ScriptEngine.ScriptEngines)
// Check XMLRPCRequests {
CheckXMLRPCRequests(); foreach (ScriptEngine se in ScriptEngine.ScriptEngines)
Thread.Sleep(25); {
// Check Listeners m_ScriptEngine = se;
CheckListeners(); m_ScriptEngine.m_ASYNCLSLCommandManager.DoOneCmdHandlerPass();
Thread.Sleep(25); }
}
// Sleep before next cycle // Sleep before next cycle
//Thread.Sleep(cmdHandlerThreadCycleSleepms); //Thread.Sleep(cmdHandlerThreadCycleSleepms);
} }
} }
catch
{
}
}
}
internal void DoOneCmdHandlerPass()
{
// Check timers
CheckTimerEvents();
// Check HttpRequests
CheckHttpRequests();
// Check XMLRPCRequests
CheckXMLRPCRequests();
// Check Listeners
CheckListeners();
}
/// <summary> /// <summary>
/// Remove a specific script (and all its pending commands) /// Remove a specific script (and all its pending commands)
/// </summary> /// </summary>
/// <param name="m_localID"></param> /// <param name="localID"></param>
/// <param name="m_itemID"></param> /// <param name="itemID"></param>
public void RemoveScript(uint localID, LLUUID itemID) public void RemoveScript(uint localID, LLUUID itemID)
{ {
// Remove a specific script // Remove a specific script

View File

@ -73,6 +73,8 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
public void ReadConfig() public void ReadConfig()
{ {
//lock (ScriptEngine.ScriptEngines)
//{
foreach (ScriptEngine m_ScriptEngine in new ArrayList(ScriptEngine.ScriptEngines)) foreach (ScriptEngine m_ScriptEngine in new ArrayList(ScriptEngine.ScriptEngines))
{ {
ScriptEngineName = m_ScriptEngine.ScriptEngineName; ScriptEngineName = m_ScriptEngine.ScriptEngineName;
@ -104,7 +106,7 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
break; break;
} }
} }
//}
// Now set that priority // Now set that priority
if (EventQueueThread != null) if (EventQueueThread != null)
if (EventQueueThread.IsAlive) if (EventQueueThread.IsAlive)
@ -187,6 +189,8 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
public void DoProcessQueue() public void DoProcessQueue()
{ {
//lock (ScriptEngine.ScriptEngines)
//{
foreach (ScriptEngine m_ScriptEngine in new ArrayList(ScriptEngine.ScriptEngines)) foreach (ScriptEngine m_ScriptEngine in new ArrayList(ScriptEngine.ScriptEngines))
{ {
lastScriptEngine = m_ScriptEngine; lastScriptEngine = m_ScriptEngine;
@ -318,7 +322,8 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
//else //else
//{ //{
// T oconsole // T oconsole
m_ScriptEngine.m_EventQueueManager.m_ScriptEngine.Log.Error("[" + ScriptEngineName + "]: " + m_ScriptEngine.m_EventQueueManager.m_ScriptEngine.Log.Error("[" + ScriptEngineName +
"]: " +
"Unable to send text in-world:\r\n" + "Unable to send text in-world:\r\n" +
text); text);
} }
@ -340,6 +345,7 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
} }
} }
} }
// }
} }
///// <summary> ///// <summary>

View File

@ -63,15 +63,20 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
public void ReadConfig() public void ReadConfig()
{ {
// Bad hack, but we need a m_ScriptEngine :) // Bad hack, but we need a m_ScriptEngine :)
lock (ScriptEngine.ScriptEngines)
{
foreach (ScriptEngine m_ScriptEngine in ScriptEngine.ScriptEngines) foreach (ScriptEngine m_ScriptEngine in ScriptEngine.ScriptEngines)
{ {
MaintenanceLoopms = m_ScriptEngine.ScriptConfigSource.GetInt("MaintenanceLoopms", 50); MaintenanceLoopms = m_ScriptEngine.ScriptConfigSource.GetInt("MaintenanceLoopms", 50);
MaintenanceLoopTicks_ScriptLoadUnload = m_ScriptEngine.ScriptConfigSource.GetInt("MaintenanceLoopTicks_ScriptLoadUnload", 1); MaintenanceLoopTicks_ScriptLoadUnload =
MaintenanceLoopTicks_Other = m_ScriptEngine.ScriptConfigSource.GetInt("MaintenanceLoopTicks_Other", 10); m_ScriptEngine.ScriptConfigSource.GetInt("MaintenanceLoopTicks_ScriptLoadUnload", 1);
MaintenanceLoopTicks_Other =
m_ScriptEngine.ScriptConfigSource.GetInt("MaintenanceLoopTicks_Other", 10);
return; return;
} }
} }
}
#region " Maintenance thread " #region " Maintenance thread "
/// <summary> /// <summary>
@ -159,7 +164,9 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
MaintenanceLoopTicks_Other_Count++; MaintenanceLoopTicks_Other_Count++;
foreach (ScriptEngine m_ScriptEngine in new ArrayList(ScriptEngine.ScriptEngines)) lock (ScriptEngine.ScriptEngines)
{
foreach (ScriptEngine m_ScriptEngine in ScriptEngine.ScriptEngines)
{ {
lastScriptEngine = m_ScriptEngine; lastScriptEngine = m_ScriptEngine;
// Re-reading config every x seconds // Re-reading config every x seconds
@ -168,7 +175,6 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
MaintenanceLoopTicks_Other_ResetCount = true; MaintenanceLoopTicks_Other_ResetCount = true;
if (m_ScriptEngine.RefreshConfigFilens > 0) if (m_ScriptEngine.RefreshConfigFilens > 0)
{ {
// Check if its time to re-read config // Check if its time to re-read config
if (DateTime.Now.Ticks - Last_ReReadConfigFilens > if (DateTime.Now.Ticks - Last_ReReadConfigFilens >
m_ScriptEngine.RefreshConfigFilens) m_ScriptEngine.RefreshConfigFilens)
@ -197,7 +203,6 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
} }
} }
} }
} }
if (MaintenanceLoopTicks_ScriptLoadUnload_Count >= MaintenanceLoopTicks_ScriptLoadUnload) if (MaintenanceLoopTicks_ScriptLoadUnload_Count >= MaintenanceLoopTicks_ScriptLoadUnload)
{ {
@ -209,6 +214,7 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
} }
} }
} }
}
catch (Exception ex) catch (Exception ex)
{ {
if (lastScriptEngine != null) if (lastScriptEngine != null)

View File

@ -84,8 +84,11 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
public ScriptEngine() public ScriptEngine()
{ {
Common.mySE = this; // For logging, just need any instance, doesn't matter Common.mySE = this; // For logging, just need any instance, doesn't matter
lock (ScriptEngines)
{
ScriptEngines.Add(this); // Keep a list of ScriptEngines for shared threads to process all instances 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)
{ {
@ -107,7 +110,7 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
newScriptManager.Start(); newScriptManager.Start();
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();
if (m_MaintenanceThread == null) if (m_MaintenanceThread == null)
m_MaintenanceThread = new MaintenanceThread(); m_MaintenanceThread = new MaintenanceThread();
@ -121,8 +124,11 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
public void Shutdown() public void Shutdown()
{ {
// We are shutting down // We are shutting down
lock (ScriptEngines)
{
ScriptEngines.Remove(this); ScriptEngines.Remove(this);
} }
}
ScriptServerInterfaces.RemoteEvents ScriptServerInterfaces.ScriptEngine.EventManager() ScriptServerInterfaces.RemoteEvents ScriptServerInterfaces.ScriptEngine.EventManager()
{ {
@ -136,13 +142,6 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
#endif #endif
RefreshConfigFileSeconds = ScriptConfigSource.GetInt("RefreshConfig", 30); RefreshConfigFileSeconds = ScriptConfigSource.GetInt("RefreshConfig", 30);
// Reload from disk? No!
//ConfigSource.Reload();
//if (File.Exists(OpenSim.Application.iniFilePath))
//{
// //ConfigSource.Merge(new IniConfigSource(OpenSim.Application.iniFilePath));
//}
// Create a new object (probably not necessary?) // Create a new object (probably not necessary?)
// ScriptConfigSource = ConfigSource.Configs[ScriptEngineName]; // ScriptConfigSource = ConfigSource.Configs[ScriptEngineName];
@ -179,15 +178,6 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
#endregion #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;
} }
} }

View File

@ -210,12 +210,6 @@ SleepTimeIfNoScriptExecutionMs=50
; Each AppDomain has some memory overhead. But leaving dead scripts in memory also has memory overhead. ; Each AppDomain has some memory overhead. But leaving dead scripts in memory also has memory overhead.
ScriptsPerAppDomain=1 ScriptsPerAppDomain=1
; Script loading / unloading sleep
; 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
; MaintenanceLoop ; MaintenanceLoop
; How often to run maintenance loop ; 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 ; Maintenance loop is doing: script compile/load, script unload, reload config, adjust running config and enforce max execution time
@ -224,6 +218,10 @@ MaintenanceLoopms=50
; How many maintenanceloops between each of these. ; How many maintenanceloops between each of these.
; (if 2 then function will be executed every MaintenanceLoopms*2 ms) ; (if 2 then function will be executed every MaintenanceLoopms*2 ms)
; Script loading/unloading ; Script loading/unloading
; 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
MaintenanceLoopTicks_ScriptLoadUnload=1 MaintenanceLoopTicks_ScriptLoadUnload=1
; Other tasks ; Other tasks