From a91ca984d57a4177ff31898e384ee85948d4eff1 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Sat, 8 Sep 2012 12:22:40 +0100 Subject: [PATCH] llClientView: try to have only one thread per client processing RegionHandleRequests. (code assumes packet handle is called async as it is not) --- .../ClientStack/Linden/UDP/LLClientView.cs | 53 +++++++++++++++++-- 1 file changed, 49 insertions(+), 4 deletions(-) diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs index e78ebed636..7749ef3890 100644 --- a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs @@ -8751,16 +8751,61 @@ 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 RegionHandleRequests = new Queue(); + bool RegionHandleRequestsInService = false; + private bool HandleRegionHandleRequest(IClientAPI sender, Packet Pack) { - RegionHandleRequestPacket rhrPack = (RegionHandleRequestPacket)Pack; + UUID currentUUID; RegionHandleRequest handlerRegionHandleRequest = OnRegionHandleRequest; - if (handlerRegionHandleRequest != null) + + if (handlerRegionHandleRequest == null) + return true; + + RegionHandleRequestPacket rhrPack = (RegionHandleRequestPacket)Pack; + + lock (RegionHandleRequests) { - handlerRegionHandleRequest(this, rhrPack.RequestBlock.RegionID); + 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; } - return 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)