Merge branch 'master' into httptests

This commit is contained in:
UbitUmarov
2016-12-30 01:52:02 +00:00
23 changed files with 271 additions and 62 deletions

View File

@@ -57,13 +57,13 @@ namespace OpenSim.Region.CoreModules.Agent.TextureSender
/// <summary>List of client methods to notify of results of decode</summary>
private readonly Dictionary<UUID, List<DecodedCallback>> m_notifyList = new Dictionary<UUID, List<DecodedCallback>>();
/// <summary>Cache that will store decoded JPEG2000 layer boundary data</summary>
private IImprovedAssetCache m_cache;
private IImprovedAssetCache Cache
private IAssetCache m_cache;
private IAssetCache Cache
{
get
{
if (m_cache == null)
m_cache = m_scene.RequestModuleInterface<IImprovedAssetCache>();
m_cache = m_scene.RequestModuleInterface<IAssetCache>();
return m_cache;
}

View File

@@ -91,7 +91,7 @@ namespace OpenSim.Region.CoreModules.Asset
/// </code>
/// </example>
[Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "CenomeMemoryAssetCache")]
public class CenomeMemoryAssetCache : IImprovedAssetCache, ISharedRegionModule
public class CenomeMemoryAssetCache : IAssetCache, ISharedRegionModule
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
@@ -192,7 +192,7 @@ namespace OpenSim.Region.CoreModules.Asset
expirationTime);
}
#region IImprovedAssetCache Members
#region IAssetCache Members
public bool Check(string id)
{
@@ -221,6 +221,11 @@ namespace OpenSim.Region.CoreModules.Asset
}
public void CacheNegative(string id)
{
// We don't do negative caching
}
/// <summary>
/// Clear asset cache.
/// </summary>
@@ -308,7 +313,7 @@ namespace OpenSim.Region.CoreModules.Asset
public void AddRegion(Scene scene)
{
if (m_enabled)
scene.RegisterModuleInterface<IImprovedAssetCache>(this);
scene.RegisterModuleInterface<IAssetCache>(this);
}
/// <summary>

View File

