Add GC call to seed node before we reach max memory

This commit is contained in:
Manfred Karrer 2016-07-25 16:20:12 +02:00
parent 1b102c6363
commit bcc4dfc839
2 changed files with 30 additions and 23 deletions

View File

@ -50,9 +50,9 @@ public class SeedNodesRepository {
// 3. Shut down the seed node
// 4. Rename the directory with your local onion address
// 5. Edit here your found onion address (new NodeAddress("YOUR_ONION.onion:8002")
new NodeAddress("rxdkppp3vicnbgqt.onion:8002"),
new NodeAddress("brmbf6mf67d2hlm4.onion:8002"),
new NodeAddress("mfla72c4igh5ta2t.onion:8002")
DevFlags.STRESS_TEST_MODE ? new NodeAddress("hlitt7z4bec4kdh4.onion:8002") : new NodeAddress("rxdkppp3vicnbgqt.onion:8002"),
DevFlags.STRESS_TEST_MODE ? new NodeAddress("hlitt7z4bec4kdh4.onion:8002") : new NodeAddress("brmbf6mf67d2hlm4.onion:8002"),
DevFlags.STRESS_TEST_MODE ? new NodeAddress("hlitt7z4bec4kdh4.onion:8002") : new NodeAddress("mfla72c4igh5ta2t.onion:8002")
);
// Addresses are used if the last digit of their port match the network id:

View File

@ -37,8 +37,8 @@ import static io.bitsquare.app.BitsquareEnvironment.*;
public class SeedNodeMain extends BitsquareExecutable {
private static final Logger log = LoggerFactory.getLogger(SeedNodeMain.class);
private static final long MAX_MEMORY_MB = 800;
private static final long CHECK_MEMORY_PERIOD_SEC = 60;
private static final long MAX_MEMORY_MB = 600;
private static final long CHECK_MEMORY_PERIOD_SEC = 10 * 60;
private SeedNode seedNode;
private volatile boolean stopped;
@ -89,31 +89,38 @@ public class SeedNodeMain extends BitsquareExecutable {
UserThread.runPeriodically(() -> {
Profiler.printSystemLoad(log);
if (!stopped && Profiler.getUsedMemoryInMB() > MAX_MEMORY_MB) {
stopped = true;
seedNode.gracefulShutDown(() -> {
try {
final String[] tokens = environment.getAppDataDir().split("_");
String logPath = "error_" + (tokens.length > 1 ? tokens[tokens.length - 2] : "") + ".log";
RestartUtil.restartApplication(logPath);
} catch (IOException e) {
log.error(e.toString());
e.printStackTrace();
} finally {
log.warn("Shutdown complete");
System.exit(0);
}
});
long usedMemoryInMB = Profiler.getUsedMemoryInMB();
if (!stopped) {
if (usedMemoryInMB > (MAX_MEMORY_MB - 100)) {
log.warn("We are over our memory warn limit and call the GC");
System.gc();
usedMemoryInMB = Profiler.getUsedMemoryInMB();
Profiler.printSystemLoad(log);
}
if (usedMemoryInMB > MAX_MEMORY_MB) {
stopped = true;
seedNode.gracefulShutDown(() -> {
try {
final String[] tokens = environment.getAppDataDir().split("_");
String logPath = "error_" + (tokens.length > 1 ? tokens[tokens.length - 2] : "") + ".log";
RestartUtil.restartApplication(logPath);
} catch (IOException e) {
log.error(e.toString());
e.printStackTrace();
} finally {
log.warn("Shutdown complete");
System.exit(0);
}
});
}
}
}, CHECK_MEMORY_PERIOD_SEC);
while (true) {
try {
Thread.sleep(Long.MAX_VALUE);
} catch (InterruptedException e) {
e.printStackTrace();
log.error(e.getMessage());
} catch (InterruptedException ignore) {
}
}
}