Move 'maxMemory' option handling to Config

Note that the default value of 600 advertised in BisqExecutable's option
handling was incorrect. The actual value had since become 1200 MB. This
correct default is now reflected in Config's option handling.
This commit is contained in:
Chris Beams 2019-12-13 06:41:38 +01:00
parent 6a20013c77
commit 849bd7c286
No known key found for this signature in database
GPG Key ID: 3D214F8F5BC5ED73
7 changed files with 17 additions and 24 deletions

View File

@ -68,6 +68,7 @@ public class Config {
private final boolean useDevMode;
private final boolean useDevPrivilegeKeys;
private final boolean dumpStatistics;
private final int maxMemory;
// properties derived from cli options, but not exposed as cli options themselves
private boolean localBitcoinNodeIsRunning = false; // FIXME: eliminate mutable state
@ -218,6 +219,11 @@ public class Config {
.ofType(boolean.class)
.defaultsTo(false);
ArgumentAcceptingOptionSpec<Integer> maxMemoryOpt =
parser.accepts("maxMemory", "Max. permitted memory (used only by headless versions)")
.withRequiredArg()
.ofType(int.class)
.defaultsTo(1200);
try {
OptionSet cliOpts = parser.parse(args);
@ -273,6 +279,7 @@ public class Config {
this.useDevMode = options.valueOf(useDevModeOpt);
this.useDevPrivilegeKeys = options.valueOf(useDevPrivilegeKeysOpt);
this.dumpStatistics = options.valueOf(dumpStatisticsOpt);
this.maxMemory = options.valueOf(maxMemoryOpt);
} catch (OptionException ex) {
throw new ConfigException(format("problem parsing option '%s': %s",
ex.options().get(0),
@ -432,4 +439,8 @@ public class Config {
public boolean isDumpStatistics() {
return dumpStatistics;
}
public int getMaxMemory() {
return maxMemory;
}
}

View File

@ -19,6 +19,5 @@ package bisq.core.app;
public class AppOptionKeys {
public static final String PROVIDERS = "providers";
public static final String MAX_MEMORY = "maxMemory";
public static final String IGNORE_DEV_MSG_KEY = "ignoreDevMsg";
}

View File

@ -26,6 +26,7 @@ import bisq.network.p2p.network.ConnectionConfig;
import bisq.common.BisqException;
import bisq.common.CommonOptionKeys;
import bisq.common.config.BaseCurrencyNetwork;
import bisq.common.config.Config;
import org.springframework.core.env.JOptCommandLinePropertySource;
import org.springframework.core.env.MutablePropertySources;
@ -71,7 +72,7 @@ public class BisqEnvironment extends StandardEnvironment {
protected final String btcNodes, seedNodes, ignoreDevMsg, useTorForBtc, rpcUser, rpcPassword,
rpcHost, rpcPort, rpcBlockNotificationPort, rpcBlockNotificationHost, dumpBlockchainData, fullDaoNode,
banList, maxMemory, socks5ProxyBtcAddress,
banList, socks5ProxyBtcAddress,
torRcFile, torRcOptions, externalTorControlPort, externalTorPassword, externalTorCookieFile,
socks5ProxyHttpAddress, useAllProvidedNodes, numConnectionForBtc, genesisTxId, genesisBlockHeight, genesisTotalSupply,
daoActivated, msgThrottlePerSec, msgThrottlePer10Sec, sendMsgThrottleTrigger, sendMsgThrottleSleep;
@ -93,7 +94,6 @@ public class BisqEnvironment extends StandardEnvironment {
//AppOptionKeys
ignoreDevMsg = getProperty(commandLineProperties, AppOptionKeys.IGNORE_DEV_MSG_KEY, "");
maxMemory = getProperty(commandLineProperties, AppOptionKeys.MAX_MEMORY, "");
providers = getProperty(commandLineProperties, AppOptionKeys.PROVIDERS, "");
//NetworkOptionKeys
@ -177,7 +177,6 @@ public class BisqEnvironment extends StandardEnvironment {
setProperty(NetworkOptionKeys.SEND_MSG_THROTTLE_SLEEP, sendMsgThrottleSleep);
setProperty(AppOptionKeys.IGNORE_DEV_MSG_KEY, ignoreDevMsg);
setProperty(AppOptionKeys.MAX_MEMORY, maxMemory);
setProperty(AppOptionKeys.PROVIDERS, providers);
setProperty(DaoOptionKeys.RPC_USER, rpcUser);

View File

@ -382,10 +382,6 @@ public abstract class BisqExecutable implements GracefulShutDownHandler, BisqSet
.ofType(int.class);
//AppOptionKeys
parser.accepts(AppOptionKeys.MAX_MEMORY,
format("Max. permitted memory (used only at headless versions) (default: %s)", "600"))
.withRequiredArg();
parser.accepts(AppOptionKeys.IGNORE_DEV_MSG_KEY,
format("If set to true all signed network_messages from bisq developers are ignored " +
"(Global alert, Version update alert, Filters for offers, nodes or trading account data) (default: %s)", "false"))

View File

@ -17,8 +17,6 @@
package bisq.core.app.misc;
import bisq.core.app.AppOptionKeys;
import bisq.core.app.BisqEnvironment;
import bisq.core.app.BisqExecutable;
import bisq.core.btc.setup.WalletsSetup;
import bisq.core.btc.wallet.BsqWalletService;
@ -48,13 +46,11 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j
public abstract class ExecutableForAppWithP2p extends BisqExecutable implements UncaughtExceptionHandler {
private static final long MAX_MEMORY_MB_DEFAULT = 1200;
private static final long CHECK_MEMORY_PERIOD_SEC = 300;
private static final long CHECK_SHUTDOWN_SEC = TimeUnit.HOURS.toSeconds(1);
private static final long SHUTDOWN_INTERVAL = TimeUnit.HOURS.toMillis(24);
private volatile boolean stopped;
private final long startTime = System.currentTimeMillis();
private static long maxMemory = MAX_MEMORY_MB_DEFAULT;
public ExecutableForAppWithP2p(String fullName, String scriptName, String appName, String version) {
super(fullName, scriptName, appName, version);
@ -139,16 +135,8 @@ public abstract class ExecutableForAppWithP2p extends BisqExecutable implements
}, CHECK_SHUTDOWN_SEC);
}
protected void checkMemory(BisqEnvironment environment, GracefulShutDownHandler gracefulShutDownHandler) {
String maxMemoryOption = environment.getProperty(AppOptionKeys.MAX_MEMORY);
if (maxMemoryOption != null && !maxMemoryOption.isEmpty()) {
try {
maxMemory = Integer.parseInt(maxMemoryOption);
} catch (Throwable t) {
log.error(t.getMessage());
}
}
protected void checkMemory(Config config, GracefulShutDownHandler gracefulShutDownHandler) {
int maxMemory = config.getMaxMemory();
UserThread.runPeriodically(() -> {
Profiler.printSystemLoad(log);
if (!stopped) {

View File

@ -50,7 +50,7 @@ public class SeedNodeMain extends ExecutableForAppWithP2p {
protected void doExecute(OptionSet options) {
super.doExecute(options);
checkMemory(bisqEnvironment, this);
checkMemory(config, this);
startShutDownInterval(this);
CommonSetup.setup(this);

View File

@ -47,7 +47,7 @@ public class StatisticsMain extends ExecutableForAppWithP2p {
protected void doExecute(OptionSet options) {
super.doExecute(options);
checkMemory(bisqEnvironment, this);
checkMemory(config, this);
CommonSetup.setup(this);
keepRunning();