@@ -40,7 +40,7 @@ using OpenSim.Services.Interfaces;
namespace OpenSim.Region.CoreModules.Asset
{
[Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "CoreAssetCache")]
public class CoreAssetCache : ISharedRegionModule, IImprovedAssetCache
public class CoreAssetCache : ISharedRegionModule, IAssetCache
{
private static readonly ILog m_log =
LogManager.GetLogger(
@@ -98,7 +98,7 @@ namespace OpenSim.Region.CoreModules.Asset
public void AddRegion(Scene scene)
{
if (m_Enabled)
scene.RegisterModuleInterface<IImprovedAssetCache>(this);
scene.RegisterModuleInterface<IAssetCache>(this);
}
public void RemoveRegion(Scene scene)
@@ -110,7 +110,7 @@ namespace OpenSim.Region.CoreModules.Asset
}
////////////////////////////////////////////////////////////
// IImprovedAssetCache
// IAssetCache
//
public bool Check(string id)
{
@@ -124,6 +124,11 @@ namespace OpenSim.Region.CoreModules.Asset
m_Cache.Store(asset.ID, asset);
}
public void CacheNegative(string id)
{
// We don't do negative caching
}
public AssetBase Get(string id)
{
return (AssetBase)m_Cache.Get(id);

View File

@@ -55,7 +55,7 @@ using OpenSim.Services.Interfaces;
namespace OpenSim.Region.CoreModules.Asset
{
[Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "FlotsamAssetCache")]
public class FlotsamAssetCache : ISharedRegionModule, IImprovedAssetCache, IAssetService
public class FlotsamAssetCache : ISharedRegionModule, IAssetCache, IAssetService
{
private static readonly ILog m_log =
LogManager.GetLogger(
@@ -78,6 +78,7 @@ namespace OpenSim.Region.CoreModules.Asset
private static ulong m_RequestsForInprogress;
private static ulong m_DiskHits;
private static ulong m_MemoryHits;
private static ulong m_weakRefHits;
#if WAIT_ON_INPROGRESS_REQUESTS
private Dictionary<string, ManualResetEvent> m_CurrentlyWriting = new Dictionary<string, ManualResetEvent>();
@@ -91,9 +92,15 @@ namespace OpenSim.Region.CoreModules.Asset
private ExpiringCache<string, AssetBase> m_MemoryCache;
private bool m_MemoryCacheEnabled = false;
private ExpiringCache<string, object> m_negativeCache;
private bool m_negativeCacheEnabled = true;
private bool m_negativeCacheSliding = false;
// Expiration is expressed in hours.
private double m_MemoryExpiration = 0.001;
private double m_MemoryExpiration = 0.016;
private const double m_DefaultFileExpiration = 48;
// Negative cache is in seconds
private int m_negativeExpiration = 120;
private TimeSpan m_FileExpiration = TimeSpan.FromHours(m_DefaultFileExpiration);
private TimeSpan m_FileExpirationCleanupTimer = TimeSpan.FromHours(1.0);
@@ -107,6 +114,10 @@ namespace OpenSim.Region.CoreModules.Asset
private List<Scene> m_Scenes = new List<Scene>();
private object timerLock = new object();
private Dictionary<string,WeakReference> weakAssetReferences = new Dictionary<string, WeakReference>();
private object weakAssetReferencesLock = new object();
private bool m_updateFileTimeOnCacheHit = false;
public FlotsamAssetCache()
{
m_InvalidChars.AddRange(Path.GetInvalidPathChars());
@@ -134,6 +145,7 @@ namespace OpenSim.Region.CoreModules.Asset
if (name == Name)
{
m_MemoryCache = new ExpiringCache<string, AssetBase>();
m_negativeCache = new ExpiringCache<string, object>();
m_Enabled = true;
m_log.InfoFormat("[FLOTSAM ASSET CACHE]: {0} enabled", this.Name);
@@ -152,6 +164,11 @@ namespace OpenSim.Region.CoreModules.Asset
m_MemoryCacheEnabled = assetConfig.GetBoolean("MemoryCacheEnabled", m_MemoryCacheEnabled);
m_MemoryExpiration = assetConfig.GetDouble("MemoryCacheTimeout", m_MemoryExpiration);
m_MemoryExpiration *= 3600.0; // config in hours to seconds
m_negativeCacheEnabled = assetConfig.GetBoolean("NegativeCacheEnabled", m_negativeCacheEnabled);
m_negativeExpiration = assetConfig.GetInt("NegativeCacheTimeout", m_negativeExpiration);
m_negativeCacheSliding = assetConfig.GetBoolean("NegativeCacheSliding", m_negativeCacheSliding);
m_updateFileTimeOnCacheHit = assetConfig.GetBoolean("UpdateFileTimeOnCacheHit", m_updateFileTimeOnCacheHit);
#if WAIT_ON_INPROGRESS_REQUESTS
m_WaitOnInprogressTimeout = assetConfig.GetInt("WaitOnInprogressTimeout", 3000);
@@ -212,7 +229,7 @@ namespace OpenSim.Region.CoreModules.Asset
{
if (m_Enabled)
{
scene.RegisterModuleInterface<IImprovedAssetCache>(this);
scene.RegisterModuleInterface<IAssetCache>(this);
m_Scenes.Add(scene);
}
}
@@ -221,7 +238,7 @@ namespace OpenSim.Region.CoreModules.Asset
{
if (m_Enabled)
{
scene.UnregisterModuleInterface<IImprovedAssetCache>(this);
scene.UnregisterModuleInterface<IAssetCache>(this);
m_Scenes.Remove(scene);
lock(timerLock)
{
@@ -255,12 +272,23 @@ namespace OpenSim.Region.CoreModules.Asset
}
}
}
if (m_MemoryCacheEnabled)
m_MemoryCache = new ExpiringCache<string, AssetBase>();
lock(weakAssetReferencesLock)
weakAssetReferences = new Dictionary<string, WeakReference>();
}
}
////////////////////////////////////////////////////////////
// IImprovedAssetCache
// IAssetCache
//
private void UpdateWeakReference(string key, AssetBase asset)
{
WeakReference aref = new WeakReference(asset);
lock(weakAssetReferencesLock)
weakAssetReferences[key] = aref;
}
private void UpdateMemoryCache(string key, AssetBase asset)
{
@@ -327,6 +355,7 @@ namespace OpenSim.Region.CoreModules.Asset
if (asset != null)
{
//m_log.DebugFormat("[FLOTSAM ASSET CACHE]: Caching asset with id {0}", asset.ID);
UpdateWeakReference(asset.ID, asset);
if (m_MemoryCacheEnabled)
UpdateMemoryCache(asset.ID, asset);
@@ -336,6 +365,17 @@ namespace OpenSim.Region.CoreModules.Asset
}
}
public void CacheNegative(string id)
{
if (m_negativeCacheEnabled)
{
if (m_negativeCacheSliding)
m_negativeCache.AddOrUpdate(id, null, TimeSpan.FromSeconds(m_negativeExpiration));
else
m_negativeCache.AddOrUpdate(id, null, m_negativeExpiration);
}
}
/// <summary>
/// Updates the cached file with the current time.
/// </summary>
@@ -354,6 +394,25 @@ namespace OpenSim.Region.CoreModules.Asset
}
}
private AssetBase GetFromWeakReference(string id)
{
AssetBase asset = null;
WeakReference aref;
lock(weakAssetReferencesLock)
{
if (weakAssetReferences.TryGetValue(id, out aref))
{
asset = aref.Target as AssetBase;
if(asset == null)
weakAssetReferences.Remove(id);
else
m_weakRefHits++;
}
}
return asset;
}
/// <summary>
/// Try to get an asset from the in-memory cache.
/// </summary>
@@ -476,13 +535,38 @@ namespace OpenSim.Region.CoreModules.Asset
{
m_Requests++;
AssetBase asset = null;
object dummy;
if (m_negativeCache.TryGetValue(id, out dummy))
return null;
if (m_MemoryCacheEnabled)
AssetBase asset = null;
asset = GetFromWeakReference(id);
if (asset != null && m_updateFileTimeOnCacheHit)
{
string filename = GetFileName(id);
UpdateFileLastAccessTime(filename);
}
if (m_MemoryCacheEnabled && asset == null)
{
asset = GetFromMemoryCache(id);
if(asset != null)
{
UpdateWeakReference(id,asset);
if (m_updateFileTimeOnCacheHit)
{
string filename = GetFileName(id);
UpdateFileLastAccessTime(filename);
}
}
}
if (asset == null && m_FileCacheEnabled)
{
asset = GetFromFileCache(id);
if(asset != null)
UpdateWeakReference(id,asset);
}
if (m_MemoryCacheEnabled && asset != null)
UpdateMemoryCache(id, asset);
@@ -494,6 +578,12 @@ namespace OpenSim.Region.CoreModules.Asset
GenerateCacheHitReport().ForEach(l => m_log.InfoFormat("[FLOTSAM ASSET CACHE]: {0}", l));
}
if(asset == null)
{
}
return asset;
}
@@ -530,6 +620,9 @@ namespace OpenSim.Region.CoreModules.Asset
if (m_MemoryCacheEnabled)
m_MemoryCache.Remove(id);
lock(weakAssetReferencesLock)
weakAssetReferences.Remove(id);
}
catch (Exception e)
{
@@ -553,7 +646,12 @@ namespace OpenSim.Region.CoreModules.Asset
}
if (m_MemoryCacheEnabled)
m_MemoryCache.Clear();
m_MemoryCache = new ExpiringCache<string, AssetBase>();
if (m_negativeCacheEnabled)
m_negativeCache = new ExpiringCache<string, object>();
lock(weakAssetReferencesLock)
weakAssetReferences = new Dictionary<string, WeakReference>();
}
private void CleanupExpiredFiles(object source, ElapsedEventArgs e)
@@ -911,28 +1009,34 @@ namespace OpenSim.Region.CoreModules.Asset
List<string> outputLines = new List<string>();
double invReq = 100.0 / m_Requests;
double weakHitRate = m_weakRefHits * invReq;
int weakEntries = weakAssetReferences.Count;
double fileHitRate = m_DiskHits * invReq;
double TotalHitRate = weakHitRate + fileHitRate;
outputLines.Add(
string.Format("File Hit Rate: {0}% for {1} requests", fileHitRate.ToString("0.00"), m_Requests));
string.Format("Total requests: {0}", m_Requests));
outputLines.Add(
string.Format("unCollected Hit Rate: {0}% ({1} entries)", weakHitRate.ToString("0.00"),weakEntries));
outputLines.Add(
string.Format("File Hit Rate: {0}%", fileHitRate.ToString("0.00")));
if (m_MemoryCacheEnabled)
{
double HitRate = m_MemoryHits * invReq;
outputLines.Add(
string.Format("Memory Hit Rate: {0}% for {1} requests", HitRate.ToString("0.00"), m_Requests));
string.Format("Memory Hit Rate: {0}%", HitRate.ToString("0.00")));
HitRate += fileHitRate;
outputLines.Add(
string.Format("Total Hit Rate: {0}% for {1} requests", HitRate.ToString("0.00"), m_Requests));
TotalHitRate += HitRate;
}
outputLines.Add(
string.Format("Total Hit Rate: {0}%", TotalHitRate.ToString("0.00")));
outputLines.Add(
string.Format(
"Unnecessary requests due to requests for assets that are currently downloading: {0}",
m_RequestsForInprogress));
"Requests overlap during file writing: {0}", m_RequestsForInprogress));
return outputLines;
}

