* Enabled GTCache for AssetCache

* Items will now be locally cached for only 24 hours from last access. (Rather than until restart)
* Caveat: Implementing the new caching mechanism means statistics gathering on AssetCache is no longer functional. (Justin - you might want to take a look and see if you can somehow get that back and running if you still need it)
0.6.1-post-fixes
Adam Frisby 2008-11-09 15:00:26 +00:00
parent 448092332c
commit c43e466301
4 changed files with 100 additions and 204 deletions

View File

@ -33,6 +33,7 @@ using OpenMetaverse;
using OpenMetaverse.Packets;
using log4net;
using OpenSim.Framework.Statistics;
using GlynnTucker.Cache;
namespace OpenSim.Framework.Communications.Cache
{
@ -52,18 +53,20 @@ namespace OpenSim.Framework.Communications.Cache
/// </summary>
public class AssetCache : IAssetReceiver
{
protected ICache m_memcache = new SimpleMemoryCache();
private static readonly ILog m_log
= LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
/// <summary>
/// The cache of assets. This does not include textures.
/// </summary>
private Dictionary<UUID, AssetInfo> Assets;
//private Dictionary<UUID, AssetInfo> Assets;
/// <summary>
/// The cache of textures.
/// </summary>
private Dictionary<UUID, TextureImage> Textures;
//private Dictionary<UUID, TextureImage> Textures;
/// <summary>
/// Assets requests which are waiting for asset server data. This includes texture requests
@ -95,52 +98,11 @@ namespace OpenSim.Framework.Communications.Cache
/// </summary>
public void ShowState()
{
m_log.InfoFormat("Assets:{0} Textures:{1} RequestLists:{2}",
Assets.Count,
Textures.Count,
m_log.InfoFormat("Memcache:{1} RequestLists:{2}",
m_memcache.Count,
// AssetRequests.Count,
// RequestedAssets.Count,
RequestLists.Count);
int temporaryImages = 0;
int temporaryAssets = 0;
long imageBytes = 0;
long assetBytes = 0;
foreach (TextureImage texture in Textures.Values)
{
if (texture != null)
{
if (texture.Temporary)
{
temporaryImages++;
}
imageBytes += texture.Data.GetLongLength(0);
}
}
foreach (AssetInfo asset in Assets.Values)
{
if (asset != null)
{
if (asset.Temporary)
{
temporaryAssets++;
}
assetBytes += asset.Data.GetLongLength(0);
}
}
m_log.InfoFormat("Temporary Images: {0} Temporary Assets: {1}",
temporaryImages,
temporaryAssets);
m_log.InfoFormat("Image data: {0}kb Asset data: {1}kb",
imageBytes / 1024,
assetBytes / 1024);
}
/// <summary>
@ -161,8 +123,6 @@ namespace OpenSim.Framework.Communications.Cache
/// </summary>
private void Initialize()
{
Assets = new Dictionary<UUID, AssetInfo>();
Textures = new Dictionary<UUID, TextureImage>();
AssetRequests = new List<AssetRequest>();
RequestedAssets = new Dictionary<UUID, AssetRequest>();
@ -181,7 +141,7 @@ namespace OpenSim.Framework.Communications.Cache
m_assetServer = assetServer;
m_assetServer.SetReceiver(this);
Thread assetCacheThread = new Thread(new ThreadStart(RunAssetManager));
Thread assetCacheThread = new Thread(RunAssetManager);
assetCacheThread.Name = "AssetCacheThread";
assetCacheThread.IsBackground = true;
assetCacheThread.Start();
@ -203,7 +163,7 @@ namespace OpenSim.Framework.Communications.Cache
}
catch (Exception e)
{
m_log.Error("[ASSET CACHE]: " + e.ToString());
m_log.Error("[ASSET CACHE]: " + e);
}
}
}
@ -216,14 +176,11 @@ namespace OpenSim.Framework.Communications.Cache
/// <returns>true if the asset was in the cache, false if it was not</returns>
public bool TryGetCachedAsset(UUID assetId, out AssetBase asset)
{
if (Textures.ContainsKey(assetId))
Object tmp;
if(m_memcache.TryGet(assetId, out tmp))
{
asset = Textures[assetId];
return true;
}
else if (Assets.ContainsKey(assetId))
{
asset = Assets[assetId];
asset = (AssetBase)tmp;
//m_log.Info("Retrieved from cache " + assetId);
return true;
}
@ -312,8 +269,6 @@ namespace OpenSim.Framework.Communications.Cache
{
return asset;
}
else
{
m_assetServer.RequestAsset(assetID, isTexture);
do
@ -331,7 +286,6 @@ namespace OpenSim.Framework.Communications.Cache
return null;
}
}
/// <summary>
/// Add an asset to both the persistent store and the cache.
@ -339,19 +293,11 @@ namespace OpenSim.Framework.Communications.Cache
/// <param name="asset"></param>
public void AddAsset(AssetBase asset)
{
// m_log.DebugFormat(
// "[ASSET CACHE]: Uploaded asset {0}, temporary {1}, store local {2}",
// asset.ID, asset.Temporary, asset.Local);
if (asset.Type == (int)AssetType.Texture)
if (!m_memcache.Contains(asset.FullID))
{
if (!Textures.ContainsKey(asset.FullID))
{
TextureImage textur = new TextureImage(asset);
Textures.Add(textur.FullID, textur);
if (StatsManager.SimExtraStats != null)
StatsManager.SimExtraStats.AddTexture(textur);
m_log.Info("[CACHE] Caching " + asset.FullID + " for 24 hours from last access");
// Use 24 hour rolling asset cache.
m_memcache.AddOrUpdate(asset.FullID, asset, TimeSpan.FromHours(24));
// According to http://wiki.secondlife.com/wiki/AssetUploadRequest, Local signifies that the
// information is stored locally. It could disappear, in which case we could send the
@ -376,32 +322,6 @@ namespace OpenSim.Framework.Communications.Cache
m_assetServer.StoreAsset(asset);
}
}
// else
// {
// m_log.DebugFormat("[ASSET CACHE]: Textures already contains {0}", asset.ID);
// }
}
else
{
if (!Assets.ContainsKey(asset.FullID))
{
AssetInfo assetInf = new AssetInfo(asset);
Assets.Add(assetInf.FullID, assetInf);
if (StatsManager.SimExtraStats != null)
StatsManager.SimExtraStats.AddAsset(assetInf);
// See comment above.
if (!asset.Temporary || asset.Local)
{
m_assetServer.StoreAsset(asset);
}
}
// else
// {
// m_log.DebugFormat("[ASSET CACHE]: Assets already contains {0}", asset.ID);
// }
}
}
/// <summary>
@ -417,44 +337,20 @@ namespace OpenSim.Framework.Communications.Cache
// in the 2 caches differently. Also, locks are probably
// needed in all of this, or move to synchronized non
// generic forms for Dictionaries.
if (Textures.ContainsKey(uuid))
if(m_memcache.Contains(uuid))
{
Textures.Remove(uuid);
}
else if (Assets.ContainsKey(uuid))
{
Assets.Remove(uuid);
m_memcache.Remove(uuid);
}
}
// See IAssetReceiver
public void AssetReceived(AssetBase asset, bool IsTexture)
{
// m_log.DebugFormat("[ASSET CACHE]: Received asset {0}", asset.ID);
//check if it is a texture or not
//then add to the correct cache list
//then check for waiting requests for this asset/texture (in the Requested lists)
//and move those requests into the Requests list.
if (IsTexture)
{
TextureImage image = new TextureImage(asset);
if (!Textures.ContainsKey(image.FullID))
{
Textures.Add(image.FullID, image);
if (StatsManager.SimExtraStats != null)
{
StatsManager.SimExtraStats.AddTexture(image);
}
}
}
else
{
AssetInfo assetInf = new AssetInfo(asset);
if (!Assets.ContainsKey(assetInf.FullID))
if (!m_memcache.Contains(assetInf.FullID))
{
Assets.Add(assetInf.FullID, assetInf);
m_memcache.AddOrUpdate(assetInf.FullID, assetInf, TimeSpan.FromHours(24));
if (StatsManager.SimExtraStats != null)
{
@ -474,10 +370,9 @@ namespace OpenSim.Framework.Communications.Cache
AssetRequests.Add(req);
}
}
}
// Notify requesters for this asset
AssetRequestsList reqList = null;
AssetRequestsList reqList;
lock (RequestLists)
{
@ -504,17 +399,8 @@ namespace OpenSim.Framework.Communications.Cache
{
// m_log.WarnFormat("[ASSET CACHE]: AssetNotFound for {0}", assetID);
if (IsTexture)
{
Textures[assetID] = null;
}
else
{
Assets[assetID] = null;
}
// Notify requesters for this asset
AssetRequestsList reqList = null;
AssetRequestsList reqList;
lock (RequestLists)
{
if (RequestLists.TryGetValue(assetID, out reqList))
@ -578,7 +464,7 @@ namespace OpenSim.Framework.Communications.Cache
//check to see if asset is in local cache, if not we need to request it from asset server.
//Console.WriteLine("asset request " + requestID);
if (!Assets.ContainsKey(requestID))
if (!m_memcache.Contains(requestID))
{
//not found asset
// so request from asset server
@ -598,7 +484,7 @@ namespace OpenSim.Framework.Communications.Cache
}
// It has an entry in our cache
AssetInfo asset = Assets[requestID];
AssetInfo asset = (AssetInfo)m_memcache[requestID];
// FIXME: We never tell the client about assets which do not exist when requested by this transfer mechanism, which can't be right.
if (null == asset)

View File

@ -48,6 +48,8 @@ namespace OpenSim.Region.Environment
{
m_log.Info("[CLIENTSTACK]: Attempting to load " + dllName);
try
{
plugin = null;
pluginAssembly = Assembly.LoadFrom(dllName);
@ -65,6 +67,14 @@ namespace OpenSim.Region.Environment
}
}
}
} catch (ReflectionTypeLoadException e)
{
foreach(Exception e2 in e.LoaderExceptions)
{
m_log.Error(e2.ToString());
}
throw e;
}
}
/// <summary>

View File

@ -664,7 +664,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
m_log.DebugFormat(
"[CLIENT]: Entered main packet processing loop for {0} {1}", FirstName, LastName);
while (true)
while (IsActive)
{
LLQueItem nextPacket = m_PacketHandler.PacketQueue.Dequeue();

View File

@ -743,6 +743,7 @@
<Reference name="Nini.dll" />
<Reference name="XMLRPC.dll"/>
<Reference name="log4net.dll"/>
<Reference name="GlynnTucker.Cache.dll"/>
<Files>
<Match pattern="*.cs" recurse="true"/>
@ -968,7 +969,6 @@
<Reference name="OpenSim.Region.Interfaces"/>
<Reference name="OpenSim.Data"/>
<Reference name="OpenSim.Framework.Servers"/>
<Reference name="OpenSim.Framework.Client"/>
<Reference name="OpenSim.Framework.Console"/>
<Reference name="OpenSim.Framework.Communications"/>
<Reference name="OpenSim.Framework.Statistics"/>