aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs')
-rw-r--r--OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs103
1 files changed, 60 insertions, 43 deletions
diff --git a/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs b/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs
index 2afe065..08d4fc0 100644
--- a/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs
+++ b/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs
@@ -31,17 +31,16 @@
31using System; 31using System;
32using System.IO; 32using System.IO;
33using System.Collections.Generic; 33using System.Collections.Generic;
34using System.Linq;
34using System.Reflection; 35using System.Reflection;
35using System.Runtime.Serialization; 36using System.Runtime.Serialization;
36using System.Runtime.Serialization.Formatters.Binary; 37using System.Runtime.Serialization.Formatters.Binary;
37using System.Threading; 38using System.Threading;
38using System.Timers; 39using System.Timers;
39
40using log4net; 40using log4net;
41using Nini.Config; 41using Nini.Config;
42using Mono.Addins; 42using Mono.Addins;
43using OpenMetaverse; 43using OpenMetaverse;
44
45using OpenSim.Framework; 44using OpenSim.Framework;
46using OpenSim.Framework.Console; 45using OpenSim.Framework.Console;
47using OpenSim.Region.Framework.Interfaces; 46using OpenSim.Region.Framework.Interfaces;
@@ -76,8 +75,6 @@ namespace OpenSim.Region.CoreModules.Asset
76 private static ulong m_RequestsForInprogress; 75 private static ulong m_RequestsForInprogress;
77 private static ulong m_DiskHits; 76 private static ulong m_DiskHits;
78 private static ulong m_MemoryHits; 77 private static ulong m_MemoryHits;
79 private static double m_HitRateMemory;
80 private static double m_HitRateFile;
81 78
82#if WAIT_ON_INPROGRESS_REQUESTS 79#if WAIT_ON_INPROGRESS_REQUESTS
83 private Dictionary<string, ManualResetEvent> m_CurrentlyWriting = new Dictionary<string, ManualResetEvent>(); 80 private Dictionary<string, ManualResetEvent> m_CurrentlyWriting = new Dictionary<string, ManualResetEvent>();
@@ -429,18 +426,9 @@ namespace OpenSim.Region.CoreModules.Asset
429 426
430 if (((m_LogLevel >= 1)) && (m_HitRateDisplay != 0) && (m_Requests % m_HitRateDisplay == 0)) 427 if (((m_LogLevel >= 1)) && (m_HitRateDisplay != 0) && (m_Requests % m_HitRateDisplay == 0))
431 { 428 {
432 m_HitRateFile = (double)m_DiskHits / m_Requests * 100.0;
433
434 m_log.InfoFormat("[FLOTSAM ASSET CACHE]: Cache Get :: {0} :: {1}", id, asset == null ? "Miss" : "Hit"); 429 m_log.InfoFormat("[FLOTSAM ASSET CACHE]: Cache Get :: {0} :: {1}", id, asset == null ? "Miss" : "Hit");
435 m_log.InfoFormat("[FLOTSAM ASSET CACHE]: File Hit Rate {0}% for {1} requests", m_HitRateFile.ToString("0.00"), m_Requests);
436 430
437 if (m_MemoryCacheEnabled) 431 GenerateCacheHitReport().ForEach(l => m_log.InfoFormat("[FLOTSAM ASSET CACHE]: {0}", l));
438 {
439 m_HitRateMemory = (double)m_MemoryHits / m_Requests * 100.0;
440 m_log.InfoFormat("[FLOTSAM ASSET CACHE]: Memory Hit Rate {0}% for {1} requests", m_HitRateMemory.ToString("0.00"), m_Requests);
441 }
442
443 m_log.InfoFormat("[FLOTSAM ASSET CACHE]: {0} unnessesary requests due to requests for assets that are currently downloading.", m_RequestsForInprogress);
444 } 432 }
445 433
446 return asset; 434 return asset;
@@ -807,45 +795,77 @@ namespace OpenSim.Region.CoreModules.Asset
807 } 795 }
808 } 796 }
809 797
798 private List<string> GenerateCacheHitReport()
799 {
800 List<string> outputLines = new List<string>();
801
802 double fileHitRate = (double)m_DiskHits / m_Requests * 100.0;
803 outputLines.Add(
804 string.Format("File Hit Rate: {0}% for {1} requests", fileHitRate.ToString("0.00"), m_Requests));
805
806 if (m_MemoryCacheEnabled)
807 {
808 double memHitRate = (double)m_MemoryHits / m_Requests * 100.0;
809
810 outputLines.Add(
811 string.Format("Memory Hit Rate: {0}% for {1} requests", memHitRate.ToString("0.00"), m_Requests));
812 }
813
814 outputLines.Add(
815 string.Format(
816 "Unnecessary requests due to requests for assets that are currently downloading: {0}",
817 m_RequestsForInprogress));
818
819 return outputLines;
820 }
821
810 #region Console Commands 822 #region Console Commands
811 private void HandleConsoleCommand(string module, string[] cmdparams) 823 private void HandleConsoleCommand(string module, string[] cmdparams)
812 { 824 {
825 ICommandConsole con = MainConsole.Instance;
826
813 if (cmdparams.Length >= 2) 827 if (cmdparams.Length >= 2)
814 { 828 {
815 string cmd = cmdparams[1]; 829 string cmd = cmdparams[1];
830
816 switch (cmd) 831 switch (cmd)
817 { 832 {
818 case "status": 833 case "status":
819 if (m_MemoryCacheEnabled) 834 if (m_MemoryCacheEnabled)
820 m_log.InfoFormat("[FLOTSAM ASSET CACHE]: Memory Cache : {0} assets", m_MemoryCache.Count); 835 con.OutputFormat("Memory Cache: {0} assets", m_MemoryCache.Count);
821 else 836 else
822 m_log.InfoFormat("[FLOTSAM ASSET CACHE]: Memory cache disabled"); 837 con.OutputFormat("Memory cache disabled");
823 838
824 if (m_FileCacheEnabled) 839 if (m_FileCacheEnabled)
825 { 840 {
826 int fileCount = GetFileCacheCount(m_CacheDirectory); 841 int fileCount = GetFileCacheCount(m_CacheDirectory);
827 m_log.InfoFormat("[FLOTSAM ASSET CACHE]: File Cache : {0} assets", fileCount); 842 con.OutputFormat("File Cache: {0} assets", fileCount);
843 }
844 else
845 {
846 con.Output("File cache disabled");
847 }
848
849 GenerateCacheHitReport().ForEach(l => con.Output(l));
850
851 if (m_FileCacheEnabled)
852 {
853 con.Output("Deep scans have previously been performed on the following regions:");
828 854
829 foreach (string s in Directory.GetFiles(m_CacheDirectory, "*.fac")) 855 foreach (string s in Directory.GetFiles(m_CacheDirectory, "*.fac"))
830 { 856 {
831 m_log.Info("[FLOTSAM ASSET CACHE]: Deep scans have previously been performed on the following regions:");
832
833 string RegionID = s.Remove(0,s.IndexOf("_")).Replace(".fac",""); 857 string RegionID = s.Remove(0,s.IndexOf("_")).Replace(".fac","");
834 DateTime RegionDeepScanTMStamp = File.GetLastWriteTime(s); 858 DateTime RegionDeepScanTMStamp = File.GetLastWriteTime(s);
835 m_log.InfoFormat("[FLOTSAM ASSET CACHE]: Region: {0}, {1}", RegionID, RegionDeepScanTMStamp.ToString("MM/dd/yyyy hh:mm:ss")); 859 con.OutputFormat("Region: {0}, {1}", RegionID, RegionDeepScanTMStamp.ToString("MM/dd/yyyy hh:mm:ss"));
836 } 860 }
837 } 861 }
838 else
839 {
840 m_log.InfoFormat("[FLOTSAM ASSET CACHE]: File cache disabled");
841 }
842 862
843 break; 863 break;
844 864
845 case "clear": 865 case "clear":
846 if (cmdparams.Length < 2) 866 if (cmdparams.Length < 2)
847 { 867 {
848 m_log.Warn("[FLOTSAM ASSET CACHE]: Usage is fcache clear [file] [memory]"); 868 con.Output("Usage is fcache clear [file] [memory]");
849 break; 869 break;
850 } 870 }
851 871
@@ -869,11 +889,11 @@ namespace OpenSim.Region.CoreModules.Asset
869 if (m_MemoryCacheEnabled) 889 if (m_MemoryCacheEnabled)
870 { 890 {
871 m_MemoryCache.Clear(); 891 m_MemoryCache.Clear();
872 m_log.Info("[FLOTSAM ASSET CACHE]: Memory cache cleared."); 892 con.Output("Memory cache cleared.");
873 } 893 }
874 else 894 else
875 { 895 {
876 m_log.Info("[FLOTSAM ASSET CACHE]: Memory cache not enabled."); 896 con.Output("Memory cache not enabled.");
877 } 897 }
878 } 898 }
879 899
@@ -882,24 +902,22 @@ namespace OpenSim.Region.CoreModules.Asset
882 if (m_FileCacheEnabled) 902 if (m_FileCacheEnabled)
883 { 903 {
884 ClearFileCache(); 904 ClearFileCache();
885 m_log.Info("[FLOTSAM ASSET CACHE]: File cache cleared."); 905 con.Output("File cache cleared.");
886 } 906 }
887 else 907 else
888 { 908 {
889 m_log.Info("[FLOTSAM ASSET CACHE]: File cache not enabled."); 909 con.Output("File cache not enabled.");
890 } 910 }
891 } 911 }
892 912
893 break; 913 break;
894 914
895 case "assets": 915 case "assets":
896 m_log.Info("[FLOTSAM ASSET CACHE]: Ensuring assets are cached for all scenes."); 916 con.Output("Ensuring assets are cached for all scenes.");
897 917
898 Util.FireAndForget(delegate { 918 Util.FireAndForget(delegate {
899 int assetReferenceTotal = TouchAllSceneAssets(true); 919 int assetReferenceTotal = TouchAllSceneAssets(true);
900 m_log.InfoFormat( 920 con.OutputFormat("Completed check with {0} assets.", assetReferenceTotal);
901 "[FLOTSAM ASSET CACHE]: Completed check with {0} assets.",
902 assetReferenceTotal);
903 }); 921 });
904 922
905 break; 923 break;
@@ -907,7 +925,7 @@ namespace OpenSim.Region.CoreModules.Asset
907 case "expire": 925 case "expire":
908 if (cmdparams.Length < 3) 926 if (cmdparams.Length < 3)
909 { 927 {
910 m_log.InfoFormat("[FLOTSAM ASSET CACHE]: Invalid parameters for Expire, please specify a valid date & time", cmd); 928 con.OutputFormat("Invalid parameters for Expire, please specify a valid date & time", cmd);
911 break; 929 break;
912 } 930 }
913 931
@@ -925,28 +943,27 @@ namespace OpenSim.Region.CoreModules.Asset
925 943
926 if (!DateTime.TryParse(s_expirationDate, out expirationDate)) 944 if (!DateTime.TryParse(s_expirationDate, out expirationDate))
927 { 945 {
928 m_log.InfoFormat("[FLOTSAM ASSET CACHE]: {0} is not a valid date & time", cmd); 946 con.OutputFormat("{0} is not a valid date & time", cmd);
929 break; 947 break;
930 } 948 }
931 949
932 if (m_FileCacheEnabled) 950 if (m_FileCacheEnabled)
933 CleanExpiredFiles(m_CacheDirectory, expirationDate); 951 CleanExpiredFiles(m_CacheDirectory, expirationDate);
934 else 952 else
935 m_log.InfoFormat("[FLOTSAM ASSET CACHE]: File cache not active, not clearing."); 953 con.OutputFormat("File cache not active, not clearing.");
936 954
937 break; 955 break;
938 default: 956 default:
939 m_log.InfoFormat("[FLOTSAM ASSET CACHE]: Unknown command {0}", cmd); 957 con.OutputFormat("Unknown command {0}", cmd);
940 break; 958 break;
941 } 959 }
942 } 960 }
943 else if (cmdparams.Length == 1) 961 else if (cmdparams.Length == 1)
944 { 962 {
945 m_log.InfoFormat("[FLOTSAM ASSET CACHE]: fcache status - Display cache status"); 963 con.Output("fcache assets - Attempt a deep cache of all assets in all scenes");
946 m_log.InfoFormat("[FLOTSAM ASSET CACHE]: fcache clearmem - Remove all assets cached in memory"); 964 con.Output("fcache expire <datetime> - Purge assets older then the specified date & time");
947 m_log.InfoFormat("[FLOTSAM ASSET CACHE]: fcache clearfile - Remove all assets cached on disk"); 965 con.Output("fcache clear [file] [memory] - Remove cached assets");
948 m_log.InfoFormat("[FLOTSAM ASSET CACHE]: fcache cachescenes - Attempt a deep cache of all assets in all scenes"); 966 con.Output("fcache status - Display cache status");
949 m_log.InfoFormat("[FLOTSAM ASSET CACHE]: fcache <datetime> - Purge assets older then the specified date & time");
950 } 967 }
951 } 968 }
952 969