Class SlotMetrics

java.lang.Object
com.loomcache.server.metrics.SlotMetrics

public class SlotMetrics extends Object
Tracks per-slot metrics for LoomCache's consistent hashing partitions.

LoomCache uses consistent hashing with 16384 virtual slots. This class tracks metrics per slot: access counts, key counts, and bytes used. Used to detect hot spots and imbalances in the cluster.

Thread-safe via ConcurrentHashMap and AtomicLong.

Since:
1.0
  • Constructor Details

    • SlotMetrics

      public SlotMetrics()
  • Method Details

    • recordAccess

      public void recordAccess(int slotId)
      Record a single access to a slot.
      Parameters:
      slotId - slot identifier (0-16383)
    • incrementKeyCount

      public void incrementKeyCount(int slotId)
      Increment the key count for a slot.
      Parameters:
      slotId - slot identifier (0-16383)
    • decrementKeyCount

      public void decrementKeyCount(int slotId)
      Decrement the key count for a slot.
      Parameters:
      slotId - slot identifier (0-16383)
    • updateBytes

      public void updateBytes(int slotId, long delta)
      Update bytes used for a slot by a delta (can be positive or negative).
      Parameters:
      slotId - slot identifier (0-16383)
      delta - bytes to add/subtract
    • getTopSlots

      public Map<Integer, SlotMetrics.SlotStats> getTopSlots(int n)
      Get the top N slots by access count.
      Parameters:
      n - number of top slots to return
      Returns:
      unmodifiable map of slot ID → SlotStats, sorted by access count descending
    • getSlot

      public @Nullable SlotMetrics.SlotStats getSlot(int slotId)
      Get statistics for a specific slot.
      Parameters:
      slotId - slot identifier (0-16383)
      Returns:
      SlotStats if slot has been accessed, null otherwise
    • getAllSlots

      public Map<Integer, SlotMetrics.SlotStats> getAllSlots()
      Get all tracked slots.
      Returns:
      unmodifiable map of slot ID → SlotStats
    • reset

      public void reset()
      Reset all metrics (for testing).