Improvements to the ServiceThrottleModule: added a category and an itemid to the interface, so that duplicate requests aren't enqueued more than once.

cpu-performance
Diva Canto 2013-07-16 19:04:30 -07:00
parent 5f27aaa6dd
commit 9432f3c94d
4 changed files with 40 additions and 11 deletions

View File

@ -50,17 +50,15 @@ namespace OpenSim.Region.CoreModules.Framework
private readonly List<Scene> m_scenes = new List<Scene>();
private System.Timers.Timer m_timer = new System.Timers.Timer();
//private OpenSim.Framework.BlockingQueue<GridRegionRequest> m_RequestQueue = new OpenSim.Framework.BlockingQueue<GridRegionRequest>();
// private OpenSim.Framework.DoubleQueue<GridRegionRequest> m_RequestQueue = new OpenSim.Framework.DoubleQueue<GridRegionRequest>();
//private Queue<GridRegionRequest> m_RequestQueue = new Queue<GridRegionRequest>();
private Queue<Action> m_RequestQueue = new Queue<Action>();
private Dictionary<string, List<string>> m_Pending = new Dictionary<string, List<string>>();
private int m_Interval;
#region ISharedRegionModule
public void Initialise(IConfigSource config)
{
m_Interval = Util.GetConfigVarFromSections<int>(config, "Interval", new string[] { "ServiceThrottle" }, 2000);
m_Interval = Util.GetConfigVarFromSections<int>(config, "Interval", new string[] { "ServiceThrottle" }, 5000);
m_timer = new System.Timers.Timer();
m_timer.AutoReset = false;
@ -159,18 +157,37 @@ namespace OpenSim.Region.CoreModules.Framework
client.SendRegionHandle(regionID, r.RegionHandle);
};
lock (m_RequestQueue)
m_RequestQueue.Enqueue(action);
Enqueue("region", regionID.ToString(), action);
}
#endregion Events
#region IServiceThrottleModule
public void Enqueue(Action continuation)
public void Enqueue(string category, string itemid, Action continuation)
{
m_RequestQueue.Enqueue(continuation);
lock (m_RequestQueue)
{
if (m_Pending.ContainsKey(category))
{
if (m_Pending[category].Contains(itemid))
// Don't enqueue, it's already pending
return;
}
else
m_Pending.Add(category, new List<string>());
m_Pending[category].Add(itemid);
m_RequestQueue.Enqueue(delegate
{
continuation();
lock (m_RequestQueue)
{
m_Pending[category].Remove(itemid);
}
});
}
}
#endregion IServiceThrottleModule

View File

@ -173,7 +173,7 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement
}
// Not found in cache, queue continuation
m_ServiceThrottle.Enqueue(delegate
m_ServiceThrottle.Enqueue("name", uuid.ToString(), delegate
{
//m_log.DebugFormat("[YYY]: Name request {0}", uuid);
bool foundRealName = TryGetUserNames(uuid, names);

View File

@ -5,7 +5,15 @@ namespace OpenSim.Region.Framework.Interfaces
{
public interface IServiceThrottleModule
{
void Enqueue(Action continuation);
/// <summary>
/// Enqueue a continuation meant to get a resource from elsewhere.
/// As usual with CPS, caller beware: if that continuation is a never-ending computation,
/// the whole thread will be blocked, and no requests are processed
/// </summary>
/// <param name="category">Category of the resource (e.g. name, region)</param>
/// <param name="itemid">The resource identifier</param>
/// <param name="continuation">The continuation to be executed</param>
void Enqueue(string category, string itemid, Action continuation);
}
}

View File

@ -1727,5 +1727,9 @@ MaxStringSpace = 0
;; {MaxDistance} {} {Cut-off distance at which sounds will not be sent to users} {100.0}
MaxDistance = 100.0
[ServiceThrottle]
;; Default time interval (in ms) for the throttle service thread to wake up
Interval = 5000
[Modules]
Include-modules = "addon-modules/*/config/*.ini"