diff options
author | Tedd Hansen | 2008-02-22 12:50:24 +0000 |
---|---|---|
committer | Tedd Hansen | 2008-02-22 12:50:24 +0000 |
commit | a040008cb956f4e99bc87a006b51925966443d63 (patch) | |
tree | aa3a5b1cc2249993c5ae73b1a27787dda103e306 /OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/MaintenanceThread.cs | |
parent | * Relative large ClientView refactoring of packet Events into .Net recommende... (diff) | |
download | opensim-SC_OLD-a040008cb956f4e99bc87a006b51925966443d63.zip opensim-SC_OLD-a040008cb956f4e99bc87a006b51925966443d63.tar.gz opensim-SC_OLD-a040008cb956f4e99bc87a006b51925966443d63.tar.bz2 opensim-SC_OLD-a040008cb956f4e99bc87a006b51925966443d63.tar.xz |
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.
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/MaintenanceThread.cs')
-rw-r--r-- | OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/MaintenanceThread.cs | 71 |
1 files changed, 39 insertions, 32 deletions
diff --git a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/MaintenanceThread.cs b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/MaintenanceThread.cs index f959a5b..1a5cca1 100644 --- a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/MaintenanceThread.cs +++ b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/MaintenanceThread.cs | |||
@@ -38,12 +38,12 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase | |||
38 | /// </summary> | 38 | /// </summary> |
39 | public class MaintenanceThread : iScriptEngineFunctionModule | 39 | public class MaintenanceThread : iScriptEngineFunctionModule |
40 | { | 40 | { |
41 | public ScriptEngine m_ScriptEngine; | 41 | //public ScriptEngine m_ScriptEngine; |
42 | private int MaintenanceLoopms; | 42 | private int MaintenanceLoopms; |
43 | 43 | ||
44 | public MaintenanceThread(ScriptEngine _ScriptEngine) | 44 | public MaintenanceThread() |
45 | { | 45 | { |
46 | m_ScriptEngine = _ScriptEngine; | 46 | //m_ScriptEngine = _ScriptEngine; |
47 | 47 | ||
48 | ReadConfig(); | 48 | ReadConfig(); |
49 | 49 | ||
@@ -95,9 +95,9 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase | |||
95 | try | 95 | try |
96 | { | 96 | { |
97 | if (MaintenanceThreadThread != null && MaintenanceThreadThread.IsAlive) | 97 | if (MaintenanceThreadThread != null && MaintenanceThreadThread.IsAlive) |
98 | { | 98 | { |
99 | MaintenanceThreadThread.Abort(); | 99 | MaintenanceThreadThread.Abort(); |
100 | } | 100 | } |
101 | } | 101 | } |
102 | catch (Exception ex) | 102 | catch (Exception ex) |
103 | { | 103 | { |
@@ -105,14 +105,15 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase | |||
105 | } | 105 | } |
106 | } | 106 | } |
107 | 107 | ||
108 | private ScriptEngine lastScriptEngine; // Keep track of what ScriptEngine instance we are at so we can give exception | ||
108 | /// <summary> | 109 | /// <summary> |
109 | /// A thread should run in this loop and check all running scripts | 110 | /// A thread should run in this loop and check all running scripts |
110 | /// </summary> | 111 | /// </summary> |
111 | public void MaintenanceLoop() | 112 | public void MaintenanceLoop() |
112 | { | 113 | { |
113 | if (m_ScriptEngine.m_EventQueueManager.maxFunctionExecutionTimens < MaintenanceLoopms) | 114 | //if (m_ScriptEngine.m_EventQueueManager.maxFunctionExecutionTimens < MaintenanceLoopms) |
114 | m_ScriptEngine.Log.Warn("[" + m_ScriptEngine.ScriptEngineName + "]: " + | 115 | // m_ScriptEngine.Log.Warn("[" + m_ScriptEngine.ScriptEngineName + "]: " + |
115 | "Configuration error: MaxEventExecutionTimeMs is less than MaintenanceLoopms. The Maintenance Loop will only check scripts once per run."); | 116 | // "Configuration error: MaxEventExecutionTimeMs is less than MaintenanceLoopms. The Maintenance Loop will only check scripts once per run."); |
116 | 117 | ||
117 | long Last_maxFunctionExecutionTimens = 0; // DateTime.Now.Ticks; | 118 | long Last_maxFunctionExecutionTimens = 0; // DateTime.Now.Ticks; |
118 | long Last_ReReadConfigFilens = DateTime.Now.Ticks; | 119 | long Last_ReReadConfigFilens = DateTime.Now.Ticks; |
@@ -126,35 +127,41 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase | |||
126 | if (PleaseShutdown) | 127 | if (PleaseShutdown) |
127 | return; | 128 | return; |
128 | 129 | ||
129 | if (m_ScriptEngine != null) | 130 | foreach (ScriptEngine m_ScriptEngine in ScriptEngine.ScriptEngines) |
130 | { | 131 | { |
131 | // Re-reading config every x seconds | 132 | lastScriptEngine = m_ScriptEngine; |
132 | if (m_ScriptEngine.RefreshConfigFilens > 0) | 133 | if (m_ScriptEngine != null) |
133 | { | 134 | { |
134 | // Check if its time to re-read config | 135 | // Re-reading config every x seconds |
135 | if (DateTime.Now.Ticks - Last_ReReadConfigFilens > m_ScriptEngine.RefreshConfigFilens) | 136 | if (m_ScriptEngine.RefreshConfigFilens > 0) |
136 | { | 137 | { |
137 | //Console.WriteLine("Time passed: " + (DateTime.Now.Ticks - Last_ReReadConfigFilens) + ">" + m_ScriptEngine.RefreshConfigFilens ); | 138 | // Check if its time to re-read config |
138 | // Its time to re-read config file | 139 | if (DateTime.Now.Ticks - Last_ReReadConfigFilens > |
139 | m_ScriptEngine.ReadConfig(); | 140 | m_ScriptEngine.RefreshConfigFilens) |
140 | Last_ReReadConfigFilens = DateTime.Now.Ticks; // Reset time | 141 | { |
142 | //Console.WriteLine("Time passed: " + (DateTime.Now.Ticks - Last_ReReadConfigFilens) + ">" + m_ScriptEngine.RefreshConfigFilens ); | ||
143 | // Its time to re-read config file | ||
144 | m_ScriptEngine.ReadConfig(); | ||
145 | Last_ReReadConfigFilens = DateTime.Now.Ticks; // Reset time | ||
146 | } | ||
141 | } | 147 | } |
142 | } | ||
143 | 148 | ||
144 | // Adjust number of running script threads if not correct | 149 | // Adjust number of running script threads if not correct |
145 | if (m_ScriptEngine.m_EventQueueManager != null) | 150 | if (m_ScriptEngine.m_EventQueueManager != null) |
146 | m_ScriptEngine.m_EventQueueManager.AdjustNumberOfScriptThreads(); | 151 | m_ScriptEngine.m_EventQueueManager.AdjustNumberOfScriptThreads(); |
147 | 152 | ||
148 | // Check if any script has exceeded its max execution time | 153 | // Check if any script has exceeded its max execution time |
149 | if (m_ScriptEngine.m_EventQueueManager != null && m_ScriptEngine.m_EventQueueManager.EnforceMaxExecutionTime) | 154 | if (m_ScriptEngine.m_EventQueueManager != null && |
150 | { | 155 | m_ScriptEngine.m_EventQueueManager.EnforceMaxExecutionTime) |
151 | // We are enforcing execution time | ||
152 | if (DateTime.Now.Ticks - Last_maxFunctionExecutionTimens > | ||
153 | m_ScriptEngine.m_EventQueueManager.maxFunctionExecutionTimens) | ||
154 | { | 156 | { |
155 | // Its time to check again | 157 | // We are enforcing execution time |
156 | m_ScriptEngine.m_EventQueueManager.CheckScriptMaxExecTime(); // Do check | 158 | if (DateTime.Now.Ticks - Last_maxFunctionExecutionTimens > |
157 | Last_maxFunctionExecutionTimens = DateTime.Now.Ticks; // Reset time | 159 | m_ScriptEngine.m_EventQueueManager.maxFunctionExecutionTimens) |
160 | { | ||
161 | // Its time to check again | ||
162 | m_ScriptEngine.m_EventQueueManager.CheckScriptMaxExecTime(); // Do check | ||
163 | Last_maxFunctionExecutionTimens = DateTime.Now.Ticks; // Reset time | ||
164 | } | ||
158 | } | 165 | } |
159 | } | 166 | } |
160 | } | 167 | } |
@@ -162,7 +169,7 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase | |||
162 | } | 169 | } |
163 | catch (Exception ex) | 170 | catch (Exception ex) |
164 | { | 171 | { |
165 | m_ScriptEngine.Log.Error("[" + m_ScriptEngine.ScriptEngineName + "]: Exception in MaintenanceLoopThread. Thread will recover after 5 sec throttle. Exception: " + ex.ToString()); | 172 | ScriptEngine.Log.Error("[" + lastScriptEngine.ScriptEngineName + "]: Exception in MaintenanceLoopThread. Thread will recover after 5 sec throttle. Exception: " + ex.ToString()); |
166 | Thread.Sleep(5000); | 173 | Thread.Sleep(5000); |
167 | } | 174 | } |
168 | } | 175 | } |