Instrumenting GlynnTuckerCache to find out the hit rate.

0.6.6-post-fixes
diva 2009-05-28 21:04:10 +00:00
parent 5db649538a
commit 0094556d04
1 changed files with 29 additions and 0 deletions

View File

@ -48,6 +48,9 @@ namespace OpenSim.Region.CoreModules.Asset
private bool m_Enabled = false;
private ICache m_Cache = new GlynnTucker.Cache.SimpleMemoryCache();
// Instrumentation
private uint m_DebugRate = 0;
public string Name
{
get { return "GlynnTuckerAssetCache"; }
@ -68,6 +71,11 @@ namespace OpenSim.Region.CoreModules.Asset
m_log.Info("[ASSET CACHE]: GlynnTucker asset cache enabled");
// Instrumentation
IConfig cacheConfig = source.Configs["AssetCache"];
if (cacheConfig != null)
m_DebugRate = (uint)cacheConfig.GetInt("DebugRate", 0);
}
}
}
@ -104,10 +112,31 @@ namespace OpenSim.Region.CoreModules.Asset
m_Cache.AddOrUpdate(asset.ID, asset);
}
private ulong m_Hits = 0;
private ulong m_Requests = 0;
private void Debug(Object asset)
{
// Temporary instrumentation to measure the hit/miss rate
if (m_DebugRate > 0)
{
m_Requests++;
if (asset != null)
m_Hits++;
if ((m_Requests % m_DebugRate) == 0)
m_log.DebugFormat("[ASSET CACHE]: Hit Rate {0} / {1} == {2}%", m_Hits, m_Requests, ((float)m_Hits / m_Requests) * 100);
}
// End instrumentation
}
public AssetBase Get(string id)
{
Object asset = null;
m_Cache.TryGet(id, out asset);
Debug(asset);
return (AssetBase)asset;
}