From 62771560448edbc2112d427acd4b37780dfe2154 Mon Sep 17 00:00:00 2001 From: Justin Clarke Casey Date: Thu, 14 May 2009 20:37:54 +0000 Subject: * When saving an oar, save assets when immediately received rather than storing them all up in memory * Hopefully this will remove out of memory problems when saving large oars on machines without much memory * It may also speed up saving of large oars --- .../CoreModules/World/Archiver/AssetsRequest.cs | 53 +++++++++++++--------- 1 file changed, 31 insertions(+), 22 deletions(-) (limited to 'OpenSim/Region/CoreModules/World/Archiver/AssetsRequest.cs') diff --git a/OpenSim/Region/CoreModules/World/Archiver/AssetsRequest.cs b/OpenSim/Region/CoreModules/World/Archiver/AssetsRequest.cs index 0a0bb4c..d806a9c 100644 --- a/OpenSim/Region/CoreModules/World/Archiver/AssetsRequest.cs +++ b/OpenSim/Region/CoreModules/World/Archiver/AssetsRequest.cs @@ -32,6 +32,7 @@ using System.Threading; using log4net; using OpenMetaverse; using OpenSim.Framework; +using OpenSim.Framework.Serialization; namespace OpenSim.Region.CoreModules.World.Archiver { @@ -42,39 +43,43 @@ namespace OpenSim.Region.CoreModules.World.Archiver { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - /// + /// /// uuids to request - /// + /// protected ICollection m_uuids; - /// + /// /// Callback used when all the assets requested have been received. - /// + /// protected AssetsRequestCallback m_assetsRequestCallback; - /// - /// Assets retrieved in this request - /// - protected Dictionary m_assets = new Dictionary(); - - /// + /// + /// List of assets that were found. This will be passed back to the requester. + /// + protected List m_foundAssetUuids = new List(); + + /// /// Maintain a list of assets that could not be found. This will be passed back to the requester. - /// + /// protected List m_notFoundAssetUuids = new List(); - /// + /// /// Record the number of asset replies required so we know when we've finished - /// + /// private int m_repliesRequired; - /// + /// /// Asset cache used to request the assets - /// + /// protected IAssetCache m_assetCache; + protected AssetsArchiver m_assetsArchiver; + protected internal AssetsRequest( - ICollection uuids, IAssetCache assetCache, AssetsRequestCallback assetsRequestCallback) + AssetsArchiver assetsArchiver, ICollection uuids, + IAssetCache assetCache, AssetsRequestCallback assetsRequestCallback) { + m_assetsArchiver = assetsArchiver; m_uuids = uuids; m_assetsRequestCallback = assetsRequestCallback; m_assetCache = assetCache; @@ -87,7 +92,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver // We can stop here if there are no assets to fetch if (m_repliesRequired == 0) - m_assetsRequestCallback(m_assets, m_notFoundAssetUuids); + m_assetsRequestCallback(m_foundAssetUuids, m_notFoundAssetUuids); foreach (UUID uuid in m_uuids) { @@ -106,21 +111,25 @@ namespace OpenSim.Region.CoreModules.World.Archiver if (asset != null) { + // Make sure that we don't run out of memory by hogging assets in the cache m_assetCache.ExpireAsset(assetID); - m_assets[assetID] = asset; + + m_foundAssetUuids.Add(assetID); + m_assetsArchiver.WriteAsset(asset); } else { m_notFoundAssetUuids.Add(assetID); } - if (m_assets.Count + m_notFoundAssetUuids.Count == m_repliesRequired) + if (m_foundAssetUuids.Count + m_notFoundAssetUuids.Count == m_repliesRequired) { m_log.DebugFormat( "[ARCHIVER]: Successfully received {0} assets and notification of {1} missing assets", - m_assets.Count, m_notFoundAssetUuids.Count); + m_foundAssetUuids.Count, m_notFoundAssetUuids.Count); - // We want to stop using the asset cache thread asap as we now need to do the actual work of producing the archive + // We want to stop using the asset cache thread asap + // as we now need to do the work of producing the rest of the archive Thread newThread = new Thread(PerformAssetsRequestCallback); newThread.Name = "OpenSimulator archiving thread post assets receipt"; newThread.Start(); @@ -134,7 +143,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver { try { - m_assetsRequestCallback(m_assets, m_notFoundAssetUuids); + m_assetsRequestCallback(m_foundAssetUuids, m_notFoundAssetUuids); } catch (Exception e) { -- cgit v1.1