cleanups using getProperty(String, int)

This commit is contained in:
zzz
2009-01-10 22:34:07 +00:00
parent 60bd9803f0
commit bc54908a22
5 changed files with 25 additions and 160 deletions

View File

@ -117,12 +117,7 @@ public class LoadTestManager {
private int getConcurrency() { private int getConcurrency() {
if (!isEnabled(_context)) return 0; if (!isEnabled(_context)) return 0;
int rv = CONCURRENT_PEERS; int rv = _context.getProperty("router.loadTestConcurrency", CONCURRENT_PEERS);
try {
rv = Integer.parseInt(_context.getProperty("router.loadTestConcurrency", CONCURRENT_PEERS+""));
} catch (NumberFormatException nfe) {
rv = CONCURRENT_PEERS;
}
if (rv < 0) if (rv < 0)
rv = 0; rv = 0;
if (rv > 50) if (rv > 50)
@ -131,15 +126,7 @@ public class LoadTestManager {
} }
private int getPeerMessages() { private int getPeerMessages() {
String msgsPerPeer = _context.getProperty("router.loadTestMessagesPerPeer"); int rv = _context.getProperty("router.loadTestMessagesPerPeer", CONCURRENT_MESSAGES);
int rv = CONCURRENT_MESSAGES;
if (msgsPerPeer != null) {
try {
rv = Integer.parseInt(msgsPerPeer);
} catch (NumberFormatException nfe) {
rv = CONCURRENT_MESSAGES;
}
}
if (rv < 1) if (rv < 1)
rv = 1; rv = 1;
if (rv > 50) if (rv > 50)

View File

@ -190,14 +190,7 @@ class RouterThrottleImpl implements RouterThrottle {
} }
} }
int max = DEFAULT_MAX_TUNNELS; int max = _context.getProperty(PROP_MAX_TUNNELS, DEFAULT_MAX_TUNNELS);
String maxTunnels = _context.getProperty(PROP_MAX_TUNNELS);
if (maxTunnels != null) {
try {
max = Integer.parseInt(maxTunnels);
} catch (NumberFormatException nfe) {
}
}
if (numTunnels >= max) { if (numTunnels >= max) {
if (_log.shouldLog(Log.WARN)) if (_log.shouldLog(Log.WARN))
_log.warn("Refusing tunnel request since we are already participating in " _log.warn("Refusing tunnel request since we are already participating in "
@ -387,11 +380,7 @@ class RouterThrottleImpl implements RouterThrottle {
/** dont ever probabalistically throttle tunnels if we have less than this many */ /** dont ever probabalistically throttle tunnels if we have less than this many */
private int getMinThrottleTunnels() { private int getMinThrottleTunnels() {
try { return _context.getProperty("router.minThrottleTunnels", 1000);
return Integer.parseInt(_context.getProperty("router.minThrottleTunnels", "1000"));
} catch (NumberFormatException nfe) {
return 1000;
}
} }
private double getTunnelGrowthFactor() { private double getTunnelGrowthFactor() {

View File

@ -1101,22 +1101,7 @@ public class ProfileOrganizer {
* @return minimum number of peers to be placed in the 'fast' group * @return minimum number of peers to be placed in the 'fast' group
*/ */
protected int getMinimumFastPeers() { protected int getMinimumFastPeers() {
String val = _context.getProperty(PROP_MINIMUM_FAST_PEERS, ""+DEFAULT_MINIMUM_FAST_PEERS); return _context.getProperty(PROP_MINIMUM_FAST_PEERS, DEFAULT_MINIMUM_FAST_PEERS);
if (val != null) {
try {
int rv = Integer.parseInt(val);
if (_log.shouldLog(Log.DEBUG))
_log.debug("router context said " + PROP_MINIMUM_FAST_PEERS + '=' + val);
return rv;
} catch (NumberFormatException nfe) {
if (_log.shouldLog(Log.WARN))
_log.warn("Minimum fast peers improperly set in the router environment [" + val + "]", nfe);
}
}
if (_log.shouldLog(Log.DEBUG))
_log.debug("no config for " + PROP_MINIMUM_FAST_PEERS + ", using " + DEFAULT_MINIMUM_FAST_PEERS);
return DEFAULT_MINIMUM_FAST_PEERS;
} }
@ -1130,22 +1115,7 @@ public class ProfileOrganizer {
* @return minimum number of peers to be placed in the 'fast' group * @return minimum number of peers to be placed in the 'fast' group
*/ */
protected int getMinimumHighCapacityPeers() { protected int getMinimumHighCapacityPeers() {
String val = _context.getProperty(PROP_MINIMUM_HIGH_CAPACITY_PEERS, ""+DEFAULT_MINIMUM_HIGH_CAPACITY_PEERS); return _context.getProperty(PROP_MINIMUM_HIGH_CAPACITY_PEERS, DEFAULT_MINIMUM_HIGH_CAPACITY_PEERS);
if (val != null) {
try {
int rv = Integer.parseInt(val);
if (_log.shouldLog(Log.DEBUG))
_log.debug("router context said " + PROP_MINIMUM_HIGH_CAPACITY_PEERS + '=' + val);
return rv;
} catch (NumberFormatException nfe) {
if (_log.shouldLog(Log.WARN))
_log.warn("Minimum high capacity peers improperly set in the router environment [" + val + "]", nfe);
}
}
if (_log.shouldLog(Log.DEBUG))
_log.debug("no config for " + PROP_MINIMUM_HIGH_CAPACITY_PEERS + ", using " + DEFAULT_MINIMUM_HIGH_CAPACITY_PEERS);
return DEFAULT_MINIMUM_HIGH_CAPACITY_PEERS;
} }
private final static DecimalFormat _fmt = new DecimalFormat("###,##0.00", new DecimalFormatSymbols(Locale.UK)); private final static DecimalFormat _fmt = new DecimalFormat("###,##0.00", new DecimalFormatSymbols(Locale.UK));

View File

@ -154,55 +154,30 @@ public class FIFOBandwidthRefiller implements Runnable {
} }
private void updateInboundRate() { private void updateInboundRate() {
String inBwStr = _context.getProperty(PROP_INBOUND_BANDWIDTH); int in = _context.getProperty(PROP_INBOUND_BANDWIDTH, DEFAULT_INBOUND_BANDWIDTH);
if ( (inBwStr != null) && if (in != _inboundKBytesPerSecond) {
(inBwStr.trim().length() > 0) &&
(!(inBwStr.equals(String.valueOf(_inboundKBytesPerSecond)))) ) {
// bandwidth was specified *and* changed // bandwidth was specified *and* changed
try {
int in = Integer.parseInt(inBwStr);
if ( (in <= 0) || (in > MIN_INBOUND_BANDWIDTH) ) if ( (in <= 0) || (in > MIN_INBOUND_BANDWIDTH) )
_inboundKBytesPerSecond = in; _inboundKBytesPerSecond = in;
else else
_inboundKBytesPerSecond = MIN_INBOUND_BANDWIDTH; _inboundKBytesPerSecond = MIN_INBOUND_BANDWIDTH;
if (_log.shouldLog(Log.DEBUG)) if (_log.shouldLog(Log.DEBUG))
_log.debug("Updating inbound rate to " + _inboundKBytesPerSecond); _log.debug("Updating inbound rate to " + _inboundKBytesPerSecond);
} catch (NumberFormatException nfe) {
if (_log.shouldLog(Log.WARN))
_log.warn("Invalid inbound bandwidth limit [" + inBwStr
+ "], keeping as " + _inboundKBytesPerSecond);
}
} else {
if ( (inBwStr == null) && (_log.shouldLog(Log.DEBUG)) )
_log.debug("Inbound bandwidth limits not specified in the config via " + PROP_INBOUND_BANDWIDTH);
} }
if (_inboundKBytesPerSecond <= 0) if (_inboundKBytesPerSecond <= 0)
_inboundKBytesPerSecond = DEFAULT_INBOUND_BANDWIDTH; _inboundKBytesPerSecond = DEFAULT_INBOUND_BANDWIDTH;
} }
private void updateOutboundRate() { private void updateOutboundRate() {
String outBwStr = _context.getProperty(PROP_OUTBOUND_BANDWIDTH); int out = _context.getProperty(PROP_OUTBOUND_BANDWIDTH, DEFAULT_OUTBOUND_BANDWIDTH);
if (out != _outboundKBytesPerSecond) {
if ( (outBwStr != null) &&
(outBwStr.trim().length() > 0) &&
(!(outBwStr.equals(String.valueOf(_outboundKBytesPerSecond)))) ) {
// bandwidth was specified *and* changed // bandwidth was specified *and* changed
try {
int out = Integer.parseInt(outBwStr);
if ( (out <= 0) || (out >= MIN_OUTBOUND_BANDWIDTH) ) if ( (out <= 0) || (out >= MIN_OUTBOUND_BANDWIDTH) )
_outboundKBytesPerSecond = out; _outboundKBytesPerSecond = out;
else else
_outboundKBytesPerSecond = MIN_OUTBOUND_BANDWIDTH; _outboundKBytesPerSecond = MIN_OUTBOUND_BANDWIDTH;
if (_log.shouldLog(Log.DEBUG)) if (_log.shouldLog(Log.DEBUG))
_log.debug("Updating outbound rate to " + _outboundKBytesPerSecond); _log.debug("Updating outbound rate to " + _outboundKBytesPerSecond);
} catch (NumberFormatException nfe) {
if (_log.shouldLog(Log.WARN))
_log.warn("Invalid outbound bandwidth limit [" + outBwStr
+ "], keeping as " + _outboundKBytesPerSecond);
}
} else {
if ( (outBwStr == null) && (_log.shouldLog(Log.DEBUG)) )
_log.debug("Outbound bandwidth limits not specified in the config via " + PROP_OUTBOUND_BANDWIDTH);
} }
if (_outboundKBytesPerSecond <= 0) if (_outboundKBytesPerSecond <= 0)
@ -210,27 +185,15 @@ public class FIFOBandwidthRefiller implements Runnable {
} }
private void updateInboundBurstRate() { private void updateInboundBurstRate() {
String inBwStr = _context.getProperty(PROP_INBOUND_BURST_BANDWIDTH); int in = _context.getProperty(PROP_INBOUND_BURST_BANDWIDTH, DEFAULT_INBOUND_BURST_BANDWIDTH);
if ( (inBwStr != null) && if (in != _inboundBurstKBytesPerSecond) {
(inBwStr.trim().length() > 0) &&
(!(inBwStr.equals(String.valueOf(_inboundBurstKBytesPerSecond)))) ) {
// bandwidth was specified *and* changed // bandwidth was specified *and* changed
try {
int in = Integer.parseInt(inBwStr);
if ( (in <= 0) || (in >= _inboundKBytesPerSecond) ) if ( (in <= 0) || (in >= _inboundKBytesPerSecond) )
_inboundBurstKBytesPerSecond = in; _inboundBurstKBytesPerSecond = in;
else else
_inboundBurstKBytesPerSecond = _inboundKBytesPerSecond; _inboundBurstKBytesPerSecond = _inboundKBytesPerSecond;
if (_log.shouldLog(Log.DEBUG)) if (_log.shouldLog(Log.DEBUG))
_log.debug("Updating inbound burst rate to " + _inboundBurstKBytesPerSecond); _log.debug("Updating inbound burst rate to " + _inboundBurstKBytesPerSecond);
} catch (NumberFormatException nfe) {
if (_log.shouldLog(Log.WARN))
_log.warn("Invalid inbound bandwidth burst limit [" + inBwStr
+ "], keeping as " + _inboundBurstKBytesPerSecond);
}
} else {
if ( (inBwStr == null) && (_log.shouldLog(Log.DEBUG)) )
_log.debug("Inbound bandwidth burst limits not specified in the config via " + PROP_INBOUND_BURST_BANDWIDTH);
} }
if (_inboundBurstKBytesPerSecond <= 0) if (_inboundBurstKBytesPerSecond <= 0)
@ -239,28 +202,15 @@ public class FIFOBandwidthRefiller implements Runnable {
} }
private void updateOutboundBurstRate() { private void updateOutboundBurstRate() {
String outBwStr = _context.getProperty(PROP_OUTBOUND_BURST_BANDWIDTH); int out = _context.getProperty(PROP_OUTBOUND_BURST_BANDWIDTH, DEFAULT_OUTBOUND_BURST_BANDWIDTH);
if (out != _outboundBurstKBytesPerSecond) {
if ( (outBwStr != null) &&
(outBwStr.trim().length() > 0) &&
(!(outBwStr.equals(String.valueOf(_outboundBurstKBytesPerSecond)))) ) {
// bandwidth was specified *and* changed // bandwidth was specified *and* changed
try {
int out = Integer.parseInt(outBwStr);
if ( (out <= 0) || (out >= _outboundKBytesPerSecond) ) if ( (out <= 0) || (out >= _outboundKBytesPerSecond) )
_outboundBurstKBytesPerSecond = out; _outboundBurstKBytesPerSecond = out;
else else
_outboundBurstKBytesPerSecond = _outboundKBytesPerSecond; _outboundBurstKBytesPerSecond = _outboundKBytesPerSecond;
if (_log.shouldLog(Log.DEBUG)) if (_log.shouldLog(Log.DEBUG))
_log.debug("Updating outbound burst rate to " + _outboundBurstKBytesPerSecond); _log.debug("Updating outbound burst rate to " + _outboundBurstKBytesPerSecond);
} catch (NumberFormatException nfe) {
if (_log.shouldLog(Log.WARN))
_log.warn("Invalid outbound bandwidth burst limit [" + outBwStr
+ "], keeping as " + _outboundBurstKBytesPerSecond);
}
} else {
if ( (outBwStr == null) && (_log.shouldLog(Log.DEBUG)) )
_log.debug("Outbound bandwidth burst limits not specified in the config via " + PROP_OUTBOUND_BURST_BANDWIDTH);
} }
if (_outboundBurstKBytesPerSecond <= 0) if (_outboundBurstKBytesPerSecond <= 0)
@ -269,13 +219,10 @@ public class FIFOBandwidthRefiller implements Runnable {
} }
private void updateInboundPeak() { private void updateInboundPeak() {
String inBwStr = _context.getProperty(PROP_INBOUND_BANDWIDTH_PEAK); int in = _context.getProperty(PROP_INBOUND_BANDWIDTH_PEAK,
if ( (inBwStr != null) && DEFAULT_BURST_SECONDS * _inboundBurstKBytesPerSecond);
(inBwStr.trim().length() > 0) && if (in != _limiter.getInboundBurstBytes()) {
(!(inBwStr.equals(String.valueOf(_limiter.getInboundBurstBytes())))) ) {
// peak bw was specified *and* changed // peak bw was specified *and* changed
try {
int in = Integer.parseInt(inBwStr);
if (in >= MIN_INBOUND_BANDWIDTH_PEAK) { if (in >= MIN_INBOUND_BANDWIDTH_PEAK) {
if (in < _inboundBurstKBytesPerSecond) if (in < _inboundBurstKBytesPerSecond)
_limiter.setInboundBurstBytes(_inboundBurstKBytesPerSecond * 1024); _limiter.setInboundBurstBytes(_inboundBurstKBytesPerSecond * 1024);
@ -287,27 +234,13 @@ public class FIFOBandwidthRefiller implements Runnable {
else else
_limiter.setInboundBurstBytes(MIN_INBOUND_BANDWIDTH_PEAK * 1024); _limiter.setInboundBurstBytes(MIN_INBOUND_BANDWIDTH_PEAK * 1024);
} }
} catch (NumberFormatException nfe) {
if (_log.shouldLog(Log.WARN))
_log.warn("Invalid inbound bandwidth burst limit [" + inBwStr
+ "]");
_limiter.setInboundBurstBytes(DEFAULT_BURST_SECONDS * _inboundBurstKBytesPerSecond * 1024);
}
} else {
if (_log.shouldLog(Log.DEBUG))
_log.debug("Inbound bandwidth burst limits not specified in the config via "
+ PROP_INBOUND_BANDWIDTH_PEAK);
_limiter.setInboundBurstBytes(DEFAULT_BURST_SECONDS * _inboundBurstKBytesPerSecond * 1024);
} }
} }
private void updateOutboundPeak() { private void updateOutboundPeak() {
String inBwStr = _context.getProperty(PROP_OUTBOUND_BANDWIDTH_PEAK); int in = _context.getProperty(PROP_OUTBOUND_BANDWIDTH_PEAK,
if ( (inBwStr != null) && DEFAULT_BURST_SECONDS * _outboundBurstKBytesPerSecond);
(inBwStr.trim().length() > 0) && if (in != _limiter.getOutboundBurstBytes()) {
(!(inBwStr.equals(String.valueOf(_limiter.getOutboundBurstBytes())))) ) {
// peak bw was specified *and* changed // peak bw was specified *and* changed
try {
int in = Integer.parseInt(inBwStr);
if (in >= MIN_OUTBOUND_BANDWIDTH_PEAK) { if (in >= MIN_OUTBOUND_BANDWIDTH_PEAK) {
if (in < _outboundBurstKBytesPerSecond) if (in < _outboundBurstKBytesPerSecond)
_limiter.setOutboundBurstBytes(_outboundBurstKBytesPerSecond * 1024); _limiter.setOutboundBurstBytes(_outboundBurstKBytesPerSecond * 1024);
@ -319,17 +252,6 @@ public class FIFOBandwidthRefiller implements Runnable {
else else
_limiter.setOutboundBurstBytes(MIN_OUTBOUND_BANDWIDTH_PEAK * 1024); _limiter.setOutboundBurstBytes(MIN_OUTBOUND_BANDWIDTH_PEAK * 1024);
} }
} catch (NumberFormatException nfe) {
if (_log.shouldLog(Log.WARN))
_log.warn("Invalid outbound bandwidth burst limit [" + inBwStr
+ "]");
_limiter.setOutboundBurstBytes(DEFAULT_BURST_SECONDS * _outboundBurstKBytesPerSecond * 1024);
}
} else {
if (_log.shouldLog(Log.DEBUG))
_log.debug("Outbound bandwidth burst limits not specified in the config via "
+ PROP_OUTBOUND_BANDWIDTH_PEAK);
_limiter.setOutboundBurstBytes(DEFAULT_BURST_SECONDS * _outboundBurstKBytesPerSecond * 1024);
} }
} }

View File

@ -39,10 +39,10 @@ class BuildExecutor implements Runnable {
_context.statManager().createRateStat("tunnel.concurrentBuildsLagged", "How many builds are going at once when we reject further builds, due to job lag (period is lag)", "Tunnels", new long[] { 60*1000, 5*60*1000, 60*60*1000 }); _context.statManager().createRateStat("tunnel.concurrentBuildsLagged", "How many builds are going at once when we reject further builds, due to job lag (period is lag)", "Tunnels", new long[] { 60*1000, 5*60*1000, 60*60*1000 });
_context.statManager().createRateStat("tunnel.buildExploratoryExpire", "How often an exploratory tunnel times out during creation", "Tunnels", new long[] { 60*1000, 10*60*1000 }); _context.statManager().createRateStat("tunnel.buildExploratoryExpire", "How often an exploratory tunnel times out during creation", "Tunnels", new long[] { 60*1000, 10*60*1000 });
_context.statManager().createRateStat("tunnel.buildClientExpire", "How often a client tunnel times out during creation", "Tunnels", new long[] { 60*1000, 10*60*1000 }); _context.statManager().createRateStat("tunnel.buildClientExpire", "How often a client tunnel times out during creation", "Tunnels", new long[] { 60*1000, 10*60*1000 });
_context.statManager().createRateStat("tunnel.buildExploratorySuccess", "How often an exploratory tunnel is fully built", "Tunnels", new long[] { 60*1000, 10*60*1000 }); _context.statManager().createRateStat("tunnel.buildExploratorySuccess", "Response time for success", "Tunnels", new long[] { 60*1000, 10*60*1000 });
_context.statManager().createRateStat("tunnel.buildClientSuccess", "How often a client tunnel is fully built", "Tunnels", new long[] { 60*1000, 10*60*1000 }); _context.statManager().createRateStat("tunnel.buildClientSuccess", "Response time for success", "Tunnels", new long[] { 60*1000, 10*60*1000 });
_context.statManager().createRateStat("tunnel.buildExploratoryReject", "How often an exploratory tunnel is rejected", "Tunnels", new long[] { 60*1000, 10*60*1000 }); _context.statManager().createRateStat("tunnel.buildExploratoryReject", "Response time for rejection", "Tunnels", new long[] { 60*1000, 10*60*1000 });
_context.statManager().createRateStat("tunnel.buildClientReject", "How often a client tunnel is rejected", "Tunnels", new long[] { 60*1000, 10*60*1000 }); _context.statManager().createRateStat("tunnel.buildClientReject", "Response time for rejection", "Tunnels", new long[] { 60*1000, 10*60*1000 });
_context.statManager().createRateStat("tunnel.buildRequestTime", "How long it takes to build a tunnel request", "Tunnels", new long[] { 60*1000, 10*60*1000 }); _context.statManager().createRateStat("tunnel.buildRequestTime", "How long it takes to build a tunnel request", "Tunnels", new long[] { 60*1000, 10*60*1000 });
_context.statManager().createRateStat("tunnel.buildRequestZeroHopTime", "How long it takes to build a zero hop tunnel", "Tunnels", new long[] { 60*1000, 10*60*1000 }); _context.statManager().createRateStat("tunnel.buildRequestZeroHopTime", "How long it takes to build a zero hop tunnel", "Tunnels", new long[] { 60*1000, 10*60*1000 });
_context.statManager().createRateStat("tunnel.pendingRemaining", "How many inbound requests are pending after a pass (period is how long the pass takes)?", "Tunnels", new long[] { 60*1000, 10*60*1000 }); _context.statManager().createRateStat("tunnel.pendingRemaining", "How many inbound requests are pending after a pass (period is how long the pass takes)?", "Tunnels", new long[] { 60*1000, 10*60*1000 });
@ -71,10 +71,7 @@ class BuildExecutor implements Runnable {
int allowed = maxKBps / 6; // Max. 1 concurrent build per 6 KB/s outbound int allowed = maxKBps / 6; // Max. 1 concurrent build per 6 KB/s outbound
if (allowed < 2) allowed = 2; // Never choke below 2 builds (but congestion may) if (allowed < 2) allowed = 2; // Never choke below 2 builds (but congestion may)
if (allowed > 10) allowed = 10; // Never go beyond 10, that is uncharted territory (old limit was 5) if (allowed > 10) allowed = 10; // Never go beyond 10, that is uncharted territory (old limit was 5)
allowed = _context.getProperty("router.tunnelConcurrentBuilds", allowed);
String prop = _context.getProperty("router.tunnelConcurrentBuilds");
if (prop != null)
try { allowed = Integer.valueOf(prop).intValue(); } catch (NumberFormatException nfe) {}
List expired = null; List expired = null;
int concurrent = 0; int concurrent = 0;