From f67f37074f3f7e0602b66aa66a044dd9fd107f6a Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Fri, 24 Feb 2012 05:02:33 +0000
Subject: Stop spurious scene loop startup timeout alarms for scenes with many
prims.
On the first frame, all startup scene objects are added to the physics scene.
This can cause a considerable delay, so we don't start raising the alarm on scene loop timeouts until the second frame.
This commit also slightly changes the behaviour of timeout reporting.
Previously, a report was made for the very first timed out thread, ignoring all others until the next watchdog check.
Instead, we now report every timed out thread, though we still only do this once no matter how long the timeout.
---
.../HttpServer/PollServiceRequestManager.cs | 2 +
OpenSim/Framework/Watchdog.cs | 57 +++++++++++++++-------
2 files changed, 42 insertions(+), 17 deletions(-)
(limited to 'OpenSim/Framework')
diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs
index 2206feb..0062d4e 100644
--- a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs
+++ b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs
@@ -65,6 +65,7 @@ namespace OpenSim.Framework.Servers.HttpServer
String.Format("PollServiceWorkerThread{0}", i),
ThreadPriority.Normal,
false,
+ true,
int.MaxValue);
}
@@ -73,6 +74,7 @@ namespace OpenSim.Framework.Servers.HttpServer
"PollServiceWatcherThread",
ThreadPriority.Normal,
false,
+ true,
1000 * 60 * 10);
}
diff --git a/OpenSim/Framework/Watchdog.cs b/OpenSim/Framework/Watchdog.cs
index 2dd6ebe..e443f0a 100644
--- a/OpenSim/Framework/Watchdog.cs
+++ b/OpenSim/Framework/Watchdog.cs
@@ -72,6 +72,11 @@ namespace OpenSim.Framework
///
public bool IsTimedOut { get; set; }
+ ///
+ /// Will this thread trigger the alarm function if it has timed out?
+ ///
+ public bool AlarmIfTimeout { get; set; }
+
public ThreadWatchdogInfo(Thread thread, int timeout)
{
Thread = thread;
@@ -112,12 +117,13 @@ namespace OpenSim.Framework
/// The method that will be executed in a new thread
/// A name to give to the new thread
/// Priority to run the thread at
- /// True to run this thread as a background
- /// thread, otherwise false
+ /// True to run this thread as a background thread, otherwise false
+ /// Trigger an alarm function is we have timed out
/// The newly created Thread object
- public static Thread StartThread(ThreadStart start, string name, ThreadPriority priority, bool isBackground)
+ public static Thread StartThread(
+ ThreadStart start, string name, ThreadPriority priority, bool isBackground, bool alarmIfTimeout)
{
- return StartThread(start, name, priority, isBackground, WATCHDOG_TIMEOUT_MS);
+ return StartThread(start, name, priority, isBackground, alarmIfTimeout, WATCHDOG_TIMEOUT_MS);
}
///
@@ -128,21 +134,21 @@ namespace OpenSim.Framework
/// Priority to run the thread at
/// True to run this thread as a background
/// thread, otherwise false
- ///
- /// Number of milliseconds to wait until we issue a warning about timeout.
- ///
+ /// Trigger an alarm function is we have timed out
+ /// Number of milliseconds to wait until we issue a warning about timeout.
/// The newly created Thread object
public static Thread StartThread(
- ThreadStart start, string name, ThreadPriority priority, bool isBackground, int timeout)
+ ThreadStart start, string name, ThreadPriority priority, bool isBackground, bool alarmIfTimeout, int timeout)
{
Thread thread = new Thread(start);
thread.Name = name;
thread.Priority = priority;
thread.IsBackground = isBackground;
- ThreadWatchdogInfo twi = new ThreadWatchdogInfo(thread, timeout);
+ ThreadWatchdogInfo twi = new ThreadWatchdogInfo(thread, timeout) { AlarmIfTimeout = alarmIfTimeout };
- m_log.Debug("[WATCHDOG]: Started tracking thread \"" + twi.Thread.Name + "\" (ID " + twi.Thread.ManagedThreadId + ")");
+ m_log.DebugFormat(
+ "[WATCHDOG]: Started tracking thread {0}, ID {1}", twi.Thread.Name, twi.Thread.ManagedThreadId);
lock (m_threads)
m_threads.Add(twi.Thread.ManagedThreadId, twi);
@@ -230,6 +236,26 @@ namespace OpenSim.Framework
return m_threads.Values.ToArray();
}
+ ///
+ /// Return the current thread's watchdog info.
+ ///
+ /// The watchdog info. null if the thread isn't being monitored.
+ public static ThreadWatchdogInfo GetCurrentThreadInfo()
+ {
+ lock (m_threads)
+ {
+ if (m_threads.ContainsKey(Thread.CurrentThread.ManagedThreadId))
+ return m_threads[Thread.CurrentThread.ManagedThreadId];
+ }
+
+ return null;
+ }
+
+ ///
+ /// Check watched threads. Fire alarm if appropriate.
+ ///
+ ///
+ ///
private static void WatchdogTimerElapsed(object sender, System.Timers.ElapsedEventArgs e)
{
WatchdogTimeout callback = OnWatchdogTimeout;
@@ -246,21 +272,18 @@ namespace OpenSim.Framework
{
if (threadInfo.Thread.ThreadState == ThreadState.Stopped)
{
- timedOut = threadInfo;
RemoveThread(threadInfo.Thread.ManagedThreadId);
- break;
+ callback(threadInfo.Thread, threadInfo.LastTick);
}
else if (!threadInfo.IsTimedOut && now - threadInfo.LastTick >= threadInfo.Timeout)
{
threadInfo.IsTimedOut = true;
- timedOut = threadInfo;
- break;
+
+ if (threadInfo.AlarmIfTimeout)
+ callback(threadInfo.Thread, threadInfo.LastTick);
}
}
}
-
- if (timedOut != null)
- callback(timedOut.Thread, timedOut.LastTick);
}
m_watchdogTimer.Start();
--
cgit v1.1
From 9e6ffe779841f470c0e2dbe673ef4b10253bcd84 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Fri, 24 Feb 2012 05:15:47 +0000
Subject: Rename Watchdog.GetThreads() to GetThreadsInfo() to reflect what it
actually returns and for consistency.
---
OpenSim/Framework/Servers/BaseOpenSimServer.cs | 2 +-
OpenSim/Framework/Watchdog.cs | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
(limited to 'OpenSim/Framework')
diff --git a/OpenSim/Framework/Servers/BaseOpenSimServer.cs b/OpenSim/Framework/Servers/BaseOpenSimServer.cs
index 0dd01af..6a3135e 100644
--- a/OpenSim/Framework/Servers/BaseOpenSimServer.cs
+++ b/OpenSim/Framework/Servers/BaseOpenSimServer.cs
@@ -247,7 +247,7 @@ namespace OpenSim.Framework.Servers
string reportFormat = "{0,6} {1,35} {2,16} {3,13} {4,10} {5,30}";
StringBuilder sb = new StringBuilder();
- Watchdog.ThreadWatchdogInfo[] threads = Watchdog.GetThreads();
+ Watchdog.ThreadWatchdogInfo[] threads = Watchdog.GetThreadsInfo();
sb.Append(threads.Length + " threads are being tracked:" + Environment.NewLine);
diff --git a/OpenSim/Framework/Watchdog.cs b/OpenSim/Framework/Watchdog.cs
index e443f0a..4891a66 100644
--- a/OpenSim/Framework/Watchdog.cs
+++ b/OpenSim/Framework/Watchdog.cs
@@ -230,7 +230,7 @@ namespace OpenSim.Framework
/// Get currently watched threads for diagnostic purposes
///
///
- public static ThreadWatchdogInfo[] GetThreads()
+ public static ThreadWatchdogInfo[] GetThreadsInfo()
{
lock (m_threads)
return m_threads.Values.ToArray();
--
cgit v1.1
From bafef292f4d41df14a1edeafc7ba5f9d623d7822 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Fri, 24 Feb 2012 05:25:18 +0000
Subject: Take watchdog alarm calling back outside the m_threads lock.
This is how it was originally. This stops a very long running alarm callback from causing a problem.
---
OpenSim/Framework/Watchdog.cs | 19 ++++++++++++++++---
1 file changed, 16 insertions(+), 3 deletions(-)
(limited to 'OpenSim/Framework')
diff --git a/OpenSim/Framework/Watchdog.cs b/OpenSim/Framework/Watchdog.cs
index 4891a66..e93e50e 100644
--- a/OpenSim/Framework/Watchdog.cs
+++ b/OpenSim/Framework/Watchdog.cs
@@ -262,7 +262,7 @@ namespace OpenSim.Framework
if (callback != null)
{
- ThreadWatchdogInfo timedOut = null;
+ List callbackInfos = null;
lock (m_threads)
{
@@ -273,17 +273,30 @@ namespace OpenSim.Framework
if (threadInfo.Thread.ThreadState == ThreadState.Stopped)
{
RemoveThread(threadInfo.Thread.ManagedThreadId);
- callback(threadInfo.Thread, threadInfo.LastTick);
+
+ if (callbackInfos == null)
+ callbackInfos = new List();
+
+ callbackInfos.Add(threadInfo);
}
else if (!threadInfo.IsTimedOut && now - threadInfo.LastTick >= threadInfo.Timeout)
{
threadInfo.IsTimedOut = true;
if (threadInfo.AlarmIfTimeout)
- callback(threadInfo.Thread, threadInfo.LastTick);
+ {
+ if (callbackInfos == null)
+ callbackInfos = new List();
+
+ callbackInfos.Add(threadInfo);
+ }
}
}
}
+
+ if (callbackInfos != null)
+ foreach (ThreadWatchdogInfo callbackInfo in callbackInfos)
+ callback(callbackInfo.Thread, callbackInfo.LastTick);
}
m_watchdogTimer.Start();
--
cgit v1.1