java.lang.Object
net.i2p.router.JobStats
Collects and maintains statistical data for job execution performance. Tracks run counts, execution times, drop rates, and pending time metrics for job queue monitoring and optimization. Public for router console only. For use by the router only. Not to be used by applications or plugins.
Nested Class Summary
Modifier and TypeClassDescriptionprivate static classOne recorded recent execution.static classTotals over the most recent runs of one job type.Field Summary
FieldsModifier and TypeFieldDescriptionprivate final StringThe name of the job being tracked.private longWhen the job last ran.private longLongest pending time so far, in ms.private final intRecent executions this job keeps.private longLongest run so far, in ms.private longShortest pending time so far, in ms.private longShortest run so far, in ms.private final AtomicLongRuns of the job dropped.private final AtomicLongRuns of the job counted.private final AtomicIntegerRecent executions recorded so far.private final JobStats.RecentExecution[]Ring holding the recent executions.private intWrite index into the recent ring.private final AtomicLongTotal time spent pending, in ms.private final AtomicLongTotal run time, in ms.private static final intRecent executions kept for a normal job.Jobs whose recent window is enlarged.private static final intRecent executions kept for a high frequency job.private static longWhen a viewer last requested the tracking.private static final longTime window covered by the recent executions.private static booleanTrue while recent executions are recorded.private static final longTime tracking stays on after the last viewer.Constructor Summary
Method Summary
Modifier and TypeMethodDescriptionstatic voidForce disable recent tracking immediately.static voidEnable recent execution tracking for a period of time.doubleAverage pending/wait time for this job type.doubleAverage execution time for this job type.longNumber of jobs that were dropped.longTime of the last run.longMaximum pending/wait time for a single run of this job type.intMaximum number of recent execution entries tracked.longMaximum execution time for a single run of this job type.longMinimum pending/wait time for a single run of this job type.longMinimum execution time for a single run of this job type.getName()Name of this job type.Summarise the executions that fell inside the recent tracking window.longgetRuns()Total number of times this job type has run.longTotal pending/wait time for all runs of this job type.longTotal execution time for all runs of this job type.static booleanCheck if recent tracking should be active.voidRecord that a job of this type was dropped due to overload.voidjobRan(long runTime, long lag) Record that a job of this type has executed.
Field Details
_job
The name of the job being tracked._numRuns
Runs of the job counted._numDropped
Runs of the job dropped._totalTime
Total run time, in ms._maxTime
private volatile long _maxTimeLongest run so far, in ms._minTime
private volatile long _minTimeShortest run so far, in ms._totalPendingTime
Total time spent pending, in ms._maxPendingTime
private volatile long _maxPendingTimeLongest pending time so far, in ms._minPendingTime
private volatile long _minPendingTimeShortest pending time so far, in ms._lastRunTime
private volatile long _lastRunTimeWhen the job last ran.DEFAULT_MAX_RECENT_ENTRIES
private static final int DEFAULT_MAX_RECENT_ENTRIESRecent executions kept for a normal job.- See Also:
HIGH_FREQ_MAX_RECENT_ENTRIES
private static final int HIGH_FREQ_MAX_RECENT_ENTRIESRecent executions kept for a high frequency job.- See Also:
HIGH_FREQ_JOBS
RECENT_WINDOW_MS
private static final long RECENT_WINDOW_MSTime window covered by the recent executions.- See Also:
recentTrackingEnabled
private static volatile boolean recentTrackingEnabledTrue while recent executions are recorded.lastTrackingEnableTime
private static volatile long lastTrackingEnableTimeWhen a viewer last requested the tracking.TRACKING_TIMEOUT_MS
private static final long TRACKING_TIMEOUT_MSTime tracking stays on after the last viewer.- See Also:
_maxRecentEntries
private final int _maxRecentEntriesRecent executions this job keeps._recentExecutions
Ring holding the recent executions._recentIndex
private volatile int _recentIndexWrite index into the recent ring._recentCount
Recent executions recorded so far.
Constructor Details
JobStats
Create statistics tracker for a named job type.- Parameters:
name- the job type being tracked; names inHIGH_FREQ_JOBSget a larger recent-execution window
Method Details
enableRecentTracking
public static void enableRecentTracking()Enable recent execution tracking for a period of time. Call this when rendering the /jobs page. Tracking will remain enabled for 60 seconds after last enable.isRecentTrackingEnabled
public static boolean isRecentTrackingEnabled()Check if recent tracking should be active. Returns true if enabled and within timeout period.- Returns:
- whether recent tracking enabled
disableRecentTracking
public static void disableRecentTracking()Force disable recent tracking immediately.jobRan
public void jobRan(long runTime, long lag) Record that a job of this type has executed.- Parameters:
runTime- the time in milliseconds the job took to executelag- the time in milliseconds the job spent waiting in the queue
getLastRunTime
public long getLastRunTime()Time of the last run.- Returns:
- the start time of the last run in milliseconds since the epoch, or 0 if the job has never run
jobDropped
public void jobDropped()Record that a job of this type was dropped due to overload.getDropped
public long getDropped()Number of jobs that were dropped.- Returns:
- the count of dropped jobs
getName
getMaxRecentEntries
public int getMaxRecentEntries()Maximum number of recent execution entries tracked.- Returns:
- the max recent entries limit
getRuns
public long getRuns()Total number of times this job type has run.- Returns:
- the run count
getTotalTime
public long getTotalTime()Total execution time for all runs of this job type.- Returns:
- total time in milliseconds
getMaxTime
public long getMaxTime()Maximum execution time for a single run of this job type.- Returns:
- maximum time in milliseconds, or -1 if never run
getMinTime
public long getMinTime()Minimum execution time for a single run of this job type.- Returns:
- minimum time in milliseconds, or -1 if never run
getAvgTime
public double getAvgTime()Average execution time for this job type.- Returns:
- average time in milliseconds per run, or 0 if never run
getTotalPendingTime
public long getTotalPendingTime()Total pending/wait time for all runs of this job type.- Returns:
- total pending time in milliseconds
getMaxPendingTime
public long getMaxPendingTime()Maximum pending/wait time for a single run of this job type.- Returns:
- maximum pending time in milliseconds, or -1 if never run
getMinPendingTime
public long getMinPendingTime()Minimum pending/wait time for a single run of this job type.- Returns:
- minimum pending time in milliseconds, or -1 if never run
getAvgPendingTime
public double getAvgPendingTime()Average pending/wait time for this job type.- Returns:
- average pending time in milliseconds per run, or 0 if never run
getRecentStats
Summarise the executions that fell inside the recent tracking window.- Returns:
- run counts and time totals restricted to the recent tracking window, with -1 for the maxima and minima if no run fell in it