From 94ec05bbf522e6220679a8e8f3e134bcc9d9e1a3 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Mon, 9 Aug 2021 14:48:52 +0100 Subject: [PATCH] flotsam cache: revert from using Task Async. That uses alot more resources than a simple thread for pool and to be slower --- .../CoreModules/Asset/FlotsamAssetCache.cs | 56 +++++++++---------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs b/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs index 291f2d2e99..8fa1acbfd1 100755 --- a/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs +++ b/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs @@ -33,7 +33,6 @@ using System.Reflection; using System.Runtime.Serialization.Formatters.Binary; using System.Text; using System.Threading; -using System.Threading.Tasks; using System.Timers; using log4net; using Nini.Config; @@ -809,7 +808,7 @@ namespace OpenSim.Region.CoreModules.Asset weakAssetReferences = new Dictionary(); } - private async void CleanupExpiredFiles(object source, ElapsedEventArgs e) + private void CleanupExpiredFiles(object source, ElapsedEventArgs e) { lock (timerLock) { @@ -819,10 +818,10 @@ namespace OpenSim.Region.CoreModules.Asset } // Purge all files last accessed prior to this point - await DoCleanExpiredFiles(DateTime.Now - m_FileExpiration).ConfigureAwait(false); + DoCleanExpiredFiles(DateTime.Now - m_FileExpiration); } - private async Task DoCleanExpiredFiles(DateTime purgeLine) + private void DoCleanExpiredFiles(DateTime purgeLine) { long heap = 0; //if (m_LogLevel >= 2) @@ -834,7 +833,7 @@ namespace OpenSim.Region.CoreModules.Asset // An asset cache may contain local non-temporary assets that are not in the asset service. Therefore, // before cleaning up expired files we must scan the objects in the scene to make sure that we retain // such local assets if they have not been recently accessed. - Dictionary gids = await gatherSceneAssets().ConfigureAwait(false); + Dictionary gids = gatherSceneAssets(); int cooldown = 0; m_log.Info("[FLOTSAM ASSET CACHE] start asset files expire"); @@ -842,10 +841,10 @@ namespace OpenSim.Region.CoreModules.Asset { if(!m_cleanupRunning) break; - cooldown = await CleanExpiredFiles(subdir, gids, purgeLine, cooldown); + cooldown = CleanExpiredFiles(subdir, gids, purgeLine, cooldown); if (++cooldown >= 10) { - await Task.Delay(100).ConfigureAwait(false); + Thread.Sleep(120); cooldown = 0; } } @@ -872,8 +871,8 @@ namespace OpenSim.Region.CoreModules.Asset /// removes empty tier directories. /// /// - /// - private async Task CleanExpiredFiles(string dir, Dictionary gids, DateTime purgeLine, int cooldown) + /// + private int CleanExpiredFiles(string dir, Dictionary gids, DateTime purgeTimeline, int cooldown) { try { @@ -889,10 +888,10 @@ namespace OpenSim.Region.CoreModules.Asset return cooldown; ++dirSize; - cooldown = await CleanExpiredFiles(subdir, gids, purgeLine, cooldown); + cooldown = CleanExpiredFiles(subdir, gids, purgeTimeline, cooldown); if (++cooldown > 10) { - await Task.Delay(100).ConfigureAwait(false); + Thread.Sleep(60); cooldown = 0; } } @@ -904,7 +903,7 @@ namespace OpenSim.Region.CoreModules.Asset ++dirSize; string id = Path.GetFileName(file); - if (String.IsNullOrEmpty(id)) + if (string.IsNullOrEmpty(id)) continue; //?? if (m_defaultAssets.Contains(id) ||(UUID.TryParse(id, out UUID uid) && gids.ContainsKey(uid))) @@ -913,7 +912,7 @@ namespace OpenSim.Region.CoreModules.Asset continue; } - if (File.GetLastAccessTime(file) < purgeLine) + if (File.GetLastAccessTime(file) < purgeTimeline) { try { @@ -928,7 +927,7 @@ namespace OpenSim.Region.CoreModules.Asset if (++cooldown >= 20) { - await Task.Delay(100).ConfigureAwait(false); + Thread.Sleep(60); cooldown = 0; } } @@ -945,7 +944,7 @@ namespace OpenSim.Region.CoreModules.Asset cooldown += 5; if (cooldown >= 20) { - await Task.Delay(100).ConfigureAwait(false); + Thread.Sleep(60); cooldown = 0; } } @@ -1150,11 +1149,11 @@ namespace OpenSim.Region.CoreModules.Asset /// If true, then assets scanned which are not found in cache are added to the cache. /// /// Number of distinct asset references found in the scene. - private async Task TouchAllSceneAssets(bool tryGetUncached) + private int TouchAllSceneAssets(bool tryGetUncached) { m_log.Info("[FLOTSAM ASSET CACHE] start touch files of assets in use"); - Dictionary gatheredids = await gatherSceneAssets(); + Dictionary gatheredids = gatherSceneAssets(); int cooldown = 0; foreach(UUID id in gatheredids.Keys) @@ -1177,7 +1176,7 @@ namespace OpenSim.Region.CoreModules.Asset return gatheredids.Count; } - private async Task> gatherSceneAssets() + private Dictionary gatherSceneAssets() { m_log.Info("[FLOTSAM ASSET CACHE] gather assets in use"); @@ -1216,7 +1215,7 @@ namespace OpenSim.Region.CoreModules.Asset if (entity is SceneObjectGroup) { SceneObjectGroup e = entity as SceneObjectGroup; - if (e.IsDeleted) + if (e == null || e.IsDeleted) continue; gatherer.AddForInspection(e); @@ -1224,13 +1223,13 @@ namespace OpenSim.Region.CoreModules.Asset { if (++cooldown > 50) { - await Task.Delay(60).ConfigureAwait(false); + Thread.Sleep(60); cooldown = 0; } } if (++cooldown > 25) { - await Task.Delay(60).ConfigureAwait(false); + Thread.Sleep(60); cooldown = 0; } } @@ -1464,7 +1463,7 @@ namespace OpenSim.Region.CoreModules.Asset con.Output("Flotsam Ensuring assets are cached for all scenes."); - WorkManager.RunInThreadPool(async delegate + WorkManager.RunInThreadPool(delegate { bool wasRunning= false; lock(timerLock) @@ -1478,9 +1477,9 @@ namespace OpenSim.Region.CoreModules.Asset } if (wasRunning) - await Task.Delay(100).ConfigureAwait(false); + Thread.Sleep(120); - int assetReferenceTotal = await TouchAllSceneAssets(true).ConfigureAwait(false); + int assetReferenceTotal = TouchAllSceneAssets(true); lock(timerLock) { @@ -1510,6 +1509,7 @@ namespace OpenSim.Region.CoreModules.Asset if (cmdparams.Length < 3) { con.Output("Invalid parameters for Expire, please specify a valid date & time"); + m_cleanupRunning = false; break; } @@ -1537,7 +1537,7 @@ namespace OpenSim.Region.CoreModules.Asset } if (m_FileCacheEnabled) { - WorkManager.RunInThreadPool(async delegate + WorkManager.RunInThreadPool(delegate { bool wasRunning = false; lock (timerLock) @@ -1551,9 +1551,9 @@ namespace OpenSim.Region.CoreModules.Asset } if(wasRunning) - await Task.Delay(100).ConfigureAwait(false); + Thread.Sleep(120); - await DoCleanExpiredFiles(expirationDate).ConfigureAwait(false); + DoCleanExpiredFiles(expirationDate); lock (timerLock) { @@ -1564,7 +1564,7 @@ namespace OpenSim.Region.CoreModules.Asset } m_cleanupRunning = false; } - }, null, "TouchAllSceneAssets", false); + }, null, "ExpireSceneAssets", false); } else con.Output("File cache not active, not clearing.");