Merge branch 'melanie_test' into prioritization

This makes SmartThreadPool configurable and also makes it the default, since
the regular thread pool simply stinks.
prioritization
Melanie 2009-10-22 07:02:21 +01:00
commit b35fbe1f98
6 changed files with 102 additions and 83 deletions

View File

@ -29,7 +29,7 @@ namespace OpenSim
{
public class VersionInfo
{
private const string VERSION_NUMBER = "0.6.8";
private const string VERSION_NUMBER = "0.6.8-mel_t";
private const Flavour VERSION_FLAVOUR = Flavour.Dev;
public enum Flavour

View File

@ -41,12 +41,14 @@ using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml;
using System.Threading;
using log4net;
using Nini.Config;
using Nwc.XmlRpc;
using BclExtras;
using OpenMetaverse;
using OpenMetaverse.StructuredData;
using Amib.Threading;
namespace OpenSim.Framework
{
@ -67,6 +69,8 @@ namespace OpenSim.Framework
/// </summary>
public class Util
{
private static SmartThreadPool m_ThreadPool = null;
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private static uint nextXferID = 5000;
@ -83,7 +87,7 @@ namespace OpenSim.Framework
public static readonly Regex UUIDPattern
= new Regex("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$");
public static FireAndForgetMethod FireAndForgetMethod = FireAndForgetMethod.UnsafeQueueUserWorkItem;
public static FireAndForgetMethod FireAndForgetMethod = FireAndForgetMethod.SmartThreadPool;
/// <summary>
/// Linear interpolates B<->C using percent A
@ -1315,6 +1319,23 @@ namespace OpenSim.Framework
FireAndForget(callback, null);
}
public static void SetMaxThreads(int maxThreads)
{
if (m_ThreadPool != null)
return;
STPStartInfo startInfo = new STPStartInfo();
startInfo.IdleTimeout = 2000; // 2 seconds
startInfo.MaxWorkerThreads = maxThreads;
startInfo.MinWorkerThreads = 2;
startInfo.StackSize = 524288;
startInfo.ThreadPriority = ThreadPriority.Normal;
startInfo.StartSuspended = false;
m_ThreadPool = new SmartThreadPool(startInfo);
}
public static void FireAndForget(System.Threading.WaitCallback callback, object obj)
{
switch (FireAndForgetMethod)
@ -1330,8 +1351,7 @@ namespace OpenSim.Framework
wrapper.FireAndForget(callback, obj);
break;
case FireAndForgetMethod.SmartThreadPool:
Amib.Threading.SmartThreadPool stp = Singleton.GetInstance<Amib.Threading.SmartThreadPool>();
stp.QueueWorkItem(delegate(object o) { callback(o); return null; }, obj);
m_ThreadPool.QueueWorkItem(delegate(object o) { callback(o); return null; }, obj);
break;
case FireAndForgetMethod.Thread:
System.Threading.Thread thread = new System.Threading.Thread(delegate(object o) { callback(o); });

View File

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

View File

@ -133,13 +133,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
return lease;
}
protected virtual void ConditionalScriptSleep(int delay)
{
// Uncomment to get SL compatibility!
//
// ScriptSleep(delay);
}
protected virtual void ScriptSleep(int delay)
{
delay = (int)((float)delay * m_ScriptDelayFactor);
@ -1682,7 +1675,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
{
m_host.AddScriptLPS(1);
SetTexture(m_host, texture, face);
ConditionalScriptSleep(200);
ScriptSleep(200);
}
public void llSetLinkTexture(int linknumber, string texture, int face)
@ -1694,7 +1687,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
foreach (SceneObjectPart part in parts)
SetTexture(part, texture, face);
ConditionalScriptSleep(200);
ScriptSleep(200);
}
protected void SetTexture(SceneObjectPart part, string texture, int face)
@ -1739,7 +1732,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
m_host.AddScriptLPS(1);
ScaleTexture(m_host, u, v, face);
ConditionalScriptSleep(200);
ScriptSleep(200);
}
protected void ScaleTexture(SceneObjectPart part, double u, double v, int face)
@ -1775,7 +1768,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
{
m_host.AddScriptLPS(1);
OffsetTexture(m_host, u, v, face);
ConditionalScriptSleep(200);
ScriptSleep(200);
}
protected void OffsetTexture(SceneObjectPart part, double u, double v, int face)
@ -1811,7 +1804,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
{
m_host.AddScriptLPS(1);
RotateTexture(m_host, rotation, face);
ConditionalScriptSleep(200);
ScriptSleep(200);
}
protected void RotateTexture(SceneObjectPart part, double rotation, int face)
@ -2283,7 +2276,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
{
m_host.AddScriptLPS(1);
m_host.PreloadSound(sound);
ConditionalScriptSleep(1000);
ScriptSleep(1000);
}
/// <summary>
@ -2575,28 +2568,28 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
{
m_host.AddScriptLPS(1);
Deprecated("llMakeExplosion");
ConditionalScriptSleep(100);
ScriptSleep(100);
}
public void llMakeFountain(int particles, double scale, double vel, double lifetime, double arc, int bounce, string texture, LSL_Vector offset, double bounce_offset)
{
m_host.AddScriptLPS(1);
Deprecated("llMakeFountain");
ConditionalScriptSleep(100);
ScriptSleep(100);
}
public void llMakeSmoke(int particles, double scale, double vel, double lifetime, double arc, string texture, LSL_Vector offset)
{
m_host.AddScriptLPS(1);
Deprecated("llMakeSmoke");
ConditionalScriptSleep(100);
ScriptSleep(100);
}
public void llMakeFire(int particles, double scale, double vel, double lifetime, double arc, string texture, LSL_Vector offset)
{
m_host.AddScriptLPS(1);
Deprecated("llMakeFire");
ConditionalScriptSleep(100);
ScriptSleep(100);
}
public void llRezAtRoot(string inventory, LSL_Vector pos, LSL_Vector vel, LSL_Rotation rot, int param)
@ -2655,7 +2648,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
}
// Variable script delay? (see (http://wiki.secondlife.com/wiki/LSL_Delay)
ScriptSleep((int)((groupmass * velmag) / 10));
ConditionalScriptSleep(100);
ScriptSleep(100);
return;
}
}
@ -2941,7 +2934,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
}
emailModule.SendEmail(m_host.UUID, address, subject, message);
ConditionalScriptSleep(20000);
ScriptSleep(20000);
}
public void llGetNextEmail(string address, string subject)
@ -3745,7 +3738,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
// destination is an object
World.MoveTaskInventoryItem(destId, m_host, objId);
}
ConditionalScriptSleep(3000);
ScriptSleep(3000);
}
public void llRemoveInventory(string name)
@ -3846,7 +3839,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
AsyncCommands.
DataserverPlugin.DataserverReply(rq.ToString(), reply);
ConditionalScriptSleep(100);
ScriptSleep(100);
return tid.ToString();
}
@ -3884,11 +3877,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
reply);
});
ConditionalScriptSleep(1000);
ScriptSleep(1000);
return tid.ToString();
}
}
ConditionalScriptSleep(1000);
ScriptSleep(1000);
return String.Empty;
}
@ -3916,7 +3909,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
}
}
}
ConditionalScriptSleep(5000);
ScriptSleep(5000);
}
public void llTextBox(string avatar, string message, int chat_channel)
@ -5376,7 +5369,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
{
m_host.AddScriptLPS(1);
m_host.AdjustSoundGain(volume);
ConditionalScriptSleep(100);
ScriptSleep(100);
}
public void llSetSoundQueueing(int queue)
@ -5459,7 +5452,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
World.TeleportClientHome(agentId, presence.ControllingClient);
}
}
ConditionalScriptSleep(5000);
ScriptSleep(5000);
}
public LSL_List llParseString2List(string str, LSL_List separators, LSL_List in_spacers)
@ -6151,7 +6144,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
land.ParcelAccessList.Add(entry);
}
}
ConditionalScriptSleep(100);
ScriptSleep(100);
}
public void llSetTouchText(string text)
@ -6248,7 +6241,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
av, m_host.Name, m_host.UUID, m_host.OwnerID,
message, new UUID("00000000-0000-2222-3333-100000001000"), chat_channel, buts);
ConditionalScriptSleep(1000);
ScriptSleep(1000);
}
public void llVolumeDetect(int detect)
@ -6273,7 +6266,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
m_host.AddScriptLPS(1);
// Report an error as it does in SL
ShoutError("Deprecated. Please use llRemoteLoadScriptPin instead.");
ConditionalScriptSleep(3000);
ScriptSleep(3000);
}
public void llSetRemoteScriptAccessPin(int pin)
@ -6359,14 +6352,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams("remote_data", resobj,
new DetectParams[0]));
}
ConditionalScriptSleep(1000);
ScriptSleep(1000);
}
public LSL_String llSendRemoteData(string channel, string dest, int idata, string sdata)
{
m_host.AddScriptLPS(1);
IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
ConditionalScriptSleep(3000);
ScriptSleep(3000);
return (xmlrpcMod.SendRemoteData(m_localID, m_itemID, channel, dest, idata, sdata)).ToString();
}
@ -6375,7 +6368,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
m_host.AddScriptLPS(1);
IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
xmlrpcMod.RemoteDataReply(channel, message_id, sdata, idata);
ConditionalScriptSleep(3000);
ScriptSleep(3000);
}
public void llCloseRemoteDataChannel(string channel)
@ -6383,7 +6376,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
m_host.AddScriptLPS(1);
IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
xmlrpcMod.CloseXMLRPCChannel((UUID)channel);
ConditionalScriptSleep(1000);
ScriptSleep(1000);
}
public LSL_String llMD5String(string src, int nonce)
@ -7114,7 +7107,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
{
m_host.AddScriptLPS(1);
Deprecated("llXorBase64Strings");
ConditionalScriptSleep(300);
ScriptSleep(300);
return String.Empty;
}
@ -7162,7 +7155,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
land.SetMusicUrl(url);
ConditionalScriptSleep(2000);
ScriptSleep(2000);
}
public LSL_Vector llGetRootPosition()
@ -8207,7 +8200,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
case 5: // DATA_SIM_POS
if (info == null)
{
ConditionalScriptSleep(1000);
ScriptSleep(1000);
return UUID.Zero.ToString();
}
reply = new LSL_Vector(
@ -8224,7 +8217,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
case 7: // DATA_SIM_RATING
if (info == null)
{
ConditionalScriptSleep(1000);
ScriptSleep(1000);
return UUID.Zero.ToString();
}
int access = info.Maturity;
@ -8243,7 +8236,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
reply = "OpenSim";
break;
default:
ConditionalScriptSleep(1000);
ScriptSleep(1000);
return UUID.Zero.ToString(); // Raise no event
}
UUID rq = UUID.Random();
@ -8254,7 +8247,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
AsyncCommands.
DataserverPlugin.DataserverReply(rq.ToString(), reply);
ConditionalScriptSleep(1000);
ScriptSleep(1000);
return tid.ToString();
}
catch(Exception)
@ -8398,7 +8391,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
dm.SendUrlToUser(
new UUID(avatar_id), m_host.Name, m_host.UUID, m_host.OwnerID, false, message, url);
ConditionalScriptSleep(10000);
ScriptSleep(10000);
}
public void llParcelMediaCommandList(LSL_List commandList)
@ -8634,7 +8627,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
time);
}
}
ConditionalScriptSleep(2000);
ScriptSleep(2000);
}
public LSL_List llParcelMediaQuery(LSL_List aList)
@ -8672,7 +8665,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
}
}
ConditionalScriptSleep(2000);
ScriptSleep(2000);
return list;
}
@ -8681,7 +8674,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
m_host.AddScriptLPS(1);
Int64 tmp = 0;
Math.DivRem(Convert.ToInt64(Math.Pow(a, b)), c, out tmp);
ConditionalScriptSleep(1000);
ScriptSleep(1000);
return Convert.ToInt32(tmp);
}
@ -8785,7 +8778,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
public void llSetPrimURL(string url)
{
m_host.AddScriptLPS(1);
ConditionalScriptSleep(2000);
ScriptSleep(2000);
}
/// <summary>
@ -8796,7 +8789,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
{
m_host.AddScriptLPS(1);
ShoutError("llRefreshPrimURL - not yet supported");
ConditionalScriptSleep(20000);
ScriptSleep(20000);
}
public LSL_String llEscapeURL(string url)
@ -8838,7 +8831,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
new Vector3((float)pos.x, (float)pos.y, (float)pos.z),
new Vector3((float)lookAt.x, (float)lookAt.y, (float)lookAt.z));
}
ConditionalScriptSleep(1000);
ScriptSleep(1000);
}
public void llAddToLandBanList(string avatar, double hours)
@ -8857,7 +8850,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
land.ParcelAccessList.Add(entry);
}
}
ConditionalScriptSleep(100);
ScriptSleep(100);
}
public void llRemoveFromLandPassList(string avatar)
@ -8879,7 +8872,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
}
}
}
ConditionalScriptSleep(100);
ScriptSleep(100);
}
public void llRemoveFromLandBanList(string avatar)
@ -8901,7 +8894,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
}
}
}
ConditionalScriptSleep(100);
ScriptSleep(100);
}
public void llSetCameraParams(LSL_List rules)
@ -9163,7 +9156,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
}
}
}
ConditionalScriptSleep(100);
ScriptSleep(100);
}
public void llResetLandPassList()
@ -9180,7 +9173,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
}
}
}
ConditionalScriptSleep(100);
ScriptSleep(100);
}
public LSL_Integer llGetParcelPrimCount(LSL_Vector pos, int category, int sim_wide)
@ -9259,7 +9252,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
ret.Add(detectedParams.Value);
}
}
ConditionalScriptSleep(2000);
ScriptSleep(2000);
return ret;
}
@ -9517,7 +9510,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
AsyncCommands.
DataserverPlugin.DataserverReply(assetID.ToString(),
NotecardCache.GetLines(assetID).ToString());
ConditionalScriptSleep(100);
ScriptSleep(100);
return tid.ToString();
}
@ -9539,7 +9532,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
NotecardCache.GetLines(id).ToString());
});
ConditionalScriptSleep(100);
ScriptSleep(100);
return tid.ToString();
}
@ -9578,7 +9571,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
{
AsyncCommands.DataserverPlugin.DataserverReply(assetID.ToString(),
NotecardCache.GetLine(assetID, line, m_notecardLineReadCharsMax));
ConditionalScriptSleep(100);
ScriptSleep(100);
return tid.ToString();
}
@ -9599,7 +9592,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
NotecardCache.GetLine(id, line, m_notecardLineReadCharsMax));
});
ConditionalScriptSleep(100);
ScriptSleep(100);
return tid.ToString();
}
}

View File

@ -39,7 +39,7 @@
; Sets the method that OpenSim will use to fire asynchronous
; events. Valid values are UnsafeQueueUserWorkItem,
; QueueUserWorkItem, BeginInvoke, SmartThreadPool, and Thread
async_call_method = UnsafeQueueUserWorkItem
; async_call_method = SmartThreadPool
; ##
; ## CLIENTS
@ -51,6 +51,9 @@
; Set this to the DLL containing the client stack to use.
clientstack_plugin="OpenSim.Region.ClientStack.LindenUDP.dll"
; Max threads to allocate on the FireAndForget pool
MaxPoolThreads = 15
; ##
; ## REGIONS
; ##

View File

@ -117,6 +117,28 @@
</Files>
</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">
<Configuration name="Debug">
<Options>
@ -145,6 +167,7 @@
<Reference name="Nini.dll" />
<Reference name="log4net.dll"/>
<Reference name="Mono.Addins.dll" />
<Reference name="SmartThreadPool" />
<Files>
<Match pattern="*.cs" recurse="false"/>
<Match path="Client" pattern="*.cs" recurse="true"/>
@ -2387,28 +2410,6 @@
</Files>
</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">
<Configuration name="Debug">
<Options>