Class SlotMetrics
java.lang.Object
com.loomcache.server.metrics.SlotMetrics
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
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddecrementKeyCount(int slotId) Decrement the key count for a slot.Get all tracked slots.@Nullable SlotMetrics.SlotStatsgetSlot(int slotId) Get statistics for a specific slot.getTopSlots(int n) Get the top N slots by access count.voidincrementKeyCount(int slotId) Increment the key count for a slot.voidrecordAccess(int slotId) Record a single access to a slot.voidreset()Reset all metrics (for testing).voidupdateBytes(int slotId, long delta) Update bytes used for a slot by a delta (can be positive or negative).
-
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
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
Get statistics for a specific slot.- Parameters:
slotId- slot identifier (0-16383)- Returns:
- SlotStats if slot has been accessed, null otherwise
-
getAllSlots
Get all tracked slots.- Returns:
- unmodifiable map of slot ID → SlotStats
-
reset
public void reset()Reset all metrics (for testing).
-