Skip to content

Commit

Permalink
Update PR
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
abraunegg committed Jun 12, 2024
1 parent 66a83e6 commit efc9d60
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 19 deletions.
26 changes: 9 additions & 17 deletions src/curlEngine.d
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -238,6 +224,8 @@ class CurlEngine {
}
// Perform Garbage Collection
GC.collect();
// Return free memory to the OS
GC.minimize();
}

// Initialise this curl instance
Expand Down Expand Up @@ -491,6 +479,8 @@ class CurlEngine {
}
// Perform Garbage Collection
GC.collect();
// Return free memory to the OS
GC.minimize();
}
}

Expand Down Expand Up @@ -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"]);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main.d
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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.");
Expand Down
4 changes: 4 additions & 0 deletions src/util.d
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit efc9d60

Please sign in to comment.