From 57ec0d38840124c21f759888cae43c33540c9851 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Mon, 8 Oct 2018 17:29:42 +0100 Subject: change caps get mesh and texture throttle --- .../ClientStack/Linden/Caps/GetMeshModule.cs | 120 +++++---------------- .../ClientStack/Linden/Caps/GetTextureModule.cs | 86 ++------------- OpenSim/Region/Framework/Scenes/ScenePresence.cs | 60 ++++++++++- 3 files changed, 96 insertions(+), 170 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/ClientStack/Linden/Caps/GetMeshModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/GetMeshModule.cs index 542d52a..d4d7b33 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/GetMeshModule.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/GetMeshModule.cs @@ -87,7 +87,6 @@ namespace OpenSim.Region.ClientStack.Linden private Dictionary m_pollservices = new Dictionary(); - #region Region Module interfaceBase Members public Type ReplaceableInterface @@ -134,7 +133,6 @@ namespace OpenSim.Region.ClientStack.Linden s.EventManager.OnRegisterCaps -= RegisterCaps; s.EventManager.OnDeregisterCaps -= DeregisterCaps; - s.EventManager.OnThrottleUpdate -= ThrottleUpdate; m_NumberScenes--; m_scene = null; } @@ -153,7 +151,6 @@ namespace OpenSim.Region.ClientStack.Linden s.EventManager.OnRegisterCaps += RegisterCaps; s.EventManager.OnDeregisterCaps += DeregisterCaps; - s.EventManager.OnThrottleUpdate += ThrottleUpdate; m_NumberScenes++; @@ -212,18 +209,6 @@ namespace OpenSim.Region.ClientStack.Linden } } - // Now we know when the throttle is changed by the client in the case of a root agent or by a neighbor region in the case of a child agent. - public void ThrottleUpdate(ScenePresence p) - { - UUID user = p.UUID; - int imagethrottle = p.ControllingClient.GetAgentThrottleSilent((int)ThrottleOutPacketType.Asset); - PollServiceMeshEventArgs args; - if (m_pollservices.TryGetValue(user, out args)) - { - args.UpdateThrottle(imagethrottle); - } - } - private class PollServiceMeshEventArgs : PollServiceEventArgs { private List requests = @@ -233,18 +218,28 @@ namespace OpenSim.Region.ClientStack.Linden private HashSet dropedResponses = new HashSet(); private Scene m_scene; - private MeshCapsDataThrottler m_throttler; + private ScenePresence m_presence; public PollServiceMeshEventArgs(string uri, UUID pId, Scene scene) : base(null, uri, null, null, null, null, pId, int.MaxValue) { m_scene = scene; - m_throttler = new MeshCapsDataThrottler(100000); + // x is request id, y is userid HasEvents = (x, y) => { lock (responses) { - return m_throttler.hasEvents(x, responses); + APollResponse response; + if (responses.TryGetValue(x, out response)) + { + if (m_presence == null) + m_presence = m_scene.GetScenePresence(pId); + + if (m_presence == null || m_presence.IsDeleted) + return true; + return m_presence.CapCanSendAsset(1, response.bytes); + } + return false; } }; @@ -269,7 +264,6 @@ namespace OpenSim.Region.ClientStack.Linden finally { responses.Remove(x); - m_throttler.PassTime(); } } }; @@ -282,7 +276,6 @@ namespace OpenSim.Region.ClientStack.Linden reqinfo.request = y; m_queue.Add(reqinfo); - m_throttler.PassTime(); }; // this should never happen except possible on shutdown @@ -307,14 +300,14 @@ namespace OpenSim.Region.ClientStack.Linden public void Process(APollRequest requestinfo) { - Hashtable response; + Hashtable curresponse; UUID requestID = requestinfo.reqID; if(m_scene.ShuttingDown) return; - lock(responses) + lock(responses) { lock(dropedResponses) { @@ -324,25 +317,23 @@ namespace OpenSim.Region.ClientStack.Linden return; } } - + // If the avatar is gone, don't bother to get the texture - if (m_scene.GetScenePresence(Id) == null) + if(m_scene.GetScenePresence(Id) == null) { - response = new Hashtable(); - - response["int_response_code"] = 500; - response["str_response_string"] = "Script timeout"; - response["content_type"] = "text/plain"; - response["keepalive"] = false; - responses[requestID] = new APollResponse() { bytes = 0, response = response}; - + curresponse = new Hashtable(); + curresponse["int_response_code"] = 500; + curresponse["str_response_string"] = "Script timeout"; + curresponse["content_type"] = "text/plain"; + curresponse["keepalive"] = false; + responses[requestID] = new APollResponse() { bytes = 0, response = curresponse }; return; } } - response = m_getMeshHandler.Handle(requestinfo.request); + curresponse = m_getMeshHandler.Handle(requestinfo.request); - lock (responses) + lock(responses) { lock(dropedResponses) { @@ -355,20 +346,10 @@ namespace OpenSim.Region.ClientStack.Linden responses[requestID] = new APollResponse() { - bytes = (int)response["int_bytes"], - response = response + bytes = (int)curresponse["int_bytes"], + response = curresponse }; - } - m_throttler.PassTime(); - } - - internal void UpdateThrottle(int pthrottle) - { - int tmp = 2 * pthrottle; - if(tmp < 10000) - tmp = 10000; - m_throttler.ThrottleBytes = tmp; } } @@ -419,52 +400,5 @@ namespace OpenSim.Region.ClientStack.Linden m_pollservices.Remove(agentID); } } - - internal sealed class MeshCapsDataThrottler - { - private double lastTimeElapsed = 0; - private double BytesSent = 0; - - public MeshCapsDataThrottler(int pBytes) - { - if(pBytes < 10000) - pBytes = 10000; - ThrottleBytes = pBytes; - lastTimeElapsed = Util.GetTimeStamp(); - } - - public bool hasEvents(UUID key, Dictionary responses) - { - PassTime(); - APollResponse response; - if (responses.TryGetValue(key, out response)) - { - // Normal - if (response.bytes == 0 || BytesSent <= ThrottleBytes) - { - BytesSent += response.bytes; - return true; - } - } - return false; - } - - public void PassTime() - { - double currenttime = Util.GetTimeStamp(); - double timeElapsed = currenttime - lastTimeElapsed; - if(timeElapsed < .05) - return; - int add = (int)(ThrottleBytes * timeElapsed); - if (add >= 1000) - { - lastTimeElapsed = currenttime; - BytesSent -= add; - if (BytesSent < 0) BytesSent = 0; - } - } - - public int ThrottleBytes; - } } } diff --git a/OpenSim/Region/ClientStack/Linden/Caps/GetTextureModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/GetTextureModule.cs index 7d1a380..0588648 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/GetTextureModule.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/GetTextureModule.cs @@ -113,7 +113,6 @@ namespace OpenSim.Region.ClientStack.Linden { s.EventManager.OnRegisterCaps -= RegisterCaps; s.EventManager.OnDeregisterCaps -= DeregisterCaps; - s.EventManager.OnThrottleUpdate -= ThrottleUpdate; m_NumberScenes--; m_scene = null; } @@ -129,7 +128,6 @@ namespace OpenSim.Region.ClientStack.Linden s.EventManager.OnRegisterCaps += RegisterCaps; s.EventManager.OnDeregisterCaps += DeregisterCaps; - s.EventManager.OnThrottleUpdate += ThrottleUpdate; m_NumberScenes++; @@ -149,19 +147,6 @@ namespace OpenSim.Region.ClientStack.Linden } } } - - // Now we know when the throttle is changed by the client in the case of a root agent or by a neighbor region in the case of a child agent. - public void ThrottleUpdate(ScenePresence p) - { - byte[] throttles = p.ControllingClient.GetThrottlesPacked(1); - UUID user = p.UUID; - int imagethrottle = p.ControllingClient.GetAgentThrottleSilent((int)ThrottleOutPacketType.Texture); - PollServiceTextureEventArgs args; - if (m_pollservices.TryGetValue(user,out args)) - { - args.UpdateThrottle(imagethrottle); - } - } public void PostInitialise() { @@ -198,20 +183,27 @@ namespace OpenSim.Region.ClientStack.Linden private HashSet dropedResponses = new HashSet(); private Scene m_scene; - private CapsDataThrottler m_throttler; + private ScenePresence m_presence; public PollServiceTextureEventArgs(UUID pId, Scene scene) : base(null, "", null, null, null, null, pId, int.MaxValue) { m_scene = scene; - m_throttler = new CapsDataThrottler(100000); // x is request id, y is userid HasEvents = (x, y) => { lock (responses) { - bool ret = m_throttler.hasEvents(x, responses); - return ret; + APollResponse response; + if (responses.TryGetValue(x, out response)) + { + if (m_presence == null) + m_presence = m_scene.GetScenePresence(pId); + if (m_presence == null || m_presence.IsDeleted) + return true; + return m_presence.CapCanSendAsset(0, response.bytes); + } + return false; } }; @@ -235,7 +227,6 @@ namespace OpenSim.Region.ClientStack.Linden finally { responses.Remove(x); - m_throttler.PassTime(); } } }; @@ -260,7 +251,6 @@ namespace OpenSim.Region.ClientStack.Linden } } m_queue.Add(reqinfo); - m_throttler.PassTime(); }; // this should never happen except possible on shutdown @@ -346,7 +336,6 @@ namespace OpenSim.Region.ClientStack.Linden if(dropedResponses.Contains(requestID)) { dropedResponses.Remove(requestID); - m_throttler.PassTime(); return; } } @@ -356,15 +345,6 @@ namespace OpenSim.Region.ClientStack.Linden response = response }; } - m_throttler.PassTime(); - } - - internal void UpdateThrottle(int pimagethrottle) - { - int tmp = 2 * pimagethrottle; - if(tmp < 10000) - tmp = 10000; - m_throttler.ThrottleBytes = tmp; } } @@ -437,49 +417,5 @@ namespace OpenSim.Region.ClientStack.Linden poolreq.thepoll.Process(poolreq); } } - - internal sealed class CapsDataThrottler - { - private double lastTimeElapsed = 0; - private volatile int BytesSent = 0; - public CapsDataThrottler(int pBytes) - { - if(pBytes < 10000) - pBytes = 10000; - ThrottleBytes = pBytes; - lastTimeElapsed = Util.GetTimeStamp(); - } - public bool hasEvents(UUID key, Dictionary responses) - { - PassTime(); - // Note, this is called IN LOCK - GetTextureModule.APollResponse response; - if (responses.TryGetValue(key, out response)) - { - if (response.bytes == 0 || BytesSent <= ThrottleBytes) - { - BytesSent += response.bytes; - return true; - } - } - return false; - } - - public void PassTime() - { - double currenttime = Util.GetTimeStamp(); - double timeElapsed = currenttime - lastTimeElapsed; - if(timeElapsed < .05) - return; - int add = (int)(ThrottleBytes * timeElapsed); - if (add >= 1000) - { - lastTimeElapsed = currenttime; - BytesSent -= add; - if (BytesSent < 0) BytesSent = 0; - } - } - public int ThrottleBytes; - } } } diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index ed4cafa..bcae69f 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs @@ -1118,6 +1118,20 @@ namespace OpenSim.Region.Framework.Scenes m_LandingPointBehavior = LandingPointBehavior.SL; } + m_bandwidth = 100000; + m_lastBandwithTime = Util.GetTimeStamp() + 0.1; + IConfig cconfig = m_scene.Config.Configs["ClientStack.LindenCaps"]; + if (cconfig != null) + { + m_capbandwidth = cconfig.GetInt("Cap_AssetThrottle", m_capbandwidth); + if(m_capbandwidth > 0) + { + m_bandwidth = m_capbandwidth; + if(m_bandwidth < 50000) + m_bandwidth = 50000; + } + } + m_bandwidthBurst = m_bandwidth / 5; ControllingClient.RefreshGroupMembership(); } @@ -4626,7 +4640,12 @@ namespace OpenSim.Region.Framework.Scenes private void RaiseUpdateThrottles() { - m_scene.EventManager.TriggerThrottleUpdate(this); + if(m_capbandwidth > 0) + return; + m_bandwidth = 4 * ControllingClient.GetAgentThrottleSilent((int)ThrottleOutPacketType.Texture); + if(m_bandwidth < 50000) + m_bandwidth = 50000; + m_bandwidthBurst = m_bandwidth / 5; } /// @@ -5834,7 +5853,7 @@ namespace OpenSim.Region.Framework.Scenes { if (scriptedcontrols.TryGetValue(Script_item_UUID, out takecontrols)) { - ScriptControlled sctc = takecontrols.eventControls; + ScriptControlled sctc = takecontrols.eventControls; ControllingClient.SendTakeControls((int)sctc, false, false); ControllingClient.SendTakeControls((int)sctc, true, false); @@ -6830,5 +6849,42 @@ namespace OpenSim.Region.Framework.Scenes { return Overrides.GetOverriddenAnimation(animState); } + + // http caps assets bandwidth control + private int m_capbandwidth = -1; + private int m_bandwidth = 100000; + private int m_bandwidthBurst = 20000; + private int m_bytesControl; + private double m_lastBandwithTime; + + public bool CapCanSendAsset(int type, int size) + { + if(size == 0) + return true; + + if(type > 1) + { + // not texture or mesh + m_bytesControl -= size; + return true; + } + + double currenttime = Util.GetTimeStamp(); + double timeElapsed = currenttime - m_lastBandwithTime; + if (timeElapsed > .05) + { + m_lastBandwithTime = currenttime; + int add = (int)(m_bandwidth * timeElapsed); + m_bytesControl += add; + if (m_bytesControl > m_bandwidthBurst) + m_bytesControl = m_bandwidthBurst; + } + if (m_bytesControl > 0 ) + { + m_bytesControl -= size; + return true; + } + return false; + } } } -- cgit v1.1