java.lang.Object
net.i2p.router.JobStats

public class JobStatsextends Object
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.
  • Field Details

    • _job

      private final String _job
      The name of the job being tracked.
    • _numRuns

      private final AtomicLong _numRuns
      Runs of the job counted.
    • _numDropped

      private final AtomicLong _numDropped
      Runs of the job dropped.
    • _totalTime

      private final AtomicLong _totalTime
      Total run time, in ms.
    • _maxTime

      private volatile long _maxTime
      Longest run so far, in ms.
    • _minTime

      private volatile long _minTime
      Shortest run so far, in ms.
    • _totalPendingTime

      private final AtomicLong _totalPendingTime
      Total time spent pending, in ms.
    • _maxPendingTime

      private volatile long _maxPendingTime
      Longest pending time so far, in ms.
    • _minPendingTime

      private volatile long _minPendingTime
      Shortest pending time so far, in ms.
    • _lastRunTime

      private volatile long _lastRunTime
      When the job last ran.
    • DEFAULT_MAX_RECENT_ENTRIES

      private static final int DEFAULT_MAX_RECENT_ENTRIES
      Recent executions kept for a normal job.
      See Also:
    • HIGH_FREQ_MAX_RECENT_ENTRIES

      private static final int HIGH_FREQ_MAX_RECENT_ENTRIES
      Recent executions kept for a high frequency job.
      See Also:
    • HIGH_FREQ_JOBS

      private static final Set<String> HIGH_FREQ_JOBS
      Jobs whose recent window is enlarged.
    • RECENT_WINDOW_MS

      private static final long RECENT_WINDOW_MS
      Time window covered by the recent executions.
      See Also:
    • recentTrackingEnabled

      private static volatile boolean recentTrackingEnabled
      True while recent executions are recorded.
    • lastTrackingEnableTime

      private static volatile long lastTrackingEnableTime
      When a viewer last requested the tracking.
    • TRACKING_TIMEOUT_MS

      private static final long TRACKING_TIMEOUT_MS
      Time tracking stays on after the last viewer.
      See Also:
    • _maxRecentEntries

      private final int _maxRecentEntries
      Recent executions this job keeps.
    • _recentExecutions

      private final JobStats.RecentExecution[] _recentExecutions
      Ring holding the recent executions.
    • _recentIndex

      private volatile int _recentIndex
      Write index into the recent ring.
    • _recentCount

      private final AtomicInteger _recentCount
      Recent executions recorded so far.
  • Constructor Details

    • JobStats

      public JobStats(String name)
      Create statistics tracker for a named job type.
      Parameters:
      name - the job type being tracked; names in HIGH_FREQ_JOBS get 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 execute
      lag - 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

      public String getName()
      Name of this job type.
      Returns:
      the job name
    • 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

      public JobStats.RecentStats 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