From efc9d60d0c80f90405344546b23131435830db84 Mon Sep 17 00:00:00 2001 From: abraunegg Date: Thu, 13 Jun 2024 05:16:55 +1000 Subject: [PATCH] Update PR * Use 'checkpoint' to merge WAL rather than 'vacuum' when completing a monitor loop, only use 'vacuum' at exit * Reset default thread pool to config value * Add missing GC.minimize --- src/curlEngine.d | 26 +++++++++----------------- src/main.d | 4 ++-- src/util.d | 4 ++++ 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/src/curlEngine.d b/src/curlEngine.d index d5c1d0f02..613630c55 100644 --- a/src/curlEngine.d +++ b/src/curlEngine.d @@ -193,35 +193,21 @@ class CurlEngine { if (uploadFile.isOpen()) { uploadFile.close(); } - // Is 'response' cleared? object.destroy(response); // Destroy, then set to null response = null; - // Is the actual http instance is stopped? if (!http.isStopped) { - // HTTP instance was not stopped .. but it should have been .. - if (exitHandlerTriggered) { - // Regardless of what we do here, if we are shutting down because of SIGINT (CTRL-C) and SIGTERM (kill) - addLogEntry("Due to a termination signal, a curl engine was potentially not shutdown in a safe manner.", ["debug"]); - // What engine is still active? - addLogEntry("Destructor HTTP instance still active: " ~ to!string(internalThreadId), ["debug"]); - // This will cause some sort of memory corruption somewhere .. - addLogEntry("Destructor HTTP instance isStopped state before http.shutdown(): " ~ to!string(http.isStopped), ["debug"]); - http.shutdown(); - addLogEntry("Destructor HTTP instance isStopped state post http.shutdown(): " ~ to!string(http.isStopped), ["debug"]); - } + http.shutdown(); } - // Make sure this HTTP instance is destroyed object.destroy(http); - addLogEntry("Destructor HTTP instance shutdown and destroyed: " ~ to!string(internalThreadId), ["debug"]); - // ThreadId needs to be set to null internalThreadId = null; - // Perform Garbage Collection GC.collect(); + // Return free memory to the OS + GC.minimize(); } // We are releasing a curl instance back to the pool @@ -238,6 +224,8 @@ class CurlEngine { } // Perform Garbage Collection GC.collect(); + // Return free memory to the OS + GC.minimize(); } // Initialise this curl instance @@ -491,6 +479,8 @@ class CurlEngine { } // Perform Garbage Collection GC.collect(); + // Return free memory to the OS + GC.minimize(); } } @@ -558,6 +548,8 @@ void releaseAllCurlInstances() { } // Perform Garbage Collection on the destroyed curl engines GC.collect(); + // Return free memory to the OS + GC.minimize(); // Log that all curl engines have been released addLogEntry("CurlEngine releaseAllCurlInstances() completed", ["debug"]); } diff --git a/src/main.d b/src/main.d index 77f80beeb..16549dcb0 100644 --- a/src/main.d +++ b/src/main.d @@ -655,7 +655,7 @@ int main(string[] cliArgs) { checkForNoMountScenario(); // Set the default thread pool value - defaultPoolThreads(1); + defaultPoolThreads(to!int(appConfig.getValueLong("threads"))); // Is the sync engine initialised correctly? if (appConfig.syncEngineWasInitialised) { @@ -1017,7 +1017,7 @@ int main(string[] cliArgs) { // Write WAL and SHM data to file for this loop and release memory used by in-memory processing addLogEntry("Merge contents of WAL and SHM files into main database file", ["debug"]); - itemDB.performVacuum(); + itemDB.performCheckpoint(); } else { // Not online addLogEntry("Microsoft OneDrive service is not reachable at this time. Will re-try on next sync attempt."); diff --git a/src/util.d b/src/util.d index cf05813ab..f5b584a48 100644 --- a/src/util.d +++ b/src/util.d @@ -229,6 +229,8 @@ bool testInternetReachability(ApplicationConfig appConfig) { object.destroy(http); // Perform Garbage Collection GC.collect(); + // Return free memory to the OS + GC.minimize(); } // Execute the request and handle exceptions @@ -705,6 +707,8 @@ JSONValue fetchOnlineURLContent(string url) { object.destroy(http); // Perform Garbage Collection GC.collect(); + // Return free memory to the OS + GC.minimize(); } // Configure the URL to access