From 5e4d6cab00cb29cd088ab7b62ab13aff103b64cb Mon Sep 17 00:00:00 2001
From: onefang
Date: Sun, 19 May 2019 21:24:15 +1000
Subject: Dump OpenSim 0.9.0.1 into it's own branch.
---
OpenSim/Framework/Monitoring/WorkManager.cs | 48 ++++++++++++++++-------------
1 file changed, 26 insertions(+), 22 deletions(-)
(limited to 'OpenSim/Framework/Monitoring/WorkManager.cs')
diff --git a/OpenSim/Framework/Monitoring/WorkManager.cs b/OpenSim/Framework/Monitoring/WorkManager.cs
index d1a74ce..5d9b185 100644
--- a/OpenSim/Framework/Monitoring/WorkManager.cs
+++ b/OpenSim/Framework/Monitoring/WorkManager.cs
@@ -36,16 +36,16 @@ namespace OpenSim.Framework.Monitoring
/// Manages various work items in the simulator.
///
///
- /// Currently, here work can be started
+ /// Currently, here work can be started
/// * As a long-running and monitored thread.
/// * In a thread that will never timeout but where the job is expected to eventually complete.
/// * In a threadpool thread that will timeout if it takes a very long time to complete (> 10 mins).
/// * As a job which will be run in a single-threaded job engine. Such jobs must not incorporate delays (sleeps,
/// network waits, etc.).
- ///
+ ///
/// This is an evolving approach to better manage the work that OpenSimulator is asked to do from a very diverse
/// range of sources (client actions, incoming network, outgoing network calls, etc.).
- ///
+ ///
/// Util.FireAndForget is still available to insert jobs in the threadpool, though this is equivalent to
/// WorkManager.RunInThreadPool().
///
@@ -57,7 +57,7 @@ namespace OpenSim.Framework.Monitoring
static WorkManager()
{
- JobEngine = new JobEngine("Non-blocking non-critical job engine", "JOB ENGINE");
+ JobEngine = new JobEngine("Non-blocking non-critical job engine", "JOB ENGINE", 30000);
StatsManager.RegisterStat(
new Stat(
@@ -82,6 +82,12 @@ namespace OpenSim.Framework.Monitoring
HandleControlCommand);
}
+ public static void Stop()
+ {
+ JobEngine.Stop();
+ Watchdog.Stop();
+ }
+
///
/// Start a new long-lived thread.
///
@@ -121,6 +127,7 @@ namespace OpenSim.Framework.Monitoring
Thread thread = new Thread(start);
thread.Priority = priority;
thread.IsBackground = isBackground;
+ thread.Name = name;
Watchdog.ThreadWatchdogInfo twi
= new Watchdog.ThreadWatchdogInfo(thread, timeout, name)
@@ -129,7 +136,6 @@ namespace OpenSim.Framework.Monitoring
Watchdog.AddThread(twi, name, log:log);
thread.Start();
- thread.Name = name;
return thread;
}
@@ -143,7 +149,7 @@ namespace OpenSim.Framework.Monitoring
/// Name of the thread
public static void RunInThread(WaitCallback callback, object obj, string name, bool log = false)
{
- if (Util.FireAndForgetMethod == FireAndForgetMethod.RegressionTest)
+ if (Util.FireAndForgetMethod == FireAndForgetMethod.RegressionTest)
{
Culture.SetCurrentCulture();
callback(obj);
@@ -168,7 +174,7 @@ namespace OpenSim.Framework.Monitoring
}
///
- /// Run the callback via a threadpool thread.
+ /// Run the callback via a threadpool thread.
///
///
/// Such jobs may run after some delay but must always complete.
@@ -176,9 +182,9 @@ namespace OpenSim.Framework.Monitoring
///
///
/// The name of the job. This is used in monitoring and debugging.
- public static void RunInThreadPool(System.Threading.WaitCallback callback, object obj, string name)
+ public static void RunInThreadPool(System.Threading.WaitCallback callback, object obj, string name, bool timeout = true)
{
- Util.FireAndForget(callback, obj, name);
+ Util.FireAndForget(callback, obj, name, timeout);
}
///
@@ -187,17 +193,17 @@ namespace OpenSim.Framework.Monitoring
///
/// This differs from direct scheduling (e.g. Util.FireAndForget) in that a job can be run in the job
/// engine if it is running, where all jobs are currently performed in sequence on a single thread. This is
- /// to prevent observed overload and server freeze problems when there are hundreds of connections which all attempt to
+ /// to prevent observed overload and server freeze problems when there are hundreds of connections which all attempt to
/// perform work at once (e.g. in conference situations). With lower numbers of connections, the small
- /// delay in performing jobs in sequence rather than concurrently has not been notiecable in testing, though a future more
+ /// delay in performing jobs in sequence rather than concurrently has not been notiecable in testing, though a future more
/// sophisticated implementation could perform jobs concurrently when the server is under low load.
- ///
+ ///
/// However, be advised that some callers of this function rely on all jobs being performed in sequence if any
/// jobs are performed in sequence (i.e. if jobengine is active or not). Therefore, expanding the jobengine
/// beyond a single thread will require considerable thought.
- ///
+ ///
/// Also, any jobs submitted must be guaranteed to complete within a reasonable timeframe (e.g. they cannot
- /// incorporate a network delay with a long timeout). At the moment, work that could suffer such issues
+ /// incorporate a network delay with a long timeout). At the moment, work that could suffer such issues
/// should still be run directly with RunInThread(), Util.FireAndForget(), etc. This is another area where
/// the job engine could be improved and so CPU utilization improved by better management of concurrency within
/// OpenSimulator.
@@ -211,10 +217,10 @@ namespace OpenSim.Framework.Monitoring
/// If set to true then extra logging is performed.
public static void RunJob(
string jobType, WaitCallback callback, object obj, string name,
- bool canRunInThisThread = false, bool mustNotTimeout = false,
+ bool canRunInThisThread = false, bool mustNotTimeout = false,
bool log = false)
{
- if (Util.FireAndForgetMethod == FireAndForgetMethod.RegressionTest)
+ if (Util.FireAndForgetMethod == FireAndForgetMethod.RegressionTest)
{
Culture.SetCurrentCulture();
callback(obj);
@@ -225,10 +231,8 @@ namespace OpenSim.Framework.Monitoring
JobEngine.QueueJob(name, () => callback(obj));
else if (canRunInThisThread)
callback(obj);
- else if (mustNotTimeout)
- RunInThread(callback, obj, name, log);
else
- Util.FireAndForget(callback, obj, name);
+ Util.FireAndForget(callback, obj, name, !mustNotTimeout);
}
private static void HandleControlCommand(string module, string[] args)
@@ -272,16 +276,16 @@ namespace OpenSim.Framework.Monitoring
MainConsole.Instance.Output("Usage: debug jobengine log ");
return;
}
-
+
// int logLevel;
int logLevel = int.Parse(args[3]);
// if (ConsoleUtil.TryParseConsoleInt(MainConsole.Instance, args[4], out logLevel))
- // {
+ // {
JobEngine.LogLevel = logLevel;
MainConsole.Instance.OutputFormat("Set debug log level to {0}", JobEngine.LogLevel);
// }
}
- else
+ else
{
MainConsole.Instance.OutputFormat("Unrecognized job engine subcommand {0}", subCommand);
}
--
cgit v1.1