aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJohn Hurliman2009-10-22 01:30:12 -0700
committerJohn Hurliman2009-10-22 01:30:12 -0700
commit2f394b7e7ebf991c7a70f93bf251d26d8043aaa2 (patch)
tree28e1635d47af4cfe4337d1d68f30090860ca01ca
parentRemove the "mel_t" from version string (diff)
downloadopensim-SC_OLD-2f394b7e7ebf991c7a70f93bf251d26d8043aaa2.zip
opensim-SC_OLD-2f394b7e7ebf991c7a70f93bf251d26d8043aaa2.tar.gz
opensim-SC_OLD-2f394b7e7ebf991c7a70f93bf251d26d8043aaa2.tar.bz2
opensim-SC_OLD-2f394b7e7ebf991c7a70f93bf251d26d8043aaa2.tar.xz
* Allow SmartThreadPool to be initialized without setting max stack size (like the original implementation)
* Only initialize Util's SmartThreadPool if it is actually being used * No longer initializing Util's SmartThreadPool with a custom max stack size. From MSDN: "Avoid using this constructor overload. The default stack size used by the Thread(ThreadStart) constructor overload is the recommended stack size for threads."
Diffstat (limited to '')
-rw-r--r--OpenSim/Framework/Util.cs12
-rw-r--r--OpenSim/Region/Application/OpenSim.cs7
-rw-r--r--ThirdParty/SmartThreadPool/SmartThreadPool.cs6
-rw-r--r--bin/OpenSim.ini.example14
4 files changed, 27 insertions, 12 deletions
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs
index d09bd6d..167e34d 100644
--- a/OpenSim/Framework/Util.cs
+++ b/OpenSim/Framework/Util.cs
@@ -69,8 +69,6 @@ namespace OpenSim.Framework
69 /// </summary> 69 /// </summary>
70 public class Util 70 public class Util
71 { 71 {
72 private static SmartThreadPool m_ThreadPool = null;
73
74 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 72 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
75 73
76 private static uint nextXferID = 5000; 74 private static uint nextXferID = 5000;
@@ -79,6 +77,9 @@ namespace OpenSim.Framework
79 private static string regexInvalidFileChars = "[" + new String(Path.GetInvalidFileNameChars()) + "]"; 77 private static string regexInvalidFileChars = "[" + new String(Path.GetInvalidFileNameChars()) + "]";
80 private static string regexInvalidPathChars = "[" + new String(Path.GetInvalidPathChars()) + "]"; 78 private static string regexInvalidPathChars = "[" + new String(Path.GetInvalidPathChars()) + "]";
81 private static object XferLock = new object(); 79 private static object XferLock = new object();
80 /// <summary>Thread pool used for Util.FireAndForget if
81 /// FireAndForgetMethod.SmartThreadPool is used</summary>
82 private static SmartThreadPool m_ThreadPool;
82 83
83 // Unix-epoch starts at January 1st 1970, 00:00:00 UTC. And all our times in the server are (or at least should be) in UTC. 84 // Unix-epoch starts at January 1st 1970, 00:00:00 UTC. And all our times in the server are (or at least should be) in UTC.
84 private static readonly DateTime unixEpoch = 85 private static readonly DateTime unixEpoch =
@@ -1319,8 +1320,11 @@ namespace OpenSim.Framework
1319 FireAndForget(callback, null); 1320 FireAndForget(callback, null);
1320 } 1321 }
1321 1322
1322 public static void SetMaxThreads(int maxThreads) 1323 public static void InitThreadPool(int maxThreads)
1323 { 1324 {
1325 if (maxThreads < 2)
1326 throw new ArgumentOutOfRangeException("maxThreads", "maxThreads must be greater than 2");
1327
1324 if (m_ThreadPool != null) 1328 if (m_ThreadPool != null)
1325 return; 1329 return;
1326 1330
@@ -1328,9 +1332,7 @@ namespace OpenSim.Framework
1328 startInfo.IdleTimeout = 2000; // 2 seconds 1332 startInfo.IdleTimeout = 2000; // 2 seconds
1329 startInfo.MaxWorkerThreads = maxThreads; 1333 startInfo.MaxWorkerThreads = maxThreads;
1330 startInfo.MinWorkerThreads = 2; 1334 startInfo.MinWorkerThreads = 2;
1331 startInfo.StackSize = 524288;
1332 startInfo.ThreadPriority = ThreadPriority.Normal; 1335 startInfo.ThreadPriority = ThreadPriority.Normal;
1333
1334 startInfo.StartSuspended = false; 1336 startInfo.StartSuspended = false;
1335 1337
1336 m_ThreadPool = new SmartThreadPool(startInfo); 1338 m_ThreadPool = new SmartThreadPool(startInfo);
diff --git a/OpenSim/Region/Application/OpenSim.cs b/OpenSim/Region/Application/OpenSim.cs
index c04b8c2..26298e7 100644
--- a/OpenSim/Region/Application/OpenSim.cs
+++ b/OpenSim/Region/Application/OpenSim.cs
@@ -67,7 +67,7 @@ namespace OpenSim
67 67
68 IConfig startupConfig = m_config.Source.Configs["Startup"]; 68 IConfig startupConfig = m_config.Source.Configs["Startup"];
69 69
70 Util.SetMaxThreads(startupConfig.GetInt("MaxPoolThreads", 15)); 70 int stpMaxThreads = 15;
71 71
72 if (startupConfig != null) 72 if (startupConfig != null)
73 { 73 {
@@ -100,8 +100,13 @@ namespace OpenSim
100 FireAndForgetMethod asyncCallMethod; 100 FireAndForgetMethod asyncCallMethod;
101 if (!String.IsNullOrEmpty(asyncCallMethodStr) && Utils.EnumTryParse<FireAndForgetMethod>(asyncCallMethodStr, out asyncCallMethod)) 101 if (!String.IsNullOrEmpty(asyncCallMethodStr) && Utils.EnumTryParse<FireAndForgetMethod>(asyncCallMethodStr, out asyncCallMethod))
102 Util.FireAndForgetMethod = asyncCallMethod; 102 Util.FireAndForgetMethod = asyncCallMethod;
103
104 stpMaxThreads = startupConfig.GetInt("MaxPoolThreads", 15);
103 } 105 }
104 106
107 if (Util.FireAndForgetMethod == FireAndForgetMethod.SmartThreadPool)
108 Util.InitThreadPool(stpMaxThreads);
109
105 m_log.Info("[OPENSIM MAIN]: Using async_call_method " + Util.FireAndForgetMethod); 110 m_log.Info("[OPENSIM MAIN]: Using async_call_method " + Util.FireAndForgetMethod);
106 } 111 }
107 112
diff --git a/ThirdParty/SmartThreadPool/SmartThreadPool.cs b/ThirdParty/SmartThreadPool/SmartThreadPool.cs
index c21984e..bd52f62 100644
--- a/ThirdParty/SmartThreadPool/SmartThreadPool.cs
+++ b/ThirdParty/SmartThreadPool/SmartThreadPool.cs
@@ -499,7 +499,11 @@ namespace Amib.Threading
499 } 499 }
500 500
501 // Create a new thread 501 // Create a new thread
502 Thread workerThread = new Thread(new ThreadStart(ProcessQueuedItems), _stpStartInfo.StackSize); 502 Thread workerThread;
503 if (_stpStartInfo.StackSize > 0)
504 workerThread = new Thread(ProcessQueuedItems, _stpStartInfo.StackSize);
505 else
506 workerThread = new Thread(ProcessQueuedItems);
503 507
504 // Configure the new thread and start it 508 // Configure the new thread and start it
505 workerThread.Name = "STP " + Name + " Thread #" + _threadCounter; 509 workerThread.Name = "STP " + Name + " Thread #" + _threadCounter;
diff --git a/bin/OpenSim.ini.example b/bin/OpenSim.ini.example
index 79d57d2..08f87d6 100644
--- a/bin/OpenSim.ini.example
+++ b/bin/OpenSim.ini.example
@@ -38,8 +38,15 @@
38 38
39 ; Sets the method that OpenSim will use to fire asynchronous 39 ; Sets the method that OpenSim will use to fire asynchronous
40 ; events. Valid values are UnsafeQueueUserWorkItem, 40 ; events. Valid values are UnsafeQueueUserWorkItem,
41 ; QueueUserWorkItem, BeginInvoke, SmartThreadPool, and Thread 41 ; QueueUserWorkItem, BeginInvoke, SmartThreadPool, and Thread.
42 ; async_call_method = SmartThreadPool 42 ; SmartThreadPool is reported to work well on Mono/Linux, but
43 ; UnsafeQueueUserWorkItem has been benchmarked with better
44 ; performance on .NET/Windows
45 ;async_call_method = SmartThreadPool
46
47 ; Max threads to allocate on the FireAndForget thread pool
48 ; when running with the SmartThreadPool option above
49 MaxPoolThreads = 15
43 50
44 ; ## 51 ; ##
45 ; ## CLIENTS 52 ; ## CLIENTS
@@ -51,9 +58,6 @@
51 ; Set this to the DLL containing the client stack to use. 58 ; Set this to the DLL containing the client stack to use.
52 clientstack_plugin="OpenSim.Region.ClientStack.LindenUDP.dll" 59 clientstack_plugin="OpenSim.Region.ClientStack.LindenUDP.dll"
53 60
54 ; Max threads to allocate on the FireAndForget pool
55 MaxPoolThreads = 15
56
57 ; ## 61 ; ##
58 ; ## REGIONS 62 ; ## REGIONS
59 ; ## 63 ; ##