From c17810277533b360f319bd46eb6445f1c6bea11a Mon Sep 17 00:00:00 2001 From: Mag-nus Date: Wed, 31 Jan 2024 20:29:46 -0600 Subject: [PATCH 1/2] Enable LOH Compacting on forcegc Maybe this will help recover long running servers that go into GC sawtooth pattern --- Source/ACE.Server/Command/Handlers/DeveloperCommands.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Source/ACE.Server/Command/Handlers/DeveloperCommands.cs b/Source/ACE.Server/Command/Handlers/DeveloperCommands.cs index 2f7c1810ef..ec776a3030 100644 --- a/Source/ACE.Server/Command/Handlers/DeveloperCommands.cs +++ b/Source/ACE.Server/Command/Handlers/DeveloperCommands.cs @@ -2,8 +2,9 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; -using System.Threading.Tasks; using System.Numerics; +using System.Runtime; +using System.Threading.Tasks; using log4net; @@ -2212,6 +2213,10 @@ public static void HandleClearPhysicsCaches(Session session, params string[] par [CommandHandler("forcegc", AccessLevel.Developer, CommandHandlerFlag.None, 0, "Forces .NET Garbage Collection")] public static void HandleForceGC(Session session, params string[] parameters) { + // https://learn.microsoft.com/en-us/dotnet/standard/garbage-collection/fundamentals + // https://learn.microsoft.com/en-us/dotnet/api/system.runtime.gcsettings.largeobjectheapcompactionmode + GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce; + GC.Collect(); CommandHandlerHelper.WriteOutputInfo(session, ".NET Garbage Collection forced"); From bea1d76e8f7f0c35bb54c9dee28b4a7d248633cb Mon Sep 17 00:00:00 2001 From: Mag-nus Date: Fri, 2 Feb 2024 09:27:19 -0600 Subject: [PATCH 2/2] This should be good for master --- Source/ACE.Server/Command/Handlers/DeveloperCommands.cs | 8 +++++++- Source/ACE.Server/Program.cs | 9 ++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Source/ACE.Server/Command/Handlers/DeveloperCommands.cs b/Source/ACE.Server/Command/Handlers/DeveloperCommands.cs index ec776a3030..cad9e528d1 100644 --- a/Source/ACE.Server/Command/Handlers/DeveloperCommands.cs +++ b/Source/ACE.Server/Command/Handlers/DeveloperCommands.cs @@ -2212,6 +2212,12 @@ public static void HandleClearPhysicsCaches(Session session, params string[] par [CommandHandler("forcegc", AccessLevel.Developer, CommandHandlerFlag.None, 0, "Forces .NET Garbage Collection")] public static void HandleForceGC(Session session, params string[] parameters) + { + GC.Collect(); + } + + [CommandHandler("forcegc2", AccessLevel.Developer, CommandHandlerFlag.None, 0, "Forces .NET Garbage Collection with LOH Compact")] + public static void HandleForceGC2(Session session, params string[] parameters) { // https://learn.microsoft.com/en-us/dotnet/standard/garbage-collection/fundamentals // https://learn.microsoft.com/en-us/dotnet/api/system.runtime.gcsettings.largeobjectheapcompactionmode @@ -2219,7 +2225,7 @@ public static void HandleForceGC(Session session, params string[] parameters) GC.Collect(); - CommandHandlerHelper.WriteOutputInfo(session, ".NET Garbage Collection forced"); + CommandHandlerHelper.WriteOutputInfo(session, ".NET Garbage Collection forced with LOH Compact"); } [CommandHandler("auditobjectmaint", AccessLevel.Developer, CommandHandlerFlag.None, 0, "Iterates over physics objects to find leaks")] diff --git a/Source/ACE.Server/Program.cs b/Source/ACE.Server/Program.cs index c45dfd2eea..4224e0aa48 100644 --- a/Source/ACE.Server/Program.cs +++ b/Source/ACE.Server/Program.cs @@ -2,6 +2,7 @@ using System.Globalization; using System.IO; using System.Reflection; +using System.Runtime; using System.Runtime.InteropServices; using System.Threading; @@ -314,8 +315,14 @@ public static void Main(string[] args) // Free up memory before the server goes online. This can free up 6 GB+ on larger servers. log.Info("Forcing .net garbage collection..."); - for (int i = 0 ; i < 10 ; i++) + for (int i = 0; i < 10; i++) + { + // https://learn.microsoft.com/en-us/dotnet/standard/garbage-collection/fundamentals + // https://learn.microsoft.com/en-us/dotnet/api/system.runtime.gcsettings.largeobjectheapcompactionmode + GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce; + GC.Collect(); + } // This should be last log.Info("Initializing CommandManager...");