diff options
author | Melanie | 2009-10-22 02:28:53 +0100 |
---|---|---|
committer | Melanie | 2009-10-22 02:28:53 +0100 |
commit | 8a336c6860d66b9fbba6922c32e7a57fd355c57e (patch) | |
tree | b519399cadf118bdb5a48fce9597e65d79667a0e /OpenSim/Framework | |
parent | Mark new version (diff) | |
download | opensim-SC_OLD-8a336c6860d66b9fbba6922c32e7a57fd355c57e.zip opensim-SC_OLD-8a336c6860d66b9fbba6922c32e7a57fd355c57e.tar.gz opensim-SC_OLD-8a336c6860d66b9fbba6922c32e7a57fd355c57e.tar.bz2 opensim-SC_OLD-8a336c6860d66b9fbba6922c32e7a57fd355c57e.tar.xz |
Add MaxPoolThreads in startup to limit the size of the thread pool used
for FireAndForget. This lets us limit concurrency to make OpenSim play nice
Diffstat (limited to 'OpenSim/Framework')
-rw-r--r-- | OpenSim/Framework/Util.cs | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index d5ae3b7..9dfb75e 100644 --- a/OpenSim/Framework/Util.cs +++ b/OpenSim/Framework/Util.cs | |||
@@ -41,12 +41,14 @@ using System.Security.Cryptography; | |||
41 | using System.Text; | 41 | using System.Text; |
42 | using System.Text.RegularExpressions; | 42 | using System.Text.RegularExpressions; |
43 | using System.Xml; | 43 | using System.Xml; |
44 | using System.Threading; | ||
44 | using log4net; | 45 | using log4net; |
45 | using Nini.Config; | 46 | using Nini.Config; |
46 | using Nwc.XmlRpc; | 47 | using Nwc.XmlRpc; |
47 | using BclExtras; | 48 | using BclExtras; |
48 | using OpenMetaverse; | 49 | using OpenMetaverse; |
49 | using OpenMetaverse.StructuredData; | 50 | using OpenMetaverse.StructuredData; |
51 | using Amib.Threading; | ||
50 | 52 | ||
51 | namespace OpenSim.Framework | 53 | namespace OpenSim.Framework |
52 | { | 54 | { |
@@ -55,6 +57,8 @@ namespace OpenSim.Framework | |||
55 | /// </summary> | 57 | /// </summary> |
56 | public class Util | 58 | public class Util |
57 | { | 59 | { |
60 | private static SmartThreadPool m_ThreadPool = null; | ||
61 | |||
58 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 62 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
59 | 63 | ||
60 | private static uint nextXferID = 5000; | 64 | private static uint nextXferID = 5000; |
@@ -1293,22 +1297,28 @@ namespace OpenSim.Framework | |||
1293 | System.Threading.ThreadPool.UnsafeQueueUserWorkItem(callback, null); | 1297 | System.Threading.ThreadPool.UnsafeQueueUserWorkItem(callback, null); |
1294 | } | 1298 | } |
1295 | 1299 | ||
1296 | public static void FireAndForget(System.Threading.WaitCallback callback, object obj) | 1300 | public static void SetMaxThreads(int maxThreads) |
1297 | { | 1301 | { |
1298 | //FireAndForgetWrapper wrapper = Singleton.GetInstance<FireAndForgetWrapper>(); | 1302 | STPStartInfo startInfo = new STPStartInfo(); |
1299 | //wrapper.FireAndForget(callback, obj); | 1303 | startInfo.IdleTimeout = 2000; // 2 seconds |
1300 | System.Threading.ThreadPool.UnsafeQueueUserWorkItem(callback, obj); | 1304 | startInfo.MaxWorkerThreads = maxThreads; |
1301 | } | 1305 | startInfo.MinWorkerThreads = 5; |
1306 | startInfo.StackSize = 524288; | ||
1307 | startInfo.ThreadPriority = ThreadPriority.Normal; | ||
1302 | 1308 | ||
1303 | /*private static void EndFireAndForget(IAsyncResult ar) | 1309 | startInfo.StartSuspended = false; |
1304 | { | ||
1305 | System.Threading.WaitCallback callback = (System.Threading.WaitCallback)ar.AsyncState; | ||
1306 | 1310 | ||
1307 | try { callback.EndInvoke(ar); } | 1311 | m_ThreadPool = new SmartThreadPool(startInfo); |
1308 | catch (Exception ex) { m_log.Error("[UTIL]: Asynchronous method threw an exception: " + ex.Message, ex); } | 1312 | } |
1309 | 1313 | ||
1310 | ar.AsyncWaitHandle.Close(); | 1314 | public static void FireAndForget(System.Threading.WaitCallback callback, object obj) |
1311 | }*/ | 1315 | { |
1316 | m_ThreadPool.QueueWorkItem(new WorkItemCallback(delegate(object o) | ||
1317 | { | ||
1318 | callback(o); | ||
1319 | return null; | ||
1320 | }), obj); | ||
1321 | } | ||
1312 | 1322 | ||
1313 | #endregion FireAndForget Threading Pattern | 1323 | #endregion FireAndForget Threading Pattern |
1314 | } | 1324 | } |