View File

@@ -41,7 +41,7 @@ using OpenSim.Services.Interfaces;
namespace OpenSim.Region.CoreModules.Asset
{
[Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "GlynnTuckerAssetCache")]
public class GlynnTuckerAssetCache : ISharedRegionModule, IImprovedAssetCache
public class GlynnTuckerAssetCache : ISharedRegionModule, IAssetCache
{
private static readonly ILog m_log =
LogManager.GetLogger(
@@ -100,7 +100,7 @@ namespace OpenSim.Region.CoreModules.Asset
public void AddRegion(Scene scene)
{
if (m_Enabled)
scene.RegisterModuleInterface<IImprovedAssetCache>(this);
scene.RegisterModuleInterface<IAssetCache>(this);
}
public void RemoveRegion(Scene scene)
@@ -112,7 +112,7 @@ namespace OpenSim.Region.CoreModules.Asset
}
////////////////////////////////////////////////////////////
// IImprovedAssetCache
// IAssetCache
//
public bool Check(string id)
@@ -126,6 +126,11 @@ namespace OpenSim.Region.CoreModules.Asset
m_Cache.AddOrUpdate(asset.ID, asset);
}
public void CacheNegative(string id)
{
// We don't do negative caching
}
public AssetBase Get(string id)
{
Object asset = null;

View File

@@ -288,7 +288,7 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory
if (bakedTextures.Count == 0)
return false;
IImprovedAssetCache cache = sp.Scene.RequestModuleInterface<IImprovedAssetCache>();
IAssetCache cache = sp.Scene.RequestModuleInterface<IAssetCache>();
if(cache == null)
return true; // no baked local caching so nothing to do
@@ -705,7 +705,7 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory
return 0;
int texturesRebaked = 0;
// IImprovedAssetCache cache = m_scene.RequestModuleInterface<IImprovedAssetCache>();
// IAssetCache cache = m_scene.RequestModuleInterface<IAssetCache>();
for (int i = 0; i < AvatarAppearance.BAKE_INDICES.Length; i++)
{

View File

@@ -69,7 +69,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
Dictionary<UUID, UUID> m_classifiedCache = new Dictionary<UUID, UUID>();
Dictionary<UUID, int> m_classifiedInterest = new Dictionary<UUID, int>();
ExpiringCache<UUID, UserProfileCacheEntry> m_profilesCache = new ExpiringCache<UUID, UserProfileCacheEntry>();
IImprovedAssetCache m_assetCache;
IAssetCache m_assetCache;
private JsonRpcRequestManager rpc = new JsonRpcRequestManager();
private bool m_allowUserProfileWebURLs = true;
@@ -221,7 +221,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
{
if(!Enabled)
return;
m_assetCache = Scene.RequestModuleInterface<IImprovedAssetCache>();
m_assetCache = Scene.RequestModuleInterface<IAssetCache>();
}
/// <summary>

View File

@@ -48,7 +48,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset
LogManager.GetLogger(
MethodBase.GetCurrentMethod().DeclaringType);
private IImprovedAssetCache m_Cache = null;
private IAssetCache m_Cache = null;
private IAssetService m_GridService;
private IAssetService m_HGService;
@@ -176,7 +176,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset
if (m_Cache == null)
{
m_Cache = scene.RequestModuleInterface<IImprovedAssetCache>();
m_Cache = scene.RequestModuleInterface<IAssetCache>();
if (!(m_Cache is ISharedRegionModule))
m_Cache = null;

View File

@@ -44,7 +44,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private IImprovedAssetCache m_Cache = null;
private IAssetCache m_Cache = null;
private IAssetService m_AssetService;
@@ -128,7 +128,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset
if (m_Cache == null)
{
m_Cache = scene.RequestModuleInterface<IImprovedAssetCache>();
m_Cache = scene.RequestModuleInterface<IAssetCache>();
if (!(m_Cache is ISharedRegionModule))
m_Cache = null;

View File

@@ -48,7 +48,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset
MethodBase.GetCurrentMethod().DeclaringType);
private bool m_Enabled = false;
private IImprovedAssetCache m_Cache;
private IAssetCache m_Cache;
public Type ReplaceableInterface
{
@@ -111,7 +111,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset
if (m_Cache == null)
{
m_Cache = scene.RequestModuleInterface<IImprovedAssetCache>();
m_Cache = scene.RequestModuleInterface<IAssetCache>();
// Since we are a shared module and scene data is not
// available for every method, the cache must be shared, too