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
prioritization
Melanie 2009-10-22 02:28:53 +01:00
parent 9ec55df988
commit 8a336c6860
4 changed files with 50 additions and 34 deletions

View File

@ -41,12 +41,14 @@ using System.Security.Cryptography;
using System.Text; using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Xml; using System.Xml;
using System.Threading;
using log4net; using log4net;
using Nini.Config; using Nini.Config;
using Nwc.XmlRpc; using Nwc.XmlRpc;
using BclExtras; using BclExtras;
using OpenMetaverse; using OpenMetaverse;
using OpenMetaverse.StructuredData; using OpenMetaverse.StructuredData;
using Amib.Threading;
namespace OpenSim.Framework namespace OpenSim.Framework
{ {
@ -55,6 +57,8 @@ namespace OpenSim.Framework
/// </summary> /// </summary>
public class Util public class Util
{ {
private static SmartThreadPool m_ThreadPool = null;
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private static uint nextXferID = 5000; private static uint nextXferID = 5000;
@ -1293,22 +1297,28 @@ namespace OpenSim.Framework
System.Threading.ThreadPool.UnsafeQueueUserWorkItem(callback, null); System.Threading.ThreadPool.UnsafeQueueUserWorkItem(callback, null);
} }
public static void FireAndForget(System.Threading.WaitCallback callback, object obj) public static void SetMaxThreads(int maxThreads)
{ {
//FireAndForgetWrapper wrapper = Singleton.GetInstance<FireAndForgetWrapper>(); STPStartInfo startInfo = new STPStartInfo();
//wrapper.FireAndForget(callback, obj); startInfo.IdleTimeout = 2000; // 2 seconds
System.Threading.ThreadPool.UnsafeQueueUserWorkItem(callback, obj); startInfo.MaxWorkerThreads = maxThreads;
startInfo.MinWorkerThreads = 5;
startInfo.StackSize = 524288;
startInfo.ThreadPriority = ThreadPriority.Normal;
startInfo.StartSuspended = false;
m_ThreadPool = new SmartThreadPool(startInfo);
} }
/*private static void EndFireAndForget(IAsyncResult ar) public static void FireAndForget(System.Threading.WaitCallback callback, object obj)
{ {
System.Threading.WaitCallback callback = (System.Threading.WaitCallback)ar.AsyncState; m_ThreadPool.QueueWorkItem(new WorkItemCallback(delegate(object o)
{
try { callback.EndInvoke(ar); } callback(o);
catch (Exception ex) { m_log.Error("[UTIL]: Asynchronous method threw an exception: " + ex.Message, ex); } return null;
}), obj);
ar.AsyncWaitHandle.Close(); }
}*/
#endregion FireAndForget Threading Pattern #endregion FireAndForget Threading Pattern
} }

View File

@ -67,6 +67,8 @@ namespace OpenSim
IConfig startupConfig = m_config.Source.Configs["Startup"]; IConfig startupConfig = m_config.Source.Configs["Startup"];
Util.SetMaxThreads(startupConfig.GetInt("MaxPoolThreads", 30));
if (startupConfig != null) if (startupConfig != null)
{ {
m_startupCommandsFile = startupConfig.GetString("startup_console_commands_file", "startup_commands.txt"); m_startupCommandsFile = startupConfig.GetString("startup_console_commands_file", "startup_commands.txt");

View File

@ -42,6 +42,9 @@
; Set this to the DLL containing the client stack to use. ; Set this to the DLL containing the client stack to use.
clientstack_plugin="OpenSim.Region.ClientStack.LindenUDP.dll" clientstack_plugin="OpenSim.Region.ClientStack.LindenUDP.dll"
; Max threads to allocate on the FireAndForget pool
MaxPoolThreads = 30
; ## ; ##
; ## REGIONS ; ## REGIONS
; ## ; ##

View File

@ -117,6 +117,28 @@
</Files> </Files>
</Project> </Project>
<Project frameworkVersion="v3_5" name="SmartThreadPool" path="ThirdParty/SmartThreadPool" type="Library">
<Configuration name="Debug">
<Options>
<OutputPath>../../bin/</OutputPath>
</Options>
</Configuration>
<Configuration name="Release">
<Options>
<OutputPath>../../bin/</OutputPath>
</Options>
</Configuration>
<ReferencePath>../../bin/</ReferencePath>
<Reference name="System"/>
<Reference name="System.Xml"/>
<Reference name="System.Data"/>
<Reference name="System.Web"/>
<Files>
<Match pattern="*.cs" recurse="false"/>
</Files>
</Project>
<Project frameworkVersion="v3_5" name="OpenSim.Framework" path="OpenSim/Framework" type="Library"> <Project frameworkVersion="v3_5" name="OpenSim.Framework" path="OpenSim/Framework" type="Library">
<Configuration name="Debug"> <Configuration name="Debug">
<Options> <Options>
@ -145,6 +167,7 @@
<Reference name="Nini.dll" /> <Reference name="Nini.dll" />
<Reference name="log4net.dll"/> <Reference name="log4net.dll"/>
<Reference name="Mono.Addins.dll" /> <Reference name="Mono.Addins.dll" />
<Reference name="SmartThreadPool" />
<Files> <Files>
<Match pattern="*.cs" recurse="false"/> <Match pattern="*.cs" recurse="false"/>
<Match path="Client" pattern="*.cs" recurse="true"/> <Match path="Client" pattern="*.cs" recurse="true"/>
@ -2387,28 +2410,6 @@
</Files> </Files>
</Project> </Project>
<Project frameworkVersion="v3_5" name="SmartThreadPool" path="ThirdParty/SmartThreadPool" type="Library">
<Configuration name="Debug">
<Options>
<OutputPath>../../bin/</OutputPath>
</Options>
</Configuration>
<Configuration name="Release">
<Options>
<OutputPath>../../bin/</OutputPath>
</Options>
</Configuration>
<ReferencePath>../../bin/</ReferencePath>
<Reference name="System"/>
<Reference name="System.Xml"/>
<Reference name="System.Data"/>
<Reference name="System.Web"/>
<Files>
<Match pattern="*.cs" recurse="false"/>
</Files>
</Project>
<Project frameworkVersion="v3_5" name="OpenSim.Region.ScriptEngine.Shared" path="OpenSim/Region/ScriptEngine/Shared" type="Library"> <Project frameworkVersion="v3_5" name="OpenSim.Region.ScriptEngine.Shared" path="OpenSim/Region/ScriptEngine/Shared" type="Library">
<Configuration name="Debug"> <Configuration name="Debug">
<Options> <Options>