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!

xassetservice
Diva Canto 2012-02-18 21:59:42 -08:00
parent 14e9bf894c
commit 2ffc055f7e
2 changed files with 40 additions and 2 deletions

View File

@ -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<ScopedRegionUUID, GridRegion> m_UUIDCache;
private ExpiringCache<ScopedRegionName, ScopedRegionUUID> m_NameCache;
private ExpiringCache<ScopedRegionPosition, GridRegion> m_PositionCache;
public RegionInfoCache()
{
m_UUIDCache = new ExpiringCache<ScopedRegionUUID, GridRegion>();
m_NameCache = new ExpiringCache<ScopedRegionName, ScopedRegionUUID>();
m_PositionCache = new ExpiringCache<ScopedRegionPosition, GridRegion>();
}
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;

View File

@ -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;
}