diff options
author | Teravus Ovares (Dan Olivares) | 2009-09-09 16:20:46 -0400 |
---|---|---|
committer | Teravus Ovares (Dan Olivares) | 2009-09-09 16:20:46 -0400 |
commit | df9f80aabd872c11711e1e4efb400a1921a9cab2 (patch) | |
tree | a7d5582ed1d763224727c8a6bdf9c1c94a674abd /OpenSim/Region/CoreModules/Asset | |
parent | * Lock timers when Calling Start() and Stop() when the Thread Context is murk... (diff) | |
parent | De-hardcode default home locations on create user (standalone). (diff) | |
download | opensim-SC_OLD-df9f80aabd872c11711e1e4efb400a1921a9cab2.zip opensim-SC_OLD-df9f80aabd872c11711e1e4efb400a1921a9cab2.tar.gz opensim-SC_OLD-df9f80aabd872c11711e1e4efb400a1921a9cab2.tar.bz2 opensim-SC_OLD-df9f80aabd872c11711e1e4efb400a1921a9cab2.tar.xz |
Merge branch 'master' of ssh://MyConnection/var/git/opensim
Diffstat (limited to 'OpenSim/Region/CoreModules/Asset')
-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 49b459a..6b0af6d 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)); |
@@ -191,6 +191,8 @@ namespace Flotsam.RegionModules.AssetCache | |||
191 | } | 191 | } |
192 | 192 | ||
193 | m_CacheWarnAt = assetConfig.GetInt("CacheWarnAt", 30000); | 193 | m_CacheWarnAt = assetConfig.GetInt("CacheWarnAt", 30000); |
194 | |||
195 | |||
194 | } | 196 | } |
195 | } | 197 | } |
196 | } | 198 | } |
@@ -206,7 +208,14 @@ namespace Flotsam.RegionModules.AssetCache | |||
206 | public void AddRegion(Scene scene) | 208 | public void AddRegion(Scene scene) |
207 | { | 209 | { |
208 | if (m_Enabled) | 210 | if (m_Enabled) |
211 | { | ||
209 | scene.RegisterModuleInterface<IImprovedAssetCache>(this); | 212 | scene.RegisterModuleInterface<IImprovedAssetCache>(this); |
213 | |||
214 | //scene.AddCommand(this, "flotsamcache", "", "Display a list of console commands for the Flotsam Asset Cache", HandleConsoleCommand); | ||
215 | scene.AddCommand(this, "flotsamcache counts", "flotsamcache counts", "Display the number of cached assets", HandleConsoleCommand); | ||
216 | scene.AddCommand(this, "flotsamcache clearmem", "flotsamcache clearmem", "Remove all assets cached in memory", HandleConsoleCommand); | ||
217 | scene.AddCommand(this, "flotsamcache clearfile", "flotsamcache clearfile", "Remove all assets cached on disk", HandleConsoleCommand); | ||
218 | } | ||
210 | } | 219 | } |
211 | 220 | ||
212 | public void RemoveRegion(Scene scene) | 221 | public void RemoveRegion(Scene scene) |
@@ -368,16 +377,16 @@ namespace Flotsam.RegionModules.AssetCache | |||
368 | { | 377 | { |
369 | m_HitRateFile = (double)m_DiskHits / m_Requests * 100.0; | 378 | m_HitRateFile = (double)m_DiskHits / m_Requests * 100.0; |
370 | 379 | ||
371 | m_log.InfoFormat("[ASSET CACHE]: Cache Get :: {0} :: {1}", id, asset == null ? "Miss" : "Hit"); | 380 | m_log.InfoFormat("[FLOTSAM ASSET CACHE]: Cache Get :: {0} :: {1}", id, asset == null ? "Miss" : "Hit"); |
372 | m_log.InfoFormat("[ASSET CACHE]: File Hit Rate {0}% for {1} requests", m_HitRateFile.ToString("0.00"), m_Requests); | 381 | m_log.InfoFormat("[FLOTSAM ASSET CACHE]: File Hit Rate {0}% for {1} requests", m_HitRateFile.ToString("0.00"), m_Requests); |
373 | 382 | ||
374 | if (m_MemoryCacheEnabled) | 383 | if (m_MemoryCacheEnabled) |
375 | { | 384 | { |
376 | m_HitRateMemory = (double)m_MemoryHits / m_Requests * 100.0; | 385 | m_HitRateMemory = (double)m_MemoryHits / m_Requests * 100.0; |
377 | m_log.InfoFormat("[ASSET CACHE]: Memory Hit Rate {0}% for {1} requests", m_HitRateMemory.ToString("0.00"), m_Requests); | 386 | m_log.InfoFormat("[FLOTSAM ASSET CACHE]: Memory Hit Rate {0}% for {1} requests", m_HitRateMemory.ToString("0.00"), m_Requests); |
378 | } | 387 | } |
379 | 388 | ||
380 | m_log.InfoFormat("[ASSET CACHE]: {0} unnessesary requests due to requests for assets that are currently downloading.", m_RequestsForInprogress); | 389 | m_log.InfoFormat("[FLOTSAM ASSET CACHE]: {0} unnessesary requests due to requests for assets that are currently downloading.", m_RequestsForInprogress); |
381 | 390 | ||
382 | } | 391 | } |
383 | 392 | ||
@@ -387,7 +396,7 @@ namespace Flotsam.RegionModules.AssetCache | |||
387 | public void Expire(string id) | 396 | public void Expire(string id) |
388 | { | 397 | { |
389 | if (m_LogLevel >= 2) | 398 | if (m_LogLevel >= 2) |
390 | m_log.DebugFormat("[ASSET CACHE]: Expiring Asset {0}.", id); | 399 | m_log.DebugFormat("[FLOTSAM ASSET CACHE]: Expiring Asset {0}.", id); |
391 | 400 | ||
392 | try | 401 | try |
393 | { | 402 | { |
@@ -409,7 +418,7 @@ namespace Flotsam.RegionModules.AssetCache | |||
409 | public void Clear() | 418 | public void Clear() |
410 | { | 419 | { |
411 | if (m_LogLevel >= 2) | 420 | if (m_LogLevel >= 2) |
412 | m_log.Debug("[ASSET CACHE]: Clearing Cache."); | 421 | m_log.Debug("[FLOTSAM ASSET CACHE]: Clearing Cache."); |
413 | 422 | ||
414 | foreach (string dir in Directory.GetDirectories(m_CacheDirectory)) | 423 | foreach (string dir in Directory.GetDirectories(m_CacheDirectory)) |
415 | { | 424 | { |
@@ -423,29 +432,42 @@ namespace Flotsam.RegionModules.AssetCache | |||
423 | private void CleanupExpiredFiles(object source, ElapsedEventArgs e) | 432 | private void CleanupExpiredFiles(object source, ElapsedEventArgs e) |
424 | { | 433 | { |
425 | if (m_LogLevel >= 2) | 434 | if (m_LogLevel >= 2) |
426 | m_log.DebugFormat("[ASSET CACHE]: Checking for expired files older then {0}.", m_FileExpiration.ToString()); | 435 | m_log.DebugFormat("[FLOTSAM ASSET CACHE]: Checking for expired files older then {0}.", m_FileExpiration.ToString()); |
427 | 436 | ||
428 | foreach (string dir in Directory.GetDirectories(m_CacheDirectory)) | 437 | foreach (string dir in Directory.GetDirectories(m_CacheDirectory)) |
429 | { | 438 | { |
430 | foreach (string file in Directory.GetFiles(dir)) | 439 | CleanExpiredFiles(dir); |
431 | { | 440 | } |
432 | if (DateTime.Now - File.GetLastAccessTime(file) > m_FileExpiration) | 441 | } |
433 | { | ||
434 | File.Delete(file); | ||
435 | } | ||
436 | } | ||
437 | 442 | ||
438 | int dirSize = Directory.GetFiles(dir).Length; | 443 | /// <summary> |
439 | if (dirSize == 0) | 444 | /// Recurses through specified directory checking for expired asset files and deletes them. Also removes empty directories. |
440 | { | 445 | /// </summary> |
441 | Directory.Delete(dir); | 446 | /// <param name="dir"></param> |
442 | } | 447 | private void CleanExpiredFiles(string dir) |
443 | else if (dirSize >= m_CacheWarnAt) | 448 | { |
449 | foreach (string file in Directory.GetFiles(dir)) | ||
450 | { | ||
451 | if (DateTime.Now - File.GetLastAccessTime(file) > m_FileExpiration) | ||
444 | { | 452 | { |
445 | m_log.WarnFormat("[ASSET CACHE]: Cache folder exceeded CacheWarnAt limit {0} {1}. Suggest increasing tiers, tier length, or reducing cache expiration", dir, dirSize); | 453 | File.Delete(file); |
446 | } | 454 | } |
447 | |||
448 | } | 455 | } |
456 | |||
457 | foreach (string subdir in Directory.GetDirectories(dir)) | ||
458 | { | ||
459 | CleanExpiredFiles(subdir); | ||
460 | } | ||
461 | |||
462 | int dirSize = Directory.GetFiles(dir).Length + Directory.GetDirectories(dir).Length; | ||
463 | if (dirSize == 0) | ||
464 | { | ||
465 | Directory.Delete(dir); | ||
466 | } | ||
467 | else if (dirSize >= m_CacheWarnAt) | ||
468 | { | ||
469 | m_log.WarnFormat("[FLOTSAM ASSET CACHE]: Cache folder exceeded CacheWarnAt limit {0} {1}. Suggest increasing tiers, tier length, or reducing cache expiration", dir, dirSize); | ||
470 | } | ||
449 | } | 471 | } |
450 | 472 | ||
451 | private string GetFileName(string id) | 473 | private string GetFileName(string id) |
@@ -489,7 +511,7 @@ namespace Flotsam.RegionModules.AssetCache | |||
489 | File.Move(tempname, filename); | 511 | File.Move(tempname, filename); |
490 | 512 | ||
491 | if (m_LogLevel >= 2) | 513 | if (m_LogLevel >= 2) |
492 | m_log.DebugFormat("[ASSET CACHE]: Cache Stored :: {0}", asset.ID); | 514 | m_log.DebugFormat("[FLOTSAM ASSET CACHE]: Cache Stored :: {0}", asset.ID); |
493 | } | 515 | } |
494 | catch (Exception e) | 516 | catch (Exception e) |
495 | { | 517 | { |
@@ -525,8 +547,88 @@ namespace Flotsam.RegionModules.AssetCache | |||
525 | string[] text = e.ToString().Split(new char[] { '\n' }); | 547 | string[] text = e.ToString().Split(new char[] { '\n' }); |
526 | foreach (string t in text) | 548 | foreach (string t in text) |
527 | { | 549 | { |
528 | m_log.ErrorFormat("[ASSET CACHE]: {0} ", t); | 550 | m_log.ErrorFormat("[FLOTSAM ASSET CACHE]: {0} ", t); |
551 | } | ||
552 | } | ||
553 | |||
554 | private int GetFileCacheCount(string dir) | ||
555 | { | ||
556 | int count = Directory.GetFiles(dir).Length; | ||
557 | |||
558 | foreach (string subdir in Directory.GetDirectories(dir)) | ||
559 | { | ||
560 | count += GetFileCacheCount(subdir); | ||
529 | } | 561 | } |
562 | |||
563 | return count; | ||
530 | } | 564 | } |
565 | |||
566 | #region Console Commands | ||
567 | private void HandleConsoleCommand(string module, string[] cmdparams) | ||
568 | { | ||
569 | if (cmdparams.Length == 2) | ||
570 | { | ||
571 | string cmd = cmdparams[1]; | ||
572 | switch (cmd) | ||
573 | { | ||
574 | case "count": | ||
575 | case "counts": | ||
576 | m_log.InfoFormat("[FLOTSAM ASSET CACHE] Memory Cache : {0}", m_MemoryCache.Count); | ||
577 | |||
578 | int fileCount = GetFileCacheCount(m_CacheDirectory); | ||
579 | m_log.InfoFormat("[FLOTSAM ASSET CACHE] File Cache : {0}", fileCount); | ||
580 | |||
581 | break; | ||
582 | |||
583 | case "clearmem": | ||
584 | m_MemoryCache.Clear(); | ||
585 | m_log.InfoFormat("[FLOTSAM ASSET CACHE] Memory Cache Cleared, there are now {0} items in the memory cache", m_MemoryCache.Count); | ||
586 | break; | ||
587 | |||
588 | case "clearfile": | ||
589 | foreach (string dir in Directory.GetDirectories(m_CacheDirectory)) | ||
590 | { | ||
591 | try | ||
592 | { | ||
593 | Directory.Delete(dir, true); | ||
594 | } | ||
595 | catch (Exception e) | ||
596 | { | ||
597 | LogException(e); | ||
598 | } | ||
599 | } | ||
600 | |||
601 | foreach (string file in Directory.GetFiles(m_CacheDirectory)) | ||
602 | { | ||
603 | try | ||
604 | { | ||
605 | File.Delete(file); | ||
606 | } | ||
607 | catch (Exception e) | ||
608 | { | ||
609 | LogException(e); | ||
610 | } | ||
611 | } | ||
612 | |||
613 | break; | ||
614 | |||
615 | default: | ||
616 | m_log.InfoFormat("[FLOTSAM ASSET CACHE] Unknown command {0}", cmd); | ||
617 | break; | ||
618 | } | ||
619 | } | ||
620 | else if (cmdparams.Length == 1) | ||
621 | { | ||
622 | m_log.InfoFormat("[FLOTSAM ASSET CACHE] flotsamcache counts - Display the number of cached assets"); | ||
623 | m_log.InfoFormat("[FLOTSAM ASSET CACHE] flotsamcache clearmem - Remove all assets cached in memory"); | ||
624 | m_log.InfoFormat("[FLOTSAM ASSET CACHE] flotsamcache clearfile - Remove all assets cached on disk"); | ||
625 | |||
626 | } | ||
627 | |||
628 | |||
629 | } | ||
630 | |||
631 | #endregion | ||
632 | |||
531 | } | 633 | } |
532 | } | 634 | } |