aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework
diff options
context:
space:
mode:
authorOren Hurvitz2013-12-05 08:40:41 +0200
committerOren Hurvitz2014-03-25 08:01:32 +0100
commit8555e54e22f6d15375b9279a59ec8695a883dc11 (patch)
treeb482a9c1d5af4ed53fd0a0cb81874e48e27a2f9a /OpenSim/Framework
parentAdded debug flag: LogThreadPool. It makes us log every use of the main thread... (diff)
downloadopensim-SC_OLD-8555e54e22f6d15375b9279a59ec8695a883dc11.zip
opensim-SC_OLD-8555e54e22f6d15375b9279a59ec8695a883dc11.tar.gz
opensim-SC_OLD-8555e54e22f6d15375b9279a59ec8695a883dc11.tar.bz2
opensim-SC_OLD-8555e54e22f6d15375b9279a59ec8695a883dc11.tar.xz
Automatically start logging FireAndForget activity if the threadpool is full
Resolves http://opensimulator.org/mantis/view.php?id=6945
Diffstat (limited to '')
-rw-r--r--OpenSim/Framework/Util.cs23
1 files changed, 19 insertions, 4 deletions
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs
index ed94c6f..0dfee71 100644
--- a/OpenSim/Framework/Util.cs
+++ b/OpenSim/Framework/Util.cs
@@ -1901,11 +1901,14 @@ namespace OpenSim.Framework
1901 private static long nextThreadFuncNum = 0; 1901 private static long nextThreadFuncNum = 0;
1902 private static long numQueuedThreadFuncs = 0; 1902 private static long numQueuedThreadFuncs = 0;
1903 private static long numRunningThreadFuncs = 0; 1903 private static long numRunningThreadFuncs = 0;
1904 private static Int32 threadFuncOverloadMode = 0;
1904 1905
1905 public static void FireAndForget(System.Threading.WaitCallback callback, object obj) 1906 public static void FireAndForget(System.Threading.WaitCallback callback, object obj)
1906 { 1907 {
1907 WaitCallback realCallback; 1908 WaitCallback realCallback;
1908 1909
1910 bool loggingEnabled = LogThreadPool;
1911
1909 long threadFuncNum = Interlocked.Increment(ref nextThreadFuncNum); 1912 long threadFuncNum = Interlocked.Increment(ref nextThreadFuncNum);
1910 1913
1911 if (FireAndForgetMethod == FireAndForgetMethod.RegressionTest) 1914 if (FireAndForgetMethod == FireAndForgetMethod.RegressionTest)
@@ -1925,7 +1928,7 @@ namespace OpenSim.Framework
1925 1928
1926 try 1929 try
1927 { 1930 {
1928 if (LogThreadPool) 1931 if (loggingEnabled || (threadFuncOverloadMode == 1))
1929 m_log.DebugFormat("Run threadfunc {0} (Queued {1}, Running {2})", threadFuncNum, numQueued1, numRunning1); 1932 m_log.DebugFormat("Run threadfunc {0} (Queued {1}, Running {2})", threadFuncNum, numQueued1, numRunning1);
1930 1933
1931 Culture.SetCurrentCulture(); 1934 Culture.SetCurrentCulture();
@@ -1939,7 +1942,7 @@ namespace OpenSim.Framework
1939 finally 1942 finally
1940 { 1943 {
1941 Interlocked.Decrement(ref numRunningThreadFuncs); 1944 Interlocked.Decrement(ref numRunningThreadFuncs);
1942 if (LogThreadPool) 1945 if (loggingEnabled || (threadFuncOverloadMode == 1))
1943 m_log.Debug("Exit threadfunc " + threadFuncNum); 1946 m_log.Debug("Exit threadfunc " + threadFuncNum);
1944 } 1947 }
1945 }; 1948 };
@@ -1948,9 +1951,21 @@ namespace OpenSim.Framework
1948 long numQueued = Interlocked.Increment(ref numQueuedThreadFuncs); 1951 long numQueued = Interlocked.Increment(ref numQueuedThreadFuncs);
1949 try 1952 try
1950 { 1953 {
1951 if (LogThreadPool) 1954 long numRunning = numRunningThreadFuncs;
1955 if ((threadFuncOverloadMode == 0) && (numRunning >= m_ThreadPool.MaxThreads))
1956 {
1957 if (Interlocked.CompareExchange(ref threadFuncOverloadMode, 1, 0) == 0)
1958 m_log.DebugFormat("Threadfunc: enable overload mode (Queued {0}, Running {1})", numQueued, numRunning);
1959 }
1960 else if ((threadFuncOverloadMode == 1) && (numRunning <= (m_ThreadPool.MaxThreads*2)/3))
1961 {
1962 if (Interlocked.CompareExchange(ref threadFuncOverloadMode, 0, 1) == 1)
1963 m_log.DebugFormat("Threadfunc: disable overload mode (Queued {0}, Running {1})", numQueued, numRunning);
1964 }
1965
1966 if (loggingEnabled || (threadFuncOverloadMode == 1))
1952 m_log.DebugFormat("Queue threadfunc {0} (Queued {1}, Running {2}) {3}", 1967 m_log.DebugFormat("Queue threadfunc {0} (Queued {1}, Running {2}) {3}",
1953 threadFuncNum, numQueued, numRunningThreadFuncs, GetFireAndForgetStackTrace(true)); 1968 threadFuncNum, numQueued, numRunningThreadFuncs, GetFireAndForgetStackTrace(loggingEnabled));
1954 1969
1955 switch (FireAndForgetMethod) 1970 switch (FireAndForgetMethod)
1956 { 1971 {