From 2ffc055f7ead4e6b07b82bcc47748295595d350d Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Sat, 18 Feb 2012 21:59:42 -0800 Subject: 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! --- .../ServiceConnectorsOut/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 786e0b5..be8a9a2 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 6f364ae..e6c89d7 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; } -- cgit v1.1