Field Summary
Modifier and TypeFieldDescriptionprivate final RouterContextThe router context.private final RateStatRate stat for the failures.private longWhen we last agreed to a build request.private longWhen the history was last written.private longWhen a tunnel last failed.private longWhen we last rejected for bandwidth.private longWhen we last rejected for a critical reason.private longWhen we last rejected probabilistically.private longWhen we last rejected for a transient reason.private longWhen a tunnel last passed a test.private longWhen a build last timed out.private final AtomicLongBuild requests we agreed to, lifetime.private final AtomicLongTunnels that failed, lifetime.private final AtomicLongBuild requests we rejected, lifetime.private final AtomicLongBuilds that timed out, lifetime.private final LogLogger for the tunnel history.private final RateStatRate stat for the rejections.private static final longDenominator of the rejection rate decay.(package private) static final longHow often the lifetime counters decay, as a whole interval.private static final longNumerator of the rejection rate decay.private static final StringComment rule line of the history file.private static final StringThe platform line separator.(package private) static final long[]Rate periods for history tracking.static final intTunnel rejection due to excess bandwidth usage - used for most rejections even if not really for bandwidth.static final intTunnel rejection due to system failure - not currently used.static final intProbabalistic tunnel rejection due to a flood of requests - infrequent.static final intStreaming NACK - peer accepted tunnel but can't deliver data.static final intTunnel rejection due to temporary cpu/job/tunnel overload - rare.Constructor Summary
ConstructorsConstructorDescriptionTunnelHistory(RouterContext context, String statGroup) Creates the per-peer reject and fail rate stats.Method Summary
Modifier and TypeMethodDescriptionprivate static voidadd(StringBuilder buf, boolean addComments, String name, long val, String description) Appends one statistic to the history file.private static voidaddDate(StringBuilder buf, boolean addComments, String name, long val, String description) Appends the date line to the history file.voidCoalesce the rate statistics and periodically decay lifetime counters.private voiddecayCounter(AtomicLong counter, String name) Apply decay to a counter.voiddecayLifetimeCounters(long now) Apply the lifetime-counter decay if its interval has elapsed.doubleCalculate the ratio of accepted to total tunnel requests.Failure rate statistics for this peer.longWhen the peer last agreed to participate in a tunnel.longWhen the last tunnel the peer participated in failed.longWhen the peer last refused to participate in a tunnel complaining of bandwidth overload.longWhen the peer last refused to participate in a tunnel with level of critical.longWhen the peer last refused to participate in a tunnel probabalistically.longWhen the peer last refused to participate in a tunnel complaining of transient overload.longWhen the peer last passed a tunnel test.longWhen the peer last timed out without responding to a tunnel request.longTotal tunnels the peer has agreed to participate in.longTotal tunnels the peer has agreed to participate in that were later marked as failed prematurely.longTotal tunnels the peer has refused to participate in (does not include timeouts).longTotal tunnel builds to this peer that timed out without a response.private static final longgetLong(Properties props, String key) Reads a long property with a default of zero.Rejection rate statistics for this peer.voidCount a tunnel participation agreement and record its time.voidincrementFailed(int pct) Define this rate as the probability it really failed.voidincrementProcessed(int processedSuccessfully, int failedProcessing) Processed message counter; legacy method, no longer tracked.voidincrementRejected(int severity) Count a tunnel rejection at the given severity and record its time.voidRecord that a tunnel test through this peer succeeded.voidCount a tunnel build timeout (peer did not respond in time).voidload(Properties props) Restore the tunnel history fields from the given properties.voidstore(OutputStream out) Write the tunnel history to the stream, including comments.voidstore(OutputStream out, boolean addComments) Write the data from the profile to the stream.
Field Details
_context
The router context._log
Logger for the tunnel history._lifetimeAgreedTo
Build requests we agreed to, lifetime._lifetimeRejected
Build requests we rejected, lifetime._lifetimeTimedOut
Builds that timed out, lifetime._lastAgreedTo
private volatile long _lastAgreedToWhen we last agreed to a build request._lastRejectedCritical
private volatile long _lastRejectedCriticalWhen we last rejected for a critical reason._lastRejectedBandwidth
private volatile long _lastRejectedBandwidthWhen we last rejected for bandwidth._lastRejectedTransient
private volatile long _lastRejectedTransientWhen we last rejected for a transient reason._lastRejectedProbabalistic
private volatile long _lastRejectedProbabalisticWhen we last rejected probabilistically._lastTimedOut
private volatile long _lastTimedOutWhen a build last timed out._lifetimeFailed
Tunnels that failed, lifetime._lastFailed
private volatile long _lastFailedWhen a tunnel last failed._lastTestedSuccessfully
private volatile long _lastTestedSuccessfullyWhen a tunnel last passed a test._rejectRate
Rate stat for the rejections._failRate
Rate stat for the failures._lastCoalesce
private volatile long _lastCoalesceWhen the history was last written.RATES
static final long[] RATESRate periods for history tracking.TUNNEL_REJECT_PROBABALISTIC_REJECT
public static final int TUNNEL_REJECT_PROBABALISTIC_REJECTProbabalistic tunnel rejection due to a flood of requests - infrequent.- See Also:
TUNNEL_REJECT_TRANSIENT_OVERLOAD
public static final int TUNNEL_REJECT_TRANSIENT_OVERLOADTunnel rejection due to temporary cpu/job/tunnel overload - rare.- See Also:
TUNNEL_REJECT_BANDWIDTH
public static final int TUNNEL_REJECT_BANDWIDTHTunnel rejection due to excess bandwidth usage - used for most rejections even if not really for bandwidth.- See Also:
TUNNEL_REJECT_CRIT
public static final int TUNNEL_REJECT_CRITTunnel rejection due to system failure - not currently used.- See Also:
TUNNEL_REJECT_STREAMING_NACK
public static final int TUNNEL_REJECT_STREAMING_NACKStreaming NACK - peer accepted tunnel but can't deliver data.- See Also:
DECAY_INTERVAL_MS
static final long DECAY_INTERVAL_MSHow often the lifetime counters decay, as a whole interval.Eight hours, not fifteen minutes. At 3/4 per interval the shorter period made a peer forget its own record faster than it could accumulate one: 50 accepted builds fell to 16 within an hour and under 1 within four, so a *good* history decayed exactly as fast as a bad one. Eight hours gives a half-life near 19 hours, so an established record takes about 128 hours to fall to 1% and a peer's last few days of behaviour dominate its ratio.
- See Also:
DECAY_NUMERATOR
private static final long DECAY_NUMERATORNumerator of the rejection rate decay.- See Also:
DECAY_DENOMINATOR
private static final long DECAY_DENOMINATORDenominator of the rejection rate decay.- See Also:
NL
The platform line separator.HR
Constructor Details
TunnelHistory
Creates the per-peer reject and fail rate stats.- Parameters:
context- the router context this history is attached tostatGroup- the statistics group the rate stats are filed under
Method Details
getLifetimeAgreedTo
public long getLifetimeAgreedTo()Total tunnels the peer has agreed to participate in.- Returns:
- the count since the last decay, applied every 8 hours by
decayLifetimeCounters(long)
getLifetimeRejected
public long getLifetimeRejected()Total tunnels the peer has refused to participate in (does not include timeouts).- Returns:
- the count since the last decay, applied every 8 hours by
decayLifetimeCounters(long)
getLifetimeTimedOut
public long getLifetimeTimedOut()Total tunnel builds to this peer that timed out without a response.- Returns:
- the count since the last decay, applied every 8 hours by
decayLifetimeCounters(long)
getLifetimeFailed
public long getLifetimeFailed()Total tunnels the peer has agreed to participate in that were later marked as failed prematurely.- Returns:
- the count since the last decay, applied every 8 hours by
decayLifetimeCounters(long)
getLastAgreedTo
public long getLastAgreedTo()When the peer last agreed to participate in a tunnel.- Returns:
- milliseconds since the epoch, or 0 if the peer has never agreed
getLastRejectedCritical
public long getLastRejectedCritical()When the peer last refused to participate in a tunnel with level of critical.- Returns:
- milliseconds since the epoch, or 0 if the peer has never rejected at this severity
getLastRejectedBandwidth
public long getLastRejectedBandwidth()When the peer last refused to participate in a tunnel complaining of bandwidth overload.- Returns:
- milliseconds since the epoch, or 0 if the peer has never rejected at this severity
getLastRejectedTransient
public long getLastRejectedTransient()When the peer last refused to participate in a tunnel complaining of transient overload.- Returns:
- milliseconds since the epoch, or 0 if the peer has never rejected at this severity
getLastRejectedProbabalistic
public long getLastRejectedProbabalistic()When the peer last refused to participate in a tunnel probabalistically.- Returns:
- milliseconds since the epoch, or 0 if the peer has never rejected at this severity
getLastTimedOut
public long getLastTimedOut()When the peer last timed out without responding to a tunnel request.- Returns:
- milliseconds since the epoch, or 0 if the peer has never timed out
getLastFailed
public long getLastFailed()When the last tunnel the peer participated in failed.- Returns:
- milliseconds since the epoch, or 0 if no participating tunnel has failed
getLastTestedSuccessfully
public long getLastTestedSuccessfully()When the peer last passed a tunnel test.- Returns:
- milliseconds since the epoch, or 0 if the peer has never passed a tunnel test
incrementTestSucceeded
public void incrementTestSucceeded()Record that a tunnel test through this peer succeeded. This indicates the peer is actively participating in working tunnels.getAcceptanceRatio
public double getAcceptanceRatio()Calculate the ratio of accepted to total tunnel requests. Only explicit rejections are counted; timeouts are tracked separately viagetLifetimeTimedOut()and the time-windowedgetRejectionRate()RateStat.- Returns:
- ratio (0.0 to 1.0), or 1.0 if no data available
incrementProcessed
public void incrementProcessed(int processedSuccessfully, int failedProcessing) Processed message counter; legacy method, no longer tracked.- Parameters:
processedSuccessfully- the number of successfully processed messages, ignoredfailedProcessing- the number of messages that failed to process, ignored
incrementAgreedTo
public void incrementAgreedTo()Count a tunnel participation agreement and record its time.incrementRejected
public void incrementRejected(int severity) Count a tunnel rejection at the given severity and record its time.- Parameters:
severity- how much the peer doesnt want to participate in the tunnel (large == more severe)
incrementTimedOut
public void incrementTimedOut()Count a tunnel build timeout (peer did not respond in time). Timeouts are tracked separately from rejections because a peer that is slow to respond is different from a peer that actively refuses. Timeouts do NOT count towardgetLifetimeRejected()and therefore do not affectgetAcceptanceRatio().incrementFailed
public void incrementFailed(int pct) Define this rate as the probability it really failed.- Parameters:
pct- = probability * 100
getRejectionRate
Rejection rate statistics for this peer.- Returns:
- the rejection rate
getFailedRate
decayLifetimeCounters
public void decayLifetimeCounters(long now) Apply the lifetime-counter decay if its interval has elapsed.Deliberately does not coalesce the
RateStats. Those are folded bycoalesceStats()on the caller's own cadence, and folding them again here would advance their windows twice as often as the statistic's consumers expect. A caller that only wants the decay — the tier reorganise walking every candidate — can call this cheaply: one volatile read and one comparison, with real work only on the pass that actually crosses the interval.Must be called with the write lock held when called from the reorganise, so the tier membership being read and the counters being decayed are consistent.
- Parameters:
now- current time in ms
coalesceStats
public void coalesceStats()Coalesce the rate statistics and periodically decay lifetime counters.Lifetime counters (
_lifetimeAgreedTo,_lifetimeRejected,_lifetimeTimedOut,_lifetimeFailed) are decayed at 75% per 8 hours (matchingDBHistory). This prevents unbounded growth across restarts and ensures stale history does not permanently block peers from tiers. Recency is handled by the RateStats (10-minute and 1-hour windows) and by selection gates.decayCounter
Apply decay to a counter. 3/4 per 8 h = ~1% after 128 hours.- Parameters:
counter- the lifetime counter to scale down, left alone when already zeroname- the counter's name, for the debug log
store
Write the tunnel history to the stream, including comments.- Parameters:
out- the stream to write the properties-formatted history to- Throws:
IOException- if the stream rejects a write
store
Write the data from the profile to the stream.- Parameters:
out- the stream to write the properties-formatted history toaddComments- add comment lines to the output- Throws:
IOException- if the stream rejects a write
addDate
private static void addDate(StringBuilder buf, boolean addComments, String name, long val, String description) Appends the date line to the history file.- Parameters:
buf- where the line is appendedaddComments- true to write the line as a commentname- the statistic nameval- the statistic value, used as the datedescription- the text shown before the date
add
private static void add(StringBuilder buf, boolean addComments, String name, long val, String description) Appends one statistic to the history file.- Parameters:
buf- where the line is appendedaddComments- true to write the line as a commentname- the statistic nameval- the statistic valuedescription- the text shown with the value
load
Restore the tunnel history fields from the given properties.- Parameters:
props- the persisted properties previously written bystore(OutputStream, boolean)
getLong
Reads a long property with a default of zero.- Parameters:
props- the properties readkey- the property name- Returns:
- the value, zero if unparseable