diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs | 158 |
1 files changed, 130 insertions, 28 deletions
diff --git a/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs b/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs index 53b8ebc..c520356 100644 --- a/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs +++ b/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs | |||
@@ -129,18 +129,18 @@ namespace Flotsam.RegionModules.AssetCache | |||
129 | if (name == Name) | 129 | if (name == Name) |
130 | { | 130 | { |
131 | m_Enabled = true; | 131 | m_Enabled = true; |
132 | m_log.InfoFormat("[ASSET CACHE]: {0} enabled", this.Name); | 132 | m_log.InfoFormat("[FLOTSAM ASSET CACHE]: {0} enabled", this.Name); |
133 | 133 | ||
134 | IConfig assetConfig = source.Configs["AssetCache"]; | 134 | IConfig assetConfig = source.Configs["AssetCache"]; |
135 | if (assetConfig == null) | 135 | if (assetConfig == null) |
136 | { | 136 | { |
137 | m_log.Warn("[ASSET CACHE]: AssetCache missing from OpenSim.ini, using defaults."); | 137 | m_log.Warn("[FLOTSAM ASSET CACHE]: AssetCache missing from OpenSim.ini, using defaults."); |
138 | m_log.InfoFormat("[ASSET CACHE]: Cache Directory", m_DefaultCacheDirectory); | 138 | m_log.InfoFormat("[FLOTSAM ASSET CACHE]: Cache Directory", m_DefaultCacheDirectory); |
139 | return; | 139 | return; |
140 | } | 140 | } |
141 | 141 | ||
142 | m_CacheDirectory = assetConfig.GetString("CacheDirectory", m_DefaultCacheDirectory); | 142 | m_CacheDirectory = assetConfig.GetString("CacheDirectory", m_DefaultCacheDirectory); |
143 | m_log.InfoFormat("[ASSET CACHE]: Cache Directory", m_DefaultCacheDirectory); | 143 | m_log.InfoFormat("[FLOTSAM ASSET CACHE]: Cache Directory", m_DefaultCacheDirectory); |
144 | 144 | ||
145 | m_MemoryCacheEnabled = assetConfig.GetBoolean("MemoryCacheEnabled", true); | 145 | m_MemoryCacheEnabled = assetConfig.GetBoolean("MemoryCacheEnabled", true); |
146 | m_MemoryExpiration = TimeSpan.FromHours(assetConfig.GetDouble("MemoryCacheTimeout", m_DefaultMemoryExpiration)); | 146 | m_MemoryExpiration = TimeSpan.FromHours(assetConfig.GetDouble("MemoryCacheTimeout", m_DefaultMemoryExpiration)); |
@@ -188,6 +188,8 @@ namespace Flotsam.RegionModules.AssetCache | |||
188 | } | 188 | } |
189 | 189 | ||
190 | m_CacheWarnAt = assetConfig.GetInt("CacheWarnAt", 30000); | 190 | m_CacheWarnAt = assetConfig.GetInt("CacheWarnAt", 30000); |
191 | |||
192 | |||
191 | } | 193 | } |
192 | } | 194 | } |
193 | } | 195 | } |
@@ -203,7 +205,14 @@ namespace Flotsam.RegionModules.AssetCache | |||
203 | public void AddRegion(Scene scene) | 205 | public void AddRegion(Scene scene) |
204 | { | 206 | { |
205 | if (m_Enabled) | 207 | if (m_Enabled) |
208 | { | ||
206 | scene.RegisterModuleInterface<IImprovedAssetCache>(this); | 209 | scene.RegisterModuleInterface<IImprovedAssetCache>(this); |
210 | |||
211 | //scene.AddCommand(this, "flotsamcache", "", "Display a list of console commands for the Flotsam Asset Cache", HandleConsoleCommand); | ||
212 | scene.AddCommand(this, "flotsamcache counts", "flotsamcache counts", "Display the number of cached assets", HandleConsoleCommand); | ||
213 | scene.AddCommand(this, "flotsamcache clearmem", "flotsamcache clearmem", "Remove all assets cached in memory", HandleConsoleCommand); | ||
214 | scene.AddCommand(this, "flotsamcache clearfile", "flotsamcache clearfile", "Remove all assets cached on disk", HandleConsoleCommand); | ||
215 | } | ||
207 | } | 216 | } |
208 | 217 | ||
209 | public void RemoveRegion(Scene scene) | 218 | public void RemoveRegion(Scene scene) |
@@ -365,16 +374,16 @@ namespace Flotsam.RegionModules.AssetCache | |||
365 | { | 374 | { |
366 | m_HitRateFile = (double)m_DiskHits / m_Requests * 100.0; | 375 | m_HitRateFile = (double)m_DiskHits / m_Requests * 100.0; |
367 | 376 | ||
368 | m_log.InfoFormat("[ASSET CACHE]: Cache Get :: {0} :: {1}", id, asset == null ? "Miss" : "Hit"); | 377 | m_log.InfoFormat("[FLOTSAM ASSET CACHE]: Cache Get :: {0} :: {1}", id, asset == null ? "Miss" : "Hit"); |
369 | m_log.InfoFormat("[ASSET CACHE]: File Hit Rate {0}% for {1} requests", m_HitRateFile.ToString("0.00"), m_Requests); | 378 | m_log.InfoFormat("[FLOTSAM ASSET CACHE]: File Hit Rate {0}% for {1} requests", m_HitRateFile.ToString("0.00"), m_Requests); |
370 | 379 | ||
371 | if (m_MemoryCacheEnabled) | 380 | if (m_MemoryCacheEnabled) |
372 | { | 381 | { |
373 | m_HitRateMemory = (double)m_MemoryHits / m_Requests * 100.0; | 382 | m_HitRateMemory = (double)m_MemoryHits / m_Requests * 100.0; |
374 | m_log.InfoFormat("[ASSET CACHE]: Memory Hit Rate {0}% for {1} requests", m_HitRateMemory.ToString("0.00"), m_Requests); | 383 | m_log.InfoFormat("[FLOTSAM ASSET CACHE]: Memory Hit Rate {0}% for {1} requests", m_HitRateMemory.ToString("0.00"), m_Requests); |
375 | } | 384 | } |
376 | 385 | ||
377 | m_log.InfoFormat("[ASSET CACHE]: {0} unnessesary requests due to requests for assets that are currently downloading.", m_RequestsForInprogress); | 386 | m_log.InfoFormat("[FLOTSAM ASSET CACHE]: {0} unnessesary requests due to requests for assets that are currently downloading.", m_RequestsForInprogress); |
378 | 387 | ||
379 | } | 388 | } |
380 | 389 | ||
@@ -384,7 +393,7 @@ namespace Flotsam.RegionModules.AssetCache | |||
384 | public void Expire(string id) | 393 | public void Expire(string id) |
385 | { | 394 | { |
386 | if (m_LogLevel >= 2) | 395 | if (m_LogLevel >= 2) |
387 | m_log.DebugFormat("[ASSET CACHE]: Expiring Asset {0}.", id); | 396 | m_log.DebugFormat("[FLOTSAM ASSET CACHE]: Expiring Asset {0}.", id); |
388 | 397 | ||
389 | try | 398 | try |
390 | { | 399 | { |
@@ -406,7 +415,7 @@ namespace Flotsam.RegionModules.AssetCache | |||
406 | public void Clear() | 415 | public void Clear() |
407 | { | 416 | { |
408 | if (m_LogLevel >= 2) | 417 | if (m_LogLevel >= 2) |
409 | m_log.Debug("[ASSET CACHE]: Clearing Cache."); | 418 | m_log.Debug("[FLOTSAM ASSET CACHE]: Clearing Cache."); |
410 | 419 | ||
411 | foreach (string dir in Directory.GetDirectories(m_CacheDirectory)) | 420 | foreach (string dir in Directory.GetDirectories(m_CacheDirectory)) |
412 | { | 421 | { |
@@ -420,29 +429,42 @@ namespace Flotsam.RegionModules.AssetCache | |||
420 | private void CleanupExpiredFiles(object source, ElapsedEventArgs e) | 429 | private void CleanupExpiredFiles(object source, ElapsedEventArgs e) |
421 | { | 430 | { |
422 | if (m_LogLevel >= 2) | 431 | if (m_LogLevel >= 2) |
423 | m_log.DebugFormat("[ASSET CACHE]: Checking for expired files older then {0}.", m_FileExpiration.ToString()); | 432 | m_log.DebugFormat("[FLOTSAM ASSET CACHE]: Checking for expired files older then {0}.", m_FileExpiration.ToString()); |
424 | 433 | ||
425 | foreach (string dir in Directory.GetDirectories(m_CacheDirectory)) | 434 | foreach (string dir in Directory.GetDirectories(m_CacheDirectory)) |
426 | { | 435 | { |
427 | foreach (string file in Directory.GetFiles(dir)) | 436 | CleanExpiredFiles(dir); |
428 | { | 437 | } |
429 | if (DateTime.Now - File.GetLastAccessTime(file) > m_FileExpiration) | 438 | } |
430 | { | ||
431 | File.Delete(file); | ||
432 | } | ||
433 | } | ||
434 | 439 | ||
435 | int dirSize = Directory.GetFiles(dir).Length; | 440 | /// <summary> |
436 | if (dirSize == 0) | 441 | /// Recurses through specified directory checking for expired asset files and deletes them. Also removes empty directories. |
437 | { | 442 | /// </summary> |
438 | Directory.Delete(dir); | 443 | /// <param name="dir"></param> |
439 | } | 444 | private void CleanExpiredFiles(string dir) |
440 | else if (dirSize >= m_CacheWarnAt) | 445 | { |
446 | foreach (string file in Directory.GetFiles(dir)) | ||
447 | { | ||
448 | if (DateTime.Now - File.GetLastAccessTime(file) > m_FileExpiration) | ||
441 | { | 449 | { |
442 | m_log.WarnFormat("[ASSET CACHE]: Cache folder exceeded CacheWarnAt limit {0} {1}. Suggest increasing tiers, tier length, or reducing cache expiration", dir, dirSize); | 450 | File.Delete(file); |
443 | } | 451 | } |
444 | |||
445 | } | 452 | } |
453 | |||
454 | foreach (string subdir in Directory.GetDirectories(dir)) | ||
455 | { | ||
456 | CleanExpiredFiles(subdir); | ||
457 | } | ||
458 | |||
459 | int dirSize = Directory.GetFiles(dir).Length + Directory.GetDirectories(dir).Length; | ||
460 | if (dirSize == 0) | ||
461 | { | ||
462 | Directory.Delete(dir); | ||
463 | } | ||
464 | else if (dirSize >= m_CacheWarnAt) | ||
465 | { | ||
466 | m_log.WarnFormat("[FLOTSAM ASSET CACHE]: Cache folder exceeded CacheWarnAt limit {0} {1}. Suggest increasing tiers, tier length, or reducing cache expiration", dir, dirSize); | ||
467 | } | ||
446 | } | 468 | } |
447 | 469 | ||
448 | private string GetFileName(string id) | 470 | private string GetFileName(string id) |
@@ -486,7 +508,7 @@ namespace Flotsam.RegionModules.AssetCache | |||
486 | File.Move(tempname, filename); | 508 | File.Move(tempname, filename); |
487 | 509 | ||
488 | if (m_LogLevel >= 2) | 510 | if (m_LogLevel >= 2) |
489 | m_log.DebugFormat("[ASSET CACHE]: Cache Stored :: {0}", asset.ID); | 511 | m_log.DebugFormat("[FLOTSAM ASSET CACHE]: Cache Stored :: {0}", asset.ID); |
490 | } | 512 | } |
491 | catch (Exception e) | 513 | catch (Exception e) |
492 | { | 514 | { |
@@ -522,8 +544,88 @@ namespace Flotsam.RegionModules.AssetCache | |||
522 | string[] text = e.ToString().Split(new char[] { '\n' }); | 544 | string[] text = e.ToString().Split(new char[] { '\n' }); |
523 | foreach (string t in text) | 545 | foreach (string t in text) |
524 | { | 546 | { |
525 | m_log.ErrorFormat("[ASSET CACHE]: {0} ", t); | 547 | m_log.ErrorFormat("[FLOTSAM ASSET CACHE]: {0} ", t); |
548 | } | ||
549 | } | ||
550 | |||
551 | private int GetFileCacheCount(string dir) | ||
552 | { | ||
553 | int count = Directory.GetFiles(dir).Length; | ||
554 | |||
555 | foreach (string subdir in Directory.GetDirectories(dir)) | ||
556 | { | ||
557 | count += GetFileCacheCount(subdir); | ||
526 | } | 558 | } |
559 | |||
560 | return count; | ||
527 | } | 561 | } |
562 | |||
563 | #region Console Commands | ||
564 | private void HandleConsoleCommand(string module, string[] cmdparams) | ||
565 | { | ||
566 | if (cmdparams.Length == 2) | ||
567 | { | ||
568 | string cmd = cmdparams[1]; | ||
569 | switch (cmd) | ||
570 | { | ||
571 | case "count": | ||
572 | case "counts": | ||
573 | m_log.InfoFormat("[FLOTSAM ASSET CACHE] Memory Cache : {0}", m_MemoryCache.Count); | ||
574 | |||
575 | int fileCount = GetFileCacheCount(m_CacheDirectory); | ||
576 | m_log.InfoFormat("[FLOTSAM ASSET CACHE] File Cache : {0}", fileCount); | ||
577 | |||
578 | break; | ||
579 | |||
580 | case "clearmem": | ||
581 | m_MemoryCache.Clear(); | ||
582 | m_log.InfoFormat("[FLOTSAM ASSET CACHE] Memory Cache Cleared, there are now {0} items in the memory cache", m_MemoryCache.Count); | ||
583 | break; | ||
584 | |||
585 | case "clearfile": | ||
586 | foreach (string dir in Directory.GetDirectories(m_CacheDirectory)) | ||
587 | { | ||
588 | try | ||
589 | { | ||
590 | Directory.Delete(dir, true); | ||
591 | } | ||
592 | catch (Exception e) | ||
593 | { | ||
594 | LogException(e); | ||
595 | } | ||
596 | } | ||
597 | |||
598 | foreach (string file in Directory.GetFiles(m_CacheDirectory)) | ||
599 | { | ||
600 | try | ||
601 | { | ||
602 | File.Delete(file); | ||
603 | } | ||
604 | catch (Exception e) | ||
605 | { | ||
606 | LogException(e); | ||
607 | } | ||
608 | } | ||
609 | |||
610 | break; | ||
611 | |||
612 | default: | ||
613 | m_log.InfoFormat("[FLOTSAM ASSET CACHE] Unknown command {0}", cmd); | ||
614 | break; | ||
615 | } | ||
616 | } | ||
617 | else if (cmdparams.Length == 1) | ||
618 | { | ||
619 | m_log.InfoFormat("[FLOTSAM ASSET CACHE] flotsamcache counts - Display the number of cached assets"); | ||
620 | m_log.InfoFormat("[FLOTSAM ASSET CACHE] flotsamcache clearmem - Remove all assets cached in memory"); | ||
621 | m_log.InfoFormat("[FLOTSAM ASSET CACHE] flotsamcache clearfile - Remove all assets cached on disk"); | ||
622 | |||
623 | } | ||
624 | |||
625 | |||
626 | } | ||
627 | |||
628 | #endregion | ||
629 | |||
528 | } | 630 | } |
529 | } | 631 | } |