From 7156545fcaa632a104f09a9dcffda5238c3bf75c Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Sat, 18 Feb 2012 21:59:42 -0800 Subject: [PATCH] This should smooth movement in heteregeneous networks by a lot: cache the region by position instead of looking it up all the time -- this was being done during the main update loop! --- .../Grid/RegionInfoCache.cs | 34 ++++++++++++++++++- .../Grid/RemoteGridServiceConnector.cs | 8 ++++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionInfoCache.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionInfoCache.cs index 786e0b5737..be8a9a2307 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionInfoCache.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionInfoCache.cs @@ -65,13 +65,26 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid } } + internal struct ScopedRegionPosition + { + public UUID m_scopeID; + public ulong m_regionHandle; + public ScopedRegionPosition(UUID scopeID, ulong handle) + { + m_scopeID = scopeID; + m_regionHandle = handle; + } + } + private ExpiringCache m_UUIDCache; private ExpiringCache m_NameCache; + private ExpiringCache m_PositionCache; public RegionInfoCache() { m_UUIDCache = new ExpiringCache(); - m_NameCache = new ExpiringCache(); + m_NameCache = new ExpiringCache(); + m_PositionCache = new ExpiringCache(); } public void Cache(GridRegion rinfo) @@ -96,6 +109,9 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid { ScopedRegionName name = new ScopedRegionName(scopeID,rinfo.RegionName); m_NameCache.AddOrUpdate(name, id, CACHE_EXPIRATION_SECONDS); + + ScopedRegionPosition pos = new ScopedRegionPosition(scopeID, rinfo.RegionHandle); + m_PositionCache.AddOrUpdate(pos, rinfo, CACHE_EXPIRATION_SECONDS); } } @@ -114,6 +130,22 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid return null; } + public GridRegion Get(UUID scopeID, ulong handle, out bool inCache) + { + inCache = false; + + GridRegion rinfo = null; + ScopedRegionPosition pos = new ScopedRegionPosition(scopeID, handle); + if (m_PositionCache.TryGetValue(pos, out rinfo)) + { + inCache = true; + return rinfo; + } + + return null; + } + + public GridRegion Get(UUID scopeID, string name, out bool inCache) { inCache = false; diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs index 6f364ae4c8..e6c89d7af6 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs @@ -186,10 +186,16 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid public GridRegion GetRegionByPosition(UUID scopeID, int x, int y) { - GridRegion rinfo = m_LocalGridService.GetRegionByPosition(scopeID, x, y); + bool inCache = false; + GridRegion rinfo = m_RegionInfoCache.Get(scopeID, Util.UIntsToLong((uint)x, (uint)y), out inCache); + if (inCache) + return rinfo; + + rinfo = m_LocalGridService.GetRegionByPosition(scopeID, x, y); if (rinfo == null) rinfo = m_RemoteGridService.GetRegionByPosition(scopeID, x, y); + m_RegionInfoCache.Cache(rinfo); return rinfo; }