java.lang.Object
net.i2p.router.RouterThrottleImpl
- All Implemented Interfaces:
RouterThrottle
Simple throttle that basically stops accepting messages or nontrivial requests if the jobQueue lag is too large.
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classReset status from starting up to not-starting up, in case we don't get a tunnel request soon after the 20 minutes is up.Field Summary
Modifier and TypeFieldDescriptionprivate doubleCached tunnel growth factor.private StringConfig value the cached growth factor was read from.private intCached processing time limit, in ms.private StringConfig value the cached processing time was read from.private intCached maximum tunnel count.private StringConfig value the cached max tunnels was read from.private intCached minimum tunnels before throttling, -1 if unset.private StringConfig value the cached minimum throttle tunnels was read from.private doubleCached test time growth factor.private StringConfig value the cached test time factor was read from.protected final RouterContextRouter context, used for the job queue, tunnel counts, bandwidth limits and rates.private final LogLogger for the throttle.private longTimestamp (ms) the message-delay average first crossed the threshold, or -1.private final longStartup time before the throttle may reject.private static doubleTuner override for the growth factor, -1 if unset.private static intTuner override for the processing time, -1 if unset.private static intTuner override for the reject exponent, -1 if unset.private StringTunnel status text for the reject log.private static final intDefault processing time limit, in ms.static final intThis is the estimated number of 1 KB tunnel messages that we'll see in 10 minute lifetime of an exploratory tunnel.private static final longDefault startup delay before rejecting.private static final doubleDefault tunnel growth factor.private static final doubleDefault test time growth factor.static intDefault maximum tunnels, adjusted by system speed and memory.private static final longArbitrary hard limit - if it's taking this long to get to a job, we're congested.private static final StringLog text for a bandwidth-limit rejection.private static final intAlso limited to 90% - see below.private static final longShortest reject startup delay allowed.private static final longHow long the 1-minute message-processing average must stay above the throttle threshold before we actually reject tunnel requests.private static final int= TrivialPreprocessor.PREPROCESSED_SIZE.private static final StringConfig key for the processing time limit.static final StringProperty name for the participating tunnel cap.private static final StringConfig key for the minimum tunnels before throttling.private static final StringConfig key for the reject startup delay.private static final StringConfig key for the tunnel growth factor.private static final StringConfig key for the test time growth factor.static final intTunnel acceptance.Constructor Summary
ConstructorsConstructorDescriptionRouterThrottleImpl(RouterContext context) Create a throttle and schedule the reset of the "starting up" tunnel status.Method Summary
Modifier and TypeMethodDescriptionprivate static final StringMark a string for extraction by xgettext and translation.booleanShould we accept any more data from the network for any sort of message, taking into account our current load, or should we simply slow down?intIf we should send a reject, return a nonzero reject code.private booleanallowTunnel(double bytesAllocated, int numTunnels) With bytesAllocated already accounted for across the numTunnels existing tunnels we have agreed to, can we handle another tunnel with our existing bandwidth?voidRestore normal throttling after a shutdown attempt.static intParticipating tunnel cap in force when the property is unset.The current tunnel status, translated if available.private intReturns the cached processing time limit.static intThe max processing time in effect, tuned value if set else config.private intReturns the cached maximum tunnel count.longThe average message processing delay.static intCalculate a floor for per-tunnel bandwidth allocation based on participating tunnel count and total outbound bandwidth share.private intDon't ever probabilistically throttle tunnels if we have less than this many.static intThe throttle rejection-curve exponent, tuned value if set else therouter.throttleRejectExponentconfig, clamped to the caller's [3,20] validity window.private doubleReturns the tunnel growth factor in effect.static doubleThe tunnel growth factor in effect, tuned value if set else config.longThe current tunnel lag.The current tunnel status message.private doubleReturns the test time growth factor in effect.static booleanisShuttingDown(RouterContext context) Whether the router is shutting down.static voidsetDefaultMaxTunnels(int val) Set the default tunnel cap, clamped to 500..20000.static voidsetMaxProcessingTime(int ms) Set the max processing time (called by Tuner).voidThrottle hard while the router attempts to shut down.static voidsetThrottleRejectExponent(int exp) Set the throttle rejection-curve exponent (called by Tuner).static voidsetTunnelGrowthFactor(double factor) Set the tunnel growth factor (called by Tuner).private voidRebuilds the tunnel status text for the reject log.voidsetTunnelStatus(String msg) The tunnel acceptance status message.static intThe highest rejection exponent the throttle applies.static intThe lowest rejection exponent the throttle applies.
Field Details
_context
Router context, used for the job queue, tunnel counts, bandwidth limits and rates._log
Logger for the throttle._tunnelStatus
Tunnel status text for the reject log._rejectStartupTime
private final long _rejectStartupTimeStartup time before the throttle may reject.JOB_LAG_LIMIT_NETWORK
private static final long JOB_LAG_LIMIT_NETWORKArbitrary hard limit - if it's taking this long to get to a job, we're congested.- See Also:
PROP_MAX_TUNNELS
Property name for the participating tunnel cap.- See Also:
defaultMaxTunnels
public static volatile int defaultMaxTunnelsDefault maximum tunnels, adjusted by system speed and memory.PROP_MAX_PROCESSINGTIME
Config key for the processing time limit.- See Also:
DEFAULT_REJECT_STARTUP_TIME
private static final long DEFAULT_REJECT_STARTUP_TIMEDefault startup delay before rejecting.- See Also:
MIN_REJECT_STARTUP_TIME
private static final long MIN_REJECT_STARTUP_TIMEShortest reject startup delay allowed.- See Also:
PROP_REJECT_STARTUP_TIME
Config key for the reject startup delay.- See Also:
PROP_MIN_THROTTLE_TUNNELS
Config key for the minimum tunnels before throttling.- See Also:
MSG_DELAY_SUSTAIN_MS
private static final long MSG_DELAY_SUSTAIN_MSHow long the 1-minute message-processing average must stay above the throttle threshold before we actually reject tunnel requests. Brief lag spikes (GC pauses, netdb churn, rebuild storms) that recover within this window must not trip throttling. 3 minutes > one 1-minute coalesce period, so the condition is confirmed across multiple samples.- See Also:
_msgDelayOverSince
private volatile long _msgDelayOverSinceTimestamp (ms) the message-delay average first crossed the threshold, or -1.DEFAULT_MAX_PROCESSINGTIME
private static final int DEFAULT_MAX_PROCESSINGTIMEDefault processing time limit, in ms.TUNNEL_ACCEPT
PREPROCESSED_SIZE
private static final int PREPROCESSED_SIZE= TrivialPreprocessor.PREPROCESSED_SIZE.- See Also:
DEFAULT_MESSAGES_PER_TUNNEL_ESTIMATE
public static final int DEFAULT_MESSAGES_PER_TUNNEL_ESTIMATEThis is the estimated number of 1 KB tunnel messages that we'll see in 10 minute lifetime of an exploratory tunnel. We use it as a baseline minimum for estimating tunnel bandwidth, if accepted.600 KB in 10 minutes equals ~4 KBps - increased from 200 for better bandwidth allocation per transit tunnel.
- See Also:
MIN_AVAILABLE_BPS
private static final int MIN_AVAILABLE_BPSAlso limited to 90% - see below.- See Also:
LIMIT_STR
Log text for a bandwidth-limit rejection.PROP_TUNNEL_GROWTH_FACTOR
Config key for the tunnel growth factor.- See Also:
PROP_TUNNEL_TEST_TIME_GROWTH_FACTOR
Config key for the test time growth factor.- See Also:
DEFAULT_TUNNEL_GROWTH_FACTOR
private static final double DEFAULT_TUNNEL_GROWTH_FACTORDefault tunnel growth factor.- See Also:
DEFAULT_TUNNEL_TEST_TIME_GROWTH_FACTOR
private static final double DEFAULT_TUNNEL_TEST_TIME_GROWTH_FACTORDefault test time growth factor.- See Also:
_tunedGrowthFactor
private static volatile double _tunedGrowthFactorTuner override for the growth factor, -1 if unset._cachedGrowthFactorProp
Config value the cached growth factor was read from._cachedGrowthFactor
private double _cachedGrowthFactorCached tunnel growth factor._cachedTestTimeGrowthFactorProp
Config value the cached test time factor was read from._cachedTestTimeGrowthFactor
private double _cachedTestTimeGrowthFactorCached test time growth factor._cachedMaxTunnelsProp
Config value the cached max tunnels was read from._cachedMaxTunnels
private int _cachedMaxTunnelsCached maximum tunnel count._cachedMaxProcessingTimeProp
Config value the cached processing time was read from._cachedMaxProcessingTime
private int _cachedMaxProcessingTimeCached processing time limit, in ms._cachedMinThrottleTunnelsProp
Config value the cached minimum throttle tunnels was read from._cachedMinThrottleTunnels
private int _cachedMinThrottleTunnelsCached minimum tunnels before throttling, -1 if unset._tunedMaxProcessingTime
private static volatile int _tunedMaxProcessingTimeTuner override for the processing time, -1 if unset._tunedThrottleRejectExponent
private static volatile int _tunedThrottleRejectExponentTuner override for the reject exponent, -1 if unset.
Constructor Details
RouterThrottleImpl
Create a throttle and schedule the reset of the "starting up" tunnel status.- Parameters:
context- the router context
Method Details
getDefaultMaxTunnels
public static int getDefaultMaxTunnels()Participating tunnel cap in force when the property is unset.- Returns:
- the default tunnel count
setDefaultMaxTunnels
public static void setDefaultMaxTunnels(int val) Set the default tunnel cap, clamped to 500..20000.- Parameters:
val- participating tunnels to use when the property is unset
acceptNetworkMessage
public boolean acceptNetworkMessage()Should we accept any more data from the network for any sort of message, taking into account our current load, or should we simply slow down?- Specified by:
acceptNetworkMessagein interfaceRouterThrottle- Returns:
- true to take more network traffic, false to hold off for a while
acceptTunnelRequest
public int acceptTunnelRequest()If we should send a reject, return a nonzero reject code. Anything that causes us to drop a request instead of rejecting it must go inBuildHandler.handleInboundRequest(), not here.- Specified by:
acceptTunnelRequestin interfaceRouterThrottle- Returns:
- 0 for accept or nonzero reject code
getMinBandwidthFloorPerTunnel
Calculate a floor for per-tunnel bandwidth allocation based on participating tunnel count and total outbound bandwidth share. This ensures a minimum allocation even when many tunnels are hosted.- Parameters:
ctx- the router context supplying bandwidth, share percentage and tunnel count- Returns:
- minimum bytes per second to allocate per tunnel
allowTunnel
private boolean allowTunnel(double bytesAllocated, int numTunnels) With bytesAllocated already accounted for across the numTunnels existing tunnels we have agreed to, can we handle another tunnel with our existing bandwidth?- Parameters:
bytesAllocated- bytes per second already allocated across the existing tunnelsnumTunnels- the number of participating tunnels we are in- Returns:
- true if another tunnel request should be allowed
getMinThrottleTunnels
private int getMinThrottleTunnels()Don't ever probabilistically throttle tunnels if we have less than this many.- Returns:
- the configured minimum, or two thirds of the maximum tunnel count when the property is unset or invalid
setTunnelGrowthFactor
public static void setTunnelGrowthFactor(double factor) Set the tunnel growth factor (called by Tuner).- Parameters:
factor- the tunnel growth factor
getTunnelGrowthFactorTuned
The tunnel growth factor in effect, tuned value if set else config.- Parameters:
ctx- the router context- Returns:
- the tunnel growth factor
getMaxTunnels
private int getMaxTunnels()Returns the cached maximum tunnel count.- Returns:
- the maximum tunnels
setMaxProcessingTime
public static void setMaxProcessingTime(int ms) Set the max processing time (called by Tuner).- Parameters:
ms- the max message processing time in milliseconds
getMaxProcessingTimeTuned
The max processing time in effect, tuned value if set else config.- Parameters:
ctx- the router context- Returns:
- the max message processing time in milliseconds
setThrottleRejectExponent
public static void setThrottleRejectExponent(int exp) Set the throttle rejection-curve exponent (called by Tuner).- Parameters:
exp- the rejection exponent in effect
getThrottleRejectExponent
The throttle rejection-curve exponent, tuned value if set else therouter.throttleRejectExponentconfig, clamped to the caller's [3,20] validity window.- Parameters:
ctx- the router context- Returns:
- the rejection exponent
throttleRejectExponentMin
public static int throttleRejectExponentMin()The lowest rejection exponent the throttle applies.Public because the auto-tuner declares a range for this exponent and must not propose a value the read path clamps away: the target lands back on the current value and the param reads as one that will not take effect.
- Returns:
- the lower end of the validity window
throttleRejectExponentMax
public static int throttleRejectExponentMax()The highest rejection exponent the throttle applies.- Returns:
- the upper end of the validity window
getMaxProcessingTime
private int getMaxProcessingTime()Returns the cached processing time limit.- Returns:
- the limit, in ms
getTunnelGrowthFactor
private double getTunnelGrowthFactor()Returns the tunnel growth factor in effect.- Returns:
- the growth factor
getTunnelTestTimeGrowthFactor
private double getTunnelTestTimeGrowthFactor()Returns the test time growth factor in effect.- Returns:
- the growth factor
getMessageDelay
public long getMessageDelay()The average message processing delay.- Specified by:
getMessageDelayin interfaceRouterThrottle- Returns:
- the message delay
getTunnelLag
public long getTunnelLag()The current tunnel lag.- Specified by:
getTunnelLagin interfaceRouterThrottle- Returns:
- the tunnel lag
getTunnelStatus
The current tunnel status message.- Specified by:
getTunnelStatusin interfaceRouterThrottle- Returns:
- the tunnel status
getLocalizedTunnelStatus
The current tunnel status, translated if available.- Specified by:
getLocalizedTunnelStatusin interfaceRouterThrottle- Returns:
- the localized tunnel status
setTunnelStatus
private void setTunnelStatus()Rebuilds the tunnel status text for the reject log.isShuttingDown
Whether the router is shutting down.- Parameters:
context- the router context- Returns:
- whether shutting down
setShutdownStatus
public void setShutdownStatus()Throttle hard while the router attempts to shut down.- Specified by:
setShutdownStatusin interfaceRouterThrottle
cancelShutdownStatus
public void cancelShutdownStatus()Restore normal throttling after a shutdown attempt.- Specified by:
cancelShutdownStatusin interfaceRouterThrottle
setTunnelStatus
The tunnel acceptance status message.- Specified by:
setTunnelStatusin interfaceRouterThrottle- Parameters:
msg- the status message
_x