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 | |
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 '')
-rw-r--r-- | OpenSim/Framework/Util.cs | 34 | ||||
-rw-r--r-- | OpenSim/Region/Application/OpenSim.cs | 2 | ||||
-rw-r--r-- | bin/OpenSim.ini.example | 3 | ||||
-rw-r--r-- | prebuild.xml | 45 |
4 files changed, 50 insertions, 34 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 | } |
diff --git a/OpenSim/Region/Application/OpenSim.cs b/OpenSim/Region/Application/OpenSim.cs index 143dd2a..42e2a1e 100644 --- a/OpenSim/Region/Application/OpenSim.cs +++ b/OpenSim/Region/Application/OpenSim.cs | |||
@@ -67,6 +67,8 @@ 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", 30)); | ||
71 | |||
70 | if (startupConfig != null) | 72 | if (startupConfig != null) |
71 | { | 73 | { |
72 | m_startupCommandsFile = startupConfig.GetString("startup_console_commands_file", "startup_commands.txt"); | 74 | m_startupCommandsFile = startupConfig.GetString("startup_console_commands_file", "startup_commands.txt"); |
diff --git a/bin/OpenSim.ini.example b/bin/OpenSim.ini.example index 2d56f4e..92e6d91 100644 --- a/bin/OpenSim.ini.example +++ b/bin/OpenSim.ini.example | |||
@@ -42,6 +42,9 @@ | |||
42 | ; Set this to the DLL containing the client stack to use. | 42 | ; Set this to the DLL containing the client stack to use. |
43 | clientstack_plugin="OpenSim.Region.ClientStack.LindenUDP.dll" | 43 | clientstack_plugin="OpenSim.Region.ClientStack.LindenUDP.dll" |
44 | 44 | ||
45 | ; Max threads to allocate on the FireAndForget pool | ||
46 | MaxPoolThreads = 30 | ||
47 | |||
45 | ; ## | 48 | ; ## |
46 | ; ## REGIONS | 49 | ; ## REGIONS |
47 | ; ## | 50 | ; ## |
diff --git a/prebuild.xml b/prebuild.xml index e17da9a..81f907d 100644 --- a/prebuild.xml +++ b/prebuild.xml | |||
@@ -117,6 +117,28 @@ | |||
117 | </Files> | 117 | </Files> |
118 | </Project> | 118 | </Project> |
119 | 119 | ||
120 | <Project frameworkVersion="v3_5" name="SmartThreadPool" path="ThirdParty/SmartThreadPool" type="Library"> | ||
121 | <Configuration name="Debug"> | ||
122 | <Options> | ||
123 | <OutputPath>../../bin/</OutputPath> | ||
124 | </Options> | ||
125 | </Configuration> | ||
126 | <Configuration name="Release"> | ||
127 | <Options> | ||
128 | <OutputPath>../../bin/</OutputPath> | ||
129 | </Options> | ||
130 | </Configuration> | ||
131 | |||
132 | <ReferencePath>../../bin/</ReferencePath> | ||
133 | <Reference name="System"/> | ||
134 | <Reference name="System.Xml"/> | ||
135 | <Reference name="System.Data"/> | ||
136 | <Reference name="System.Web"/> | ||
137 | <Files> | ||
138 | <Match pattern="*.cs" recurse="false"/> | ||
139 | </Files> | ||
140 | </Project> | ||
141 | |||
120 | <Project frameworkVersion="v3_5" name="OpenSim.Framework" path="OpenSim/Framework" type="Library"> | 142 | <Project frameworkVersion="v3_5" name="OpenSim.Framework" path="OpenSim/Framework" type="Library"> |
121 | <Configuration name="Debug"> | 143 | <Configuration name="Debug"> |
122 | <Options> | 144 | <Options> |
@@ -145,6 +167,7 @@ | |||
145 | <Reference name="Nini.dll" /> | 167 | <Reference name="Nini.dll" /> |
146 | <Reference name="log4net.dll"/> | 168 | <Reference name="log4net.dll"/> |
147 | <Reference name="Mono.Addins.dll" /> | 169 | <Reference name="Mono.Addins.dll" /> |
170 | <Reference name="SmartThreadPool" /> | ||
148 | <Files> | 171 | <Files> |
149 | <Match pattern="*.cs" recurse="false"/> | 172 | <Match pattern="*.cs" recurse="false"/> |
150 | <Match path="Client" pattern="*.cs" recurse="true"/> | 173 | <Match path="Client" pattern="*.cs" recurse="true"/> |
@@ -2387,28 +2410,6 @@ | |||
2387 | </Files> | 2410 | </Files> |
2388 | </Project> | 2411 | </Project> |
2389 | 2412 | ||
2390 | <Project frameworkVersion="v3_5" name="SmartThreadPool" path="ThirdParty/SmartThreadPool" type="Library"> | ||
2391 | <Configuration name="Debug"> | ||
2392 | <Options> | ||
2393 | <OutputPath>../../bin/</OutputPath> | ||
2394 | </Options> | ||
2395 | </Configuration> | ||
2396 | <Configuration name="Release"> | ||
2397 | <Options> | ||
2398 | <OutputPath>../../bin/</OutputPath> | ||
2399 | </Options> | ||
2400 | </Configuration> | ||
2401 | |||
2402 | <ReferencePath>../../bin/</ReferencePath> | ||
2403 | <Reference name="System"/> | ||
2404 | <Reference name="System.Xml"/> | ||
2405 | <Reference name="System.Data"/> | ||
2406 | <Reference name="System.Web"/> | ||
2407 | <Files> | ||
2408 | <Match pattern="*.cs" recurse="false"/> | ||
2409 | </Files> | ||
2410 | </Project> | ||
2411 | |||
2412 | <Project frameworkVersion="v3_5" name="OpenSim.Region.ScriptEngine.Shared" path="OpenSim/Region/ScriptEngine/Shared" type="Library"> | 2413 | <Project frameworkVersion="v3_5" name="OpenSim.Region.ScriptEngine.Shared" path="OpenSim/Region/ScriptEngine/Shared" type="Library"> |
2413 | <Configuration name="Debug"> | 2414 | <Configuration name="Debug"> |
2414 | <Options> | 2415 | <Options> |