full change ServiceThrottleModule. Let it still service RegionHandleRequest and UUIDNameRequest but this wrong since they are diferent services. Keeping gambling about not having 2 much overlaps of the 2 kind of requests. Remove double thottling of RegionHandleRequest

melanie
UbitUmarov 2016-11-22 22:24:54 +00:00
parent 1a6cddf807
commit f4745e5a35
3 changed files with 24 additions and 175 deletions

View File

@ -9614,63 +9614,19 @@ namespace OpenSim.Region.ClientStack.LindenUDP
#region Parcel related packets
// acumulate several HandleRegionHandleRequest consecutive overlaping requests
// to be done with minimal resources as possible
// variables temporary here while in test
Queue<UUID> RegionHandleRequests = new Queue<UUID>();
bool RegionHandleRequestsInService = false;
private bool HandleRegionHandleRequest(IClientAPI sender, Packet Pack)
{
UUID currentUUID;
RegionHandleRequest handlerRegionHandleRequest = OnRegionHandleRequest;
if (handlerRegionHandleRequest == null)
return true;
if (handlerRegionHandleRequest != null)
{
RegionHandleRequestPacket rhrPack = (RegionHandleRequestPacket)Pack;
handlerRegionHandleRequest(this, rhrPack.RequestBlock.RegionID);
}
lock (RegionHandleRequests)
{
if (RegionHandleRequestsInService)
{
// we are already busy doing a previus request
// so enqueue it
RegionHandleRequests.Enqueue(rhrPack.RequestBlock.RegionID);
return true;
}
// else do it
currentUUID = rhrPack.RequestBlock.RegionID;
RegionHandleRequestsInService = true;
}
while (true)
{
handlerRegionHandleRequest(this, currentUUID);
lock (RegionHandleRequests)
{
// exit condition, nothing to do or closed
// current code seems to assume we may loose the handler at anytime,
// so keep checking it
handlerRegionHandleRequest = OnRegionHandleRequest;
if (RegionHandleRequests.Count == 0 || !IsActive || handlerRegionHandleRequest == null)
{
RegionHandleRequests.Clear();
RegionHandleRequestsInService = false;
return true;
}
currentUUID = RegionHandleRequests.Dequeue();
}
}
return true; // actually unreached
}
private bool HandleParcelInfoRequest(IClientAPI sender, Packet Pack)
{
ParcelInfoRequestPacket pirPack = (ParcelInfoRequestPacket)Pack;

View File

@ -48,31 +48,16 @@ namespace OpenSim.Region.CoreModules.Framework
MethodBase.GetCurrentMethod().DeclaringType);
private readonly List<Scene> m_scenes = new List<Scene>();
private System.Timers.Timer m_timer = new System.Timers.Timer();
private Queue<Action> m_RequestQueue = new Queue<Action>();
private Dictionary<string, List<string>> m_Pending = new Dictionary<string, List<string>>();
private int m_Interval;
private JobEngine m_processorJobEngine;
#region ISharedRegionModule
public void Initialise(IConfigSource config)
{
m_Interval = Util.GetConfigVarFromSections<int>(config, "Interval", new string[] { "ServiceThrottle" }, 5000);
m_timer = new System.Timers.Timer();
m_timer.AutoReset = false;
m_timer.Enabled = true;
m_timer.Interval = 15000; // 15 secs at first
m_timer.Elapsed += ProcessQueue;
m_timer.Start();
//WorkManager.StartThread(
// ProcessQueue,
// "GridServiceRequestThread",
// ThreadPriority.BelowNormal,
// true,
// false);
m_processorJobEngine = new JobEngine(
"ServiceThrottle","ServiceThrottle");
m_processorJobEngine.RequestProcessTimeoutOnStop = 31000; // many webrequests have 30s expire
m_processorJobEngine.Start();
}
public void AddRegion(Scene scene)
@ -82,7 +67,6 @@ namespace OpenSim.Region.CoreModules.Framework
m_scenes.Add(scene);
scene.RegisterModuleInterface<IServiceThrottleModule>(this);
scene.EventManager.OnNewClient += OnNewClient;
scene.EventManager.OnMakeRootAgent += OnMakeRootAgent;
}
}
@ -105,6 +89,7 @@ namespace OpenSim.Region.CoreModules.Framework
public void Close()
{
m_processorJobEngine.Stop();
}
public string Name
@ -126,38 +111,24 @@ namespace OpenSim.Region.CoreModules.Framework
client.OnRegionHandleRequest += OnRegionHandleRequest;
}
void OnMakeRootAgent(ScenePresence obj)
{
lock (m_timer)
{
if (!m_timer.Enabled)
{
m_timer.Interval = m_Interval;
m_timer.Enabled = true;
m_timer.Start();
}
}
}
public void OnRegionHandleRequest(IClientAPI client, UUID regionID)
{
//m_log.DebugFormat("[SERVICE THROTTLE]: RegionHandleRequest {0}", regionID);
ulong handle = 0;
if (IsLocalRegionHandle(regionID, out handle))
{
client.SendRegionHandle(regionID, handle);
return;
}
Action action = delegate
{
if(!client.IsActive)
return;
GridRegion r = m_scenes[0].GridService.GetRegionByUUID(UUID.Zero, regionID);
if(!client.IsActive)
return;
if (r != null && r.RegionHandle != 0)
client.SendRegionHandle(regionID, r.RegionHandle);
};
Enqueue("region", regionID.ToString(), action);
m_processorJobEngine.QueueJob("regionHandle", action, regionID.ToString());
}
#endregion Events
@ -166,91 +137,10 @@ namespace OpenSim.Region.CoreModules.Framework
public void Enqueue(string category, string itemid, Action 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
{
lock (m_RequestQueue)
m_Pending[category].Remove(itemid);
continuation();
});
}
m_processorJobEngine.QueueJob(category, continuation, itemid);
}
#endregion IServiceThrottleModule
#region Process Continuation Queue
private void ProcessQueue(object sender, System.Timers.ElapsedEventArgs e)
{
//m_log.DebugFormat("[YYY]: Process queue with {0} continuations", m_RequestQueue.Count);
while (m_RequestQueue.Count > 0)
{
Action continuation = null;
lock (m_RequestQueue)
continuation = m_RequestQueue.Dequeue();
if (continuation != null)
continuation();
}
if (AreThereRootAgents())
{
lock (m_timer)
{
m_timer.Interval = 1000; // 1 sec
m_timer.Enabled = true;
m_timer.Start();
}
}
else
lock (m_timer)
m_timer.Enabled = false;
}
#endregion Process Continuation Queue
#region Misc
private bool IsLocalRegionHandle(UUID regionID, out ulong regionHandle)
{
regionHandle = 0;
foreach (Scene s in m_scenes)
if (s.RegionInfo.RegionID == regionID)
{
regionHandle = s.RegionInfo.RegionHandle;
return true;
}
return false;
}
private bool AreThereRootAgents()
{
foreach (Scene s in m_scenes)
{
foreach (ScenePresence sp in s.GetScenePresences())
if (!sp.IsChildAgent)
return true;
}
return false;
}
#endregion Misc
}
}

View File

@ -206,7 +206,7 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement
}
// Not found in cache, queue continuation
m_ServiceThrottle.Enqueue("name", uuid.ToString(), delegate
m_ServiceThrottle.Enqueue("uuidname", uuid.ToString(), delegate
{
//m_log.DebugFormat("[YYY]: Name request {0}", uuid);
@ -216,8 +216,11 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement
// So to avoid clients
// (particularly Hypergrid clients) permanently binding "Unknown User" to a given UUID, we will
// instead drop the request entirely.
if(!client.IsActive)
return;
if (GetUser(uuid, out user))
{
if(client.IsActive)
client.SendNameReply(uuid, user.FirstName, user.LastName);
}
// else