aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Servers/ServerBase.cs
diff options
context:
space:
mode:
authoronefang2019-05-19 21:24:15 +1000
committeronefang2019-05-19 21:24:15 +1000
commit5e4d6cab00cb29cd088ab7b62ab13aff103b64cb (patch)
treea9fbc62df9eb2d1d9ba2698d8552eae71eca20d8 /OpenSim/Framework/Servers/ServerBase.cs
parentAdd a build script. (diff)
downloadopensim-SC_OLD-5e4d6cab00cb29cd088ab7b62ab13aff103b64cb.zip
opensim-SC_OLD-5e4d6cab00cb29cd088ab7b62ab13aff103b64cb.tar.gz
opensim-SC_OLD-5e4d6cab00cb29cd088ab7b62ab13aff103b64cb.tar.bz2
opensim-SC_OLD-5e4d6cab00cb29cd088ab7b62ab13aff103b64cb.tar.xz
Dump OpenSim 0.9.0.1 into it's own branch.
Diffstat (limited to 'OpenSim/Framework/Servers/ServerBase.cs')
-rw-r--r--OpenSim/Framework/Servers/ServerBase.cs180
1 files changed, 83 insertions, 97 deletions
diff --git a/OpenSim/Framework/Servers/ServerBase.cs b/OpenSim/Framework/Servers/ServerBase.cs
index 07a09e6..3c2dce8 100644
--- a/OpenSim/Framework/Servers/ServerBase.cs
+++ b/OpenSim/Framework/Servers/ServerBase.cs
@@ -56,7 +56,8 @@ namespace OpenSim.Framework.Servers
56 protected ICommandConsole m_console; 56 protected ICommandConsole m_console;
57 57
58 protected OpenSimAppender m_consoleAppender; 58 protected OpenSimAppender m_consoleAppender;
59 protected FileAppender m_logFileAppender; 59 protected FileAppender m_logFileAppender;
60 protected FileAppender m_statsLogFileAppender;
60 61
61 protected DateTime m_startuptime; 62 protected DateTime m_startuptime;
62 protected string m_startupDirectory = Environment.CurrentDirectory; 63 protected string m_startupDirectory = Environment.CurrentDirectory;
@@ -81,7 +82,7 @@ namespace OpenSim.Framework.Servers
81 { 82 {
82 if (File.Exists(path)) 83 if (File.Exists(path))
83 m_log.ErrorFormat( 84 m_log.ErrorFormat(
84 "[SERVER BASE]: Previous pid file {0} still exists on startup. Possibly previously unclean shutdown.", 85 "[SERVER BASE]: Previous pid file {0} still exists on startup. Possibly previously unclean shutdown.",
85 path); 86 path);
86 87
87 try 88 try
@@ -103,7 +104,7 @@ namespace OpenSim.Framework.Servers
103 m_log.Warn(string.Format("[SERVER BASE]: Could not create PID file at {0} ", path), e); 104 m_log.Warn(string.Format("[SERVER BASE]: Could not create PID file at {0} ", path), e);
104 } 105 }
105 } 106 }
106 107
107 protected void RemovePIDFile() 108 protected void RemovePIDFile()
108 { 109 {
109 if (m_pidFile != String.Empty) 110 if (m_pidFile != String.Empty)
@@ -156,6 +157,10 @@ namespace OpenSim.Framework.Servers
156 { 157 {
157 m_logFileAppender = (FileAppender)appender; 158 m_logFileAppender = (FileAppender)appender;
158 } 159 }
160 else if (appender.Name == "StatsLogFileAppender")
161 {
162 m_statsLogFileAppender = (FileAppender)appender;
163 }
159 } 164 }
160 165
161 if (null == m_consoleAppender) 166 if (null == m_consoleAppender)
@@ -166,11 +171,11 @@ namespace OpenSim.Framework.Servers
166 { 171 {
167 // FIXME: This should be done through an interface rather than casting. 172 // FIXME: This should be done through an interface rather than casting.
168 m_consoleAppender.Console = (ConsoleBase)m_console; 173 m_consoleAppender.Console = (ConsoleBase)m_console;
169 174
170 // If there is no threshold set then the threshold is effectively everything. 175 // If there is no threshold set then the threshold is effectively everything.
171 if (null == m_consoleAppender.Threshold) 176 if (null == m_consoleAppender.Threshold)
172 m_consoleAppender.Threshold = Level.All; 177 m_consoleAppender.Threshold = Level.All;
173 178
174 Notice(String.Format("Console log level is {0}", m_consoleAppender.Threshold)); 179 Notice(String.Format("Console log level is {0}", m_consoleAppender.Threshold));
175 } 180 }
176 181
@@ -185,6 +190,18 @@ namespace OpenSim.Framework.Servers
185 190
186 m_log.InfoFormat("[SERVER BASE]: Logging started to file {0}", m_logFileAppender.File); 191 m_log.InfoFormat("[SERVER BASE]: Logging started to file {0}", m_logFileAppender.File);
187 } 192 }
193
194 if (m_statsLogFileAppender != null && startupConfig != null)
195 {
196 string cfgStatsFileName = startupConfig.GetString("StatsLogFile", null);
197 if (cfgStatsFileName != null)
198 {
199 m_statsLogFileAppender.File = cfgStatsFileName;
200 m_statsLogFileAppender.ActivateOptions();
201 }
202
203 m_log.InfoFormat("[SERVER BASE]: Stats Logging started to file {0}", m_statsLogFileAppender.File);
204 }
188 } 205 }
189 206
190 /// <summary> 207 /// <summary>
@@ -205,11 +222,11 @@ namespace OpenSim.Framework.Servers
205 "General", false, "show uptime", "show uptime", "Show server uptime", HandleShow); 222 "General", false, "show uptime", "show uptime", "Show server uptime", HandleShow);
206 223
207 m_console.Commands.AddCommand( 224 m_console.Commands.AddCommand(
208 "General", false, "get log level", "get log level", "Get the current console logging level", 225 "General", false, "get log level", "get log level", "Get the current console logging level",
209 (mod, cmd) => ShowLogLevel()); 226 (mod, cmd) => ShowLogLevel());
210 227
211 m_console.Commands.AddCommand( 228 m_console.Commands.AddCommand(
212 "General", false, "set log level", "set log level <level>", 229 "General", false, "set log level", "set log level <level>",
213 "Set the console logging level for this session.", HandleSetLogLevel); 230 "Set the console logging level for this session.", HandleSetLogLevel);
214 231
215 m_console.Commands.AddCommand( 232 m_console.Commands.AddCommand(
@@ -222,14 +239,14 @@ namespace OpenSim.Framework.Servers
222 "config get [<section>] [<key>]", 239 "config get [<section>] [<key>]",
223 "Synonym for config show", 240 "Synonym for config show",
224 HandleConfig); 241 HandleConfig);
225 242
226 m_console.Commands.AddCommand( 243 m_console.Commands.AddCommand(
227 "General", false, "config show", 244 "General", false, "config show",
228 "config show [<section>] [<key>]", 245 "config show [<section>] [<key>]",
229 "Show config information", 246 "Show config information",
230 "If neither section nor field are specified, then the whole current configuration is printed." + Environment.NewLine 247 "If neither section nor field are specified, then the whole current configuration is printed." + Environment.NewLine
231 + "If a section is given but not a field, then all fields in that section are printed.", 248 + "If a section is given but not a field, then all fields in that section are printed.",
232 HandleConfig); 249 HandleConfig);
233 250
234 m_console.Commands.AddCommand( 251 m_console.Commands.AddCommand(
235 "General", false, "config save", 252 "General", false, "config save",
@@ -258,18 +275,6 @@ namespace OpenSim.Framework.Servers
258 (string module, string[] args) => Notice(GetThreadsReport())); 275 (string module, string[] args) => Notice(GetThreadsReport()));
259 276
260 m_console.Commands.AddCommand ( 277 m_console.Commands.AddCommand (
261 "Debug", false, "debug comms set",
262 "debug comms set serialosdreq true|false",
263 "Set comms parameters. For debug purposes.",
264 HandleDebugCommsSet);
265
266 m_console.Commands.AddCommand (
267 "Debug", false, "debug comms status",
268 "debug comms status",
269 "Show current debug comms parameters.",
270 HandleDebugCommsStatus);
271
272 m_console.Commands.AddCommand (
273 "Debug", false, "debug threadpool set", 278 "Debug", false, "debug threadpool set",
274 "debug threadpool set worker|iocp min|max <n>", 279 "debug threadpool set worker|iocp min|max <n>",
275 "Set threadpool parameters. For debug purposes.", 280 "Set threadpool parameters. For debug purposes.",
@@ -280,7 +285,7 @@ namespace OpenSim.Framework.Servers
280 "debug threadpool status", 285 "debug threadpool status",
281 "Show current debug threadpool parameters.", 286 "Show current debug threadpool parameters.",
282 HandleDebugThreadpoolStatus); 287 HandleDebugThreadpoolStatus);
283 288
284 m_console.Commands.AddCommand( 289 m_console.Commands.AddCommand(
285 "Debug", false, "debug threadpool level", 290 "Debug", false, "debug threadpool level",
286 "debug threadpool level 0.." + Util.MAX_THREADPOOL_LEVEL, 291 "debug threadpool level 0.." + Util.MAX_THREADPOOL_LEVEL,
@@ -326,47 +331,13 @@ namespace OpenSim.Framework.Servers
326 331
327 public void RegisterCommonComponents(IConfigSource configSource) 332 public void RegisterCommonComponents(IConfigSource configSource)
328 { 333 {
329 IConfig networkConfig = configSource.Configs["Network"]; 334// IConfig networkConfig = configSource.Configs["Network"];
330 335
331 if (networkConfig != null)
332 {
333 WebUtil.SerializeOSDRequestsPerEndpoint = networkConfig.GetBoolean("SerializeOSDRequests", false);
334 }
335
336 m_serverStatsCollector = new ServerStatsCollector(); 336 m_serverStatsCollector = new ServerStatsCollector();
337 m_serverStatsCollector.Initialise(configSource); 337 m_serverStatsCollector.Initialise(configSource);
338 m_serverStatsCollector.Start(); 338 m_serverStatsCollector.Start();
339 } 339 }
340 340
341 private void HandleDebugCommsStatus(string module, string[] args)
342 {
343 Notice("serialosdreq is {0}", WebUtil.SerializeOSDRequestsPerEndpoint);
344 }
345
346 private void HandleDebugCommsSet(string module, string[] args)
347 {
348 if (args.Length != 5)
349 {
350 Notice("Usage: debug comms set serialosdreq true|false");
351 return;
352 }
353
354 if (args[3] != "serialosdreq")
355 {
356 Notice("Usage: debug comms set serialosdreq true|false");
357 return;
358 }
359
360 bool setSerializeOsdRequests;
361
362 if (!ConsoleUtil.TryParseConsoleBool(m_console, args[4], out setSerializeOsdRequests))
363 return;
364
365 WebUtil.SerializeOSDRequestsPerEndpoint = setSerializeOsdRequests;
366
367 Notice("serialosdreq is now {0}", setSerializeOsdRequests);
368 }
369
370 private void HandleShowThreadpoolCallsActive(string module, string[] args) 341 private void HandleShowThreadpoolCallsActive(string module, string[] args)
371 { 342 {
372 List<KeyValuePair<string, int>> calls = Util.GetFireAndForgetCallsInProgress().ToList(); 343 List<KeyValuePair<string, int>> calls = Util.GetFireAndForgetCallsInProgress().ToList();
@@ -432,7 +403,7 @@ namespace OpenSim.Framework.Servers
432 403
433 ThreadPool.GetAvailableThreads(out workerThreads, out iocpThreads); 404 ThreadPool.GetAvailableThreads(out workerThreads, out iocpThreads);
434 Notice("Available worker threads: {0}", workerThreads); 405 Notice("Available worker threads: {0}", workerThreads);
435 Notice("Available IOCP threads: {0}", iocpThreads); 406 Notice("Available IOCP threads: {0}", iocpThreads);
436 } 407 }
437 408
438 private void HandleDebugThreadpoolSet(string module, string[] args) 409 private void HandleDebugThreadpoolSet(string module, string[] args)
@@ -488,7 +459,7 @@ namespace OpenSim.Framework.Servers
488 fail = true; 459 fail = true;
489 } 460 }
490 } 461 }
491 462
492 if (fail) 463 if (fail)
493 { 464 {
494 Notice("ERROR: Could not set {0} {1} threads to {2}", poolType, bound, newThreads); 465 Notice("ERROR: Could not set {0} {1} threads to {2}", poolType, bound, newThreads);
@@ -582,7 +553,7 @@ namespace OpenSim.Framework.Servers
582 if (cmdparams.Length > 0) 553 if (cmdparams.Length > 0)
583 { 554 {
584 string firstParam = cmdparams[0].ToLower(); 555 string firstParam = cmdparams[0].ToLower();
585 556
586 switch (firstParam) 557 switch (firstParam)
587 { 558 {
588 case "set": 559 case "set":
@@ -633,12 +604,12 @@ namespace OpenSim.Framework.Servers
633 { 604 {
634 Notice("[{0}]", config.Name); 605 Notice("[{0}]", config.Name);
635 foreach (string key in config.GetKeys()) 606 foreach (string key in config.GetKeys())
636 Notice(" {0} = {1}", key, config.GetString(key)); 607 Notice(" {0} = {1}", key, config.GetString(key));
637 } 608 }
638 else 609 else
639 { 610 {
640 Notice( 611 Notice(
641 "config get {0} {1} : {2}", 612 "config get {0} {1} : {2}",
642 cmdparams[1], cmdparams[2], config.GetString(cmdparams[2])); 613 cmdparams[1], cmdparams[2], config.GetString(cmdparams[2]));
643 } 614 }
644 } 615 }
@@ -692,10 +663,10 @@ namespace OpenSim.Framework.Servers
692 } 663 }
693 664
694 string rawLevel = cmd[3]; 665 string rawLevel = cmd[3];
695 666
696 ILoggerRepository repository = LogManager.GetRepository(); 667 ILoggerRepository repository = LogManager.GetRepository();
697 Level consoleLevel = repository.LevelMap[rawLevel]; 668 Level consoleLevel = repository.LevelMap[rawLevel];
698 669
699 if (consoleLevel != null) 670 if (consoleLevel != null)
700 m_consoleAppender.Threshold = consoleLevel; 671 m_consoleAppender.Threshold = consoleLevel;
701 else 672 else
@@ -770,9 +741,9 @@ namespace OpenSim.Framework.Servers
770 protected void ShowInfo() 741 protected void ShowInfo()
771 { 742 {
772 Notice(GetVersionText()); 743 Notice(GetVersionText());
773 Notice("Startup directory: " + m_startupDirectory); 744 Notice("Startup directory: " + m_startupDirectory);
774 if (null != m_consoleAppender) 745 if (null != m_consoleAppender)
775 Notice(String.Format("Console log level: {0}", m_consoleAppender.Threshold)); 746 Notice(String.Format("Console log level: {0}", m_consoleAppender.Threshold));
776 } 747 }
777 748
778 /// <summary> 749 /// <summary>
@@ -842,7 +813,7 @@ namespace OpenSim.Framework.Servers
842 { 813 {
843 StreamReader RevisionFile = File.OpenText(svnRevisionFileName); 814 StreamReader RevisionFile = File.OpenText(svnRevisionFileName);
844 buildVersion = RevisionFile.ReadLine(); 815 buildVersion = RevisionFile.ReadLine();
845 buildVersion.Trim(); 816 buildVersion = buildVersion.Trim();
846 RevisionFile.Close(); 817 RevisionFile.Close();
847 } 818 }
848 819
@@ -871,9 +842,9 @@ namespace OpenSim.Framework.Servers
871 } 842 }
872 } 843 }
873 844
874 protected string GetVersionText() 845 public string GetVersionText()
875 { 846 {
876 return String.Format("Version: {0} (SIMULATION/{1} - SIMULATION/{2})", 847 return String.Format("Version: {0} (SIMULATION/{1} - SIMULATION/{2})",
877 m_version, VersionInfo.SimulationServiceVersionSupportedMin, VersionInfo.SimulationServiceVersionSupportedMax); 848 m_version, VersionInfo.SimulationServiceVersionSupportedMin, VersionInfo.SimulationServiceVersionSupportedMax);
878 } 849 }
879 850
@@ -898,7 +869,7 @@ namespace OpenSim.Framework.Servers
898 foreach (Watchdog.ThreadWatchdogInfo twi in threads) 869 foreach (Watchdog.ThreadWatchdogInfo twi in threads)
899 { 870 {
900 Thread t = twi.Thread; 871 Thread t = twi.Thread;
901 872
902 sb.AppendFormat( 873 sb.AppendFormat(
903 reportFormat, 874 reportFormat,
904 t.ManagedThreadId, 875 t.ManagedThreadId,
@@ -911,16 +882,12 @@ namespace OpenSim.Framework.Servers
911 sb.Append("\n"); 882 sb.Append("\n");
912 } 883 }
913 884
914 sb.Append("\n"); 885 sb.Append(GetThreadPoolReport());
915 886
916 // For some reason mono 2.6.7 returns an empty threads set! Not going to confuse people by reporting 887 sb.Append("\n");
917 // zero active threads.
918 int totalThreads = Process.GetCurrentProcess().Threads.Count; 888 int totalThreads = Process.GetCurrentProcess().Threads.Count;
919 if (totalThreads > 0) 889 if (totalThreads > 0)
920 sb.AppendFormat("Total threads active: {0}\n\n", totalThreads); 890 sb.AppendFormat("Total process threads active: {0}\n\n", totalThreads);
921
922 sb.Append("Main threadpool (excluding script engine pools)\n");
923 sb.Append(GetThreadPoolReport());
924 891
925 return sb.ToString(); 892 return sb.ToString();
926 } 893 }
@@ -931,15 +898,46 @@ namespace OpenSim.Framework.Servers
931 /// <returns></returns> 898 /// <returns></returns>
932 public static string GetThreadPoolReport() 899 public static string GetThreadPoolReport()
933 { 900 {
901
902 StringBuilder sb = new StringBuilder();
903
904 // framework pool is alwasy active
905 int maxWorkers;
906 int minWorkers;
907 int curWorkers;
908 int maxComp;
909 int minComp;
910 int curComp;
911
912 try
913 {
914 ThreadPool.GetMaxThreads(out maxWorkers, out maxComp);
915 ThreadPool.GetMinThreads(out minWorkers, out minComp);
916 ThreadPool.GetAvailableThreads(out curWorkers, out curComp);
917 curWorkers = maxWorkers - curWorkers;
918 curComp = maxComp - curComp;
919
920 sb.Append("\nFramework main threadpool \n");
921 sb.AppendFormat("workers: {0} ({1} / {2})\n", curWorkers, maxWorkers, minWorkers);
922 sb.AppendFormat("Completion: {0} ({1} / {2})\n", curComp, maxComp, minComp);
923 }
924 catch { }
925
926 if (
927 Util.FireAndForgetMethod == FireAndForgetMethod.QueueUserWorkItem
928 || Util.FireAndForgetMethod == FireAndForgetMethod.UnsafeQueueUserWorkItem)
929 {
930 sb.AppendFormat("\nThread pool used: Framework main threadpool\n");
931 return sb.ToString();
932 }
933
934 string threadPoolUsed = null; 934 string threadPoolUsed = null;
935 int maxThreads = 0; 935 int maxThreads = 0;
936 int minThreads = 0; 936 int minThreads = 0;
937 int allocatedThreads = 0; 937 int allocatedThreads = 0;
938 int inUseThreads = 0; 938 int inUseThreads = 0;
939 int waitingCallbacks = 0; 939 int waitingCallbacks = 0;
940 int completionPortThreads = 0;
941 940
942 StringBuilder sb = new StringBuilder();
943 if (Util.FireAndForgetMethod == FireAndForgetMethod.SmartThreadPool) 941 if (Util.FireAndForgetMethod == FireAndForgetMethod.SmartThreadPool)
944 { 942 {
945 STPInfo stpi = Util.GetSmartThreadPoolInfo(); 943 STPInfo stpi = Util.GetSmartThreadPoolInfo();
@@ -955,22 +953,10 @@ namespace OpenSim.Framework.Servers
955 waitingCallbacks = stpi.WaitingCallbacks; 953 waitingCallbacks = stpi.WaitingCallbacks;
956 } 954 }
957 } 955 }
958 else if ( 956
959 Util.FireAndForgetMethod == FireAndForgetMethod.QueueUserWorkItem
960 || Util.FireAndForgetMethod == FireAndForgetMethod.UnsafeQueueUserWorkItem)
961 {
962 threadPoolUsed = "BuiltInThreadPool";
963 ThreadPool.GetMaxThreads(out maxThreads, out completionPortThreads);
964 ThreadPool.GetMinThreads(out minThreads, out completionPortThreads);
965 int availableThreads;
966 ThreadPool.GetAvailableThreads(out availableThreads, out completionPortThreads);
967 inUseThreads = maxThreads - availableThreads;
968 allocatedThreads = -1;
969 waitingCallbacks = -1;
970 }
971
972 if (threadPoolUsed != null) 957 if (threadPoolUsed != null)
973 { 958 {
959 sb.Append("\nThreadpool (excluding script engine pools)\n");
974 sb.AppendFormat("Thread pool used : {0}\n", threadPoolUsed); 960 sb.AppendFormat("Thread pool used : {0}\n", threadPoolUsed);
975 sb.AppendFormat("Max threads : {0}\n", maxThreads); 961 sb.AppendFormat("Max threads : {0}\n", maxThreads);
976 sb.AppendFormat("Min threads : {0}\n", minThreads); 962 sb.AppendFormat("Min threads : {0}\n", minThreads);
@@ -1005,7 +991,7 @@ namespace OpenSim.Framework.Servers
1005 MainConsole.Instance.OutputFormat("Aborted thread with id {0}", threadId); 991 MainConsole.Instance.OutputFormat("Aborted thread with id {0}", threadId);
1006 else 992 else
1007 MainConsole.Instance.OutputFormat("ERROR - Thread with id {0} not found in managed threads", threadId); 993 MainConsole.Instance.OutputFormat("ERROR - Thread with id {0} not found in managed threads", threadId);
1008 } 994 }
1009 995
1010 /// <summary> 996 /// <summary>
1011 /// Console output is only possible if a console has been established. 997 /// Console output is only possible if a console has been established.
@@ -1020,13 +1006,13 @@ namespace OpenSim.Framework.Servers
1020 m_console.Output(msg); 1006 m_console.Output(msg);
1021 } 1007 }
1022 } 1008 }
1023 1009
1024 /// <summary> 1010 /// <summary>
1025 /// Console output is only possible if a console has been established. 1011 /// Console output is only possible if a console has been established.
1026 /// That is something that cannot be determined within this class. So 1012 /// That is something that cannot be determined within this class. So
1027 /// all attempts to use the console MUST be verified. 1013 /// all attempts to use the console MUST be verified.
1028 /// </summary> 1014 /// </summary>
1029 /// <param name="format"></param> 1015 /// <param name="format"></param>
1030 /// <param name="components"></param> 1016 /// <param name="components"></param>
1031 protected void Notice(string format, params object[] components) 1017 protected void Notice(string format, params object[] components)
1032 { 1018 {