aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJohn Hurliman2009-10-26 14:41:27 -0700
committerJohn Hurliman2009-10-26 14:41:27 -0700
commitac7ccdf7d77810aef0a3ad70f1504fdb111dc0aa (patch)
treee27db00548a86fbf370b481ab0848bd3d30f21aa
parentChanged UseCircuitCode handling to be synchronous or asynchronous depending o... (diff)
downloadopensim-SC-ac7ccdf7d77810aef0a3ad70f1504fdb111dc0aa.zip
opensim-SC-ac7ccdf7d77810aef0a3ad70f1504fdb111dc0aa.tar.gz
opensim-SC-ac7ccdf7d77810aef0a3ad70f1504fdb111dc0aa.tar.bz2
opensim-SC-ac7ccdf7d77810aef0a3ad70f1504fdb111dc0aa.tar.xz
* Changed the watchdog timer to improve the speed of UpdateThread(), only track threads once the first call to UpdateThread() has been made, and allow re-tracking of threads that timed out but revived later
* Added a commented out call to Watchdog.UpdateThread() in OdeScene. If it turns out that loading a large OAR file or some other operation is timing out the heartbeat thread, we'll need to uncomment it
Diffstat (limited to '')
-rw-r--r--OpenSim/Framework/Watchdog.cs60
-rw-r--r--OpenSim/Region/Framework/Scenes/Scene.cs2
-rw-r--r--OpenSim/Region/Physics/OdePlugin/OdePlugin.cs8
3 files changed, 38 insertions, 32 deletions
diff --git a/OpenSim/Framework/Watchdog.cs b/OpenSim/Framework/Watchdog.cs
index b905609..5d46905 100644
--- a/OpenSim/Framework/Watchdog.cs
+++ b/OpenSim/Framework/Watchdog.cs
@@ -28,6 +28,7 @@
28using System; 28using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.Threading; 30using System.Threading;
31using log4net;
31 32
32namespace OpenSim.Framework 33namespace OpenSim.Framework
33{ 34{
@@ -66,6 +67,7 @@ namespace OpenSim.Framework
66 /// stopped or has not called UpdateThread() in time</summary> 67 /// stopped or has not called UpdateThread() in time</summary>
67 public static event WatchdogTimeout OnWatchdogTimeout; 68 public static event WatchdogTimeout OnWatchdogTimeout;
68 69
70 private static readonly ILog m_log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
69 private static Dictionary<int, ThreadWatchdogInfo> m_threads; 71 private static Dictionary<int, ThreadWatchdogInfo> m_threads;
70 private static System.Timers.Timer m_watchdogTimer; 72 private static System.Timers.Timer m_watchdogTimer;
71 73
@@ -95,9 +97,6 @@ namespace OpenSim.Framework
95 thread.IsBackground = isBackground; 97 thread.IsBackground = isBackground;
96 thread.Start(); 98 thread.Start();
97 99
98 lock (m_threads)
99 m_threads.Add(thread.ManagedThreadId, new ThreadWatchdogInfo(thread));
100
101 return thread; 100 return thread;
102 } 101 }
103 102
@@ -110,24 +109,6 @@ namespace OpenSim.Framework
110 } 109 }
111 110
112 /// <summary> 111 /// <summary>
113 /// Marks a thread as alive
114 /// </summary>
115 /// <param name="threadID">The ManagedThreadId of the thread to mark as
116 /// alive</param>
117 public static void UpdateThread(int threadID)
118 {
119 ThreadWatchdogInfo threadInfo;
120
121 lock (m_threads)
122 {
123 if (m_threads.TryGetValue(threadID, out threadInfo))
124 {
125 threadInfo.LastTick = Environment.TickCount & Int32.MaxValue;
126 }
127 }
128 }
129
130 /// <summary>
131 /// Stops watchdog tracking on the current thread 112 /// Stops watchdog tracking on the current thread
132 /// </summary> 113 /// </summary>
133 /// <returns>True if the thread was removed from the list of tracked 114 /// <returns>True if the thread was removed from the list of tracked
@@ -137,19 +118,38 @@ namespace OpenSim.Framework
137 return RemoveThread(Thread.CurrentThread.ManagedThreadId); 118 return RemoveThread(Thread.CurrentThread.ManagedThreadId);
138 } 119 }
139 120
140 /// <summary> 121 private static void AddThread(ThreadWatchdogInfo threadInfo)
141 /// Stops watchdog tracking on a thread 122 {
142 /// </summary> 123 m_log.Debug("[WATCHDOG]: Started tracking thread \"" + threadInfo.Thread.Name + "\" (ID " + threadInfo.Thread.ManagedThreadId + ")");
143 /// <param name="threadID">The ManagedThreadId of the thread to stop 124
144 /// tracking</param> 125 lock (m_threads)
145 /// <returns>True if the thread was removed from the list of tracked 126 m_threads.Add(threadInfo.Thread.ManagedThreadId, threadInfo);
146 /// threads, otherwise false</returns> 127 }
147 public static bool RemoveThread(int threadID) 128
129 private static bool RemoveThread(int threadID)
148 { 130 {
149 lock (m_threads) 131 lock (m_threads)
150 return m_threads.Remove(threadID); 132 return m_threads.Remove(threadID);
151 } 133 }
152 134
135 private static void UpdateThread(int threadID)
136 {
137 ThreadWatchdogInfo threadInfo;
138
139 // Although TryGetValue is not a thread safe operation, we use a try/catch here instead
140 // of a lock for speed. Adding/removing threads is a very rare operation compared to
141 // UpdateThread(), and a single UpdateThread() failure here and there won't break
142 // anything
143 try
144 {
145 if (m_threads.TryGetValue(threadID, out threadInfo))
146 threadInfo.LastTick = Environment.TickCount & Int32.MaxValue;
147 else
148 AddThread(new ThreadWatchdogInfo(Thread.CurrentThread));
149 }
150 catch { }
151 }
152
153 private static void WatchdogTimerElapsed(object sender, System.Timers.ElapsedEventArgs e) 153 private static void WatchdogTimerElapsed(object sender, System.Timers.ElapsedEventArgs e)
154 { 154 {
155 WatchdogTimeout callback = OnWatchdogTimeout; 155 WatchdogTimeout callback = OnWatchdogTimeout;
@@ -160,7 +160,7 @@ namespace OpenSim.Framework
160 160
161 lock (m_threads) 161 lock (m_threads)
162 { 162 {
163 int now = Environment.TickCount; 163 int now = Environment.TickCount & Int32.MaxValue;
164 164
165 foreach (ThreadWatchdogInfo threadInfo in m_threads.Values) 165 foreach (ThreadWatchdogInfo threadInfo in m_threads.Values)
166 { 166 {
diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs
index f052c65..95d69a1 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.cs
@@ -1025,6 +1025,7 @@ namespace OpenSim.Region.Framework.Scenes
1025 float physicsFPS = 0; 1025 float physicsFPS = 0;
1026 1026
1027 frameMS = Environment.TickCount; 1027 frameMS = Environment.TickCount;
1028
1028 try 1029 try
1029 { 1030 {
1030 // Increment the frame counter 1031 // Increment the frame counter
@@ -1152,6 +1153,7 @@ namespace OpenSim.Region.Framework.Scenes
1152 if ((maintc < (m_timespan * 1000)) && maintc > 0) 1153 if ((maintc < (m_timespan * 1000)) && maintc > 0)
1153 Thread.Sleep(maintc); 1154 Thread.Sleep(maintc);
1154 1155
1156 // Tell the watchdog that this thread is still alive
1155 Watchdog.UpdateThread(); 1157 Watchdog.UpdateThread();
1156 } 1158 }
1157 } 1159 }
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
index f979ce3..82392b1 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
@@ -2705,8 +2705,6 @@ namespace OpenSim.Region.Physics.OdePlugin
2705 { 2705 {
2706 foreach (OdePrim prim in _taintedPrimL) 2706 foreach (OdePrim prim in _taintedPrimL)
2707 { 2707 {
2708
2709
2710 if (prim.m_taintremove) 2708 if (prim.m_taintremove)
2711 { 2709 {
2712//Console.WriteLine("Simulate calls RemovePrimThreadLocked"); 2710//Console.WriteLine("Simulate calls RemovePrimThreadLocked");
@@ -2719,6 +2717,12 @@ namespace OpenSim.Region.Physics.OdePlugin
2719 } 2717 }
2720 processedtaints = true; 2718 processedtaints = true;
2721 prim.m_collisionscore = 0; 2719 prim.m_collisionscore = 0;
2720
2721 // This loop can block up the Heartbeat for a very long time on large regions.
2722 // We need to let the Watchdog know that the Heartbeat is not dead
2723 // NOTE: This is currently commented out, but if things like OAR loading are
2724 // timing the heartbeat out we will need to uncomment it
2725 //Watchdog.UpdateThread();
2722 } 2726 }
2723 2727
2724 if (SupportsNINJAJoints) 2728 if (SupportsNINJAJoints)