mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 09:52:23 +01:00
Improve GcUtil
Increase duration for autoReleaseMemory from 60 to 120 sec. Improve logging. Add print stack trace when in dev mode to show caller for debugging/tuning. Remove inefficient GC calls (based on test runs when no reduction occurred at those calls).
This commit is contained in:
parent
c559e6e044
commit
7b68686b28
@ -501,8 +501,6 @@ public class PersistenceManager<T extends PersistableEnvelope> {
|
||||
if (completeHandler != null) {
|
||||
UserThread.execute(completeHandler);
|
||||
}
|
||||
|
||||
GcUtil.maybeReleaseMemory();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,7 @@
|
||||
package bisq.common.util;
|
||||
|
||||
import bisq.common.UserThread;
|
||||
import bisq.common.app.DevEnv;
|
||||
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -47,18 +48,31 @@ public class GcUtil {
|
||||
* @param trigger Threshold for free memory in MB when we invoke the garbage collector
|
||||
*/
|
||||
private static void autoReleaseMemory(long trigger) {
|
||||
UserThread.runPeriodically(() -> maybeReleaseMemory(trigger), 60);
|
||||
UserThread.runPeriodically(() -> maybeReleaseMemory(trigger), 120);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param trigger Threshold for free memory in MB when we invoke the garbage collector
|
||||
*/
|
||||
private static void maybeReleaseMemory(long trigger) {
|
||||
long totalMemory = Runtime.getRuntime().totalMemory();
|
||||
if (totalMemory > trigger * 1024 * 1024) {
|
||||
log.info("Invoke garbage collector. Total memory: {} {} {}", Utilities.readableFileSize(totalMemory), totalMemory, trigger * 1024 * 1024);
|
||||
long ts = System.currentTimeMillis();
|
||||
long preGcMemory = Runtime.getRuntime().totalMemory();
|
||||
if (preGcMemory > trigger * 1024 * 1024) {
|
||||
System.gc();
|
||||
log.info("Total memory after gc() call: {}", Utilities.readableFileSize(Runtime.getRuntime().totalMemory()));
|
||||
long postGcMemory = Runtime.getRuntime().totalMemory();
|
||||
log.info("GC reduced memory by {}. Total memory before/after: {}/{}. Took {} ms.",
|
||||
Utilities.readableFileSize(preGcMemory - postGcMemory),
|
||||
Utilities.readableFileSize(preGcMemory),
|
||||
Utilities.readableFileSize(postGcMemory),
|
||||
System.currentTimeMillis() - ts);
|
||||
if (DevEnv.isDevMode()) {
|
||||
try {
|
||||
// To see from where we got called
|
||||
throw new RuntimeException("Dummy Exception for print stacktrace at maybeReleaseMemory");
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,6 @@ import bisq.core.dao.state.DaoStateService;
|
||||
import bisq.core.dao.state.model.blockchain.Block;
|
||||
|
||||
import bisq.common.app.DevEnv;
|
||||
import bisq.common.util.GcUtil;
|
||||
|
||||
import org.bitcoinj.core.Coin;
|
||||
|
||||
@ -119,7 +118,6 @@ public class BlockParser {
|
||||
blockHeight, duration);
|
||||
}
|
||||
|
||||
GcUtil.maybeReleaseMemory();
|
||||
return block;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user