Class CacheMetrics
java.lang.Object
cloud.opencode.base.cache.CacheMetrics
Cache Metrics - Detailed latency tracking with percentile calculations
缓存指标 - 带百分位数计算的详细延迟跟踪
Provides comprehensive metrics including P50, P95, P99 latency tracking for cache operations using HDR histogram approximation.
使用 HDR 直方图近似提供包括 P50、P95、P99 延迟跟踪在内的综合指标。
Features | 主要功能:
- Percentile latency tracking (P50/P95/P99) - 百分位延迟跟踪
- Min/Max/Mean latency - 最小/最大/平均延迟
- Throughput calculation - 吞吐量计算
- Operation-specific metrics - 操作特定指标
- Thread-safe concurrent recording - 线程安全并发记录
Usage Examples | 使用示例:
CacheMetrics metrics = CacheMetrics.create();
// Record operation latency - 记录操作延迟
long start = System.nanoTime();
cache.get(key);
metrics.recordGetLatency(System.nanoTime() - start);
// Get percentiles - 获取百分位数
long p50 = metrics.getLatencyP50();
long p99 = metrics.getLatencyP99();
// Get snapshot - 获取快照
MetricsSnapshot snapshot = metrics.snapshot();
Security | 安全性:
- Thread-safe: Yes - 线程安全: 是
- Memory-bounded: Yes (fixed histogram size) - 内存有界: 是(固定直方图大小)
- Since:
- JDK 25, opencode-base-cache V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordImmutable metrics snapshot 不可变指标快照 -
Method Summary
Modifier and TypeMethodDescriptionstatic CacheMetricscreate()Create new metrics instance 创建新的指标实例doubleGet average get latency in nanoseconds 获取平均获取延迟(纳秒)doubleGet average load latency in nanoseconds 获取平均加载延迟(纳秒)doubleGet average put latency in nanoseconds 获取平均放入延迟(纳秒)longGet total eviction count 获取总淘汰数longGet total get operation count 获取总获取操作数longGet P50 (median) get latency in nanoseconds 获取 P50(中位数)获取延迟(纳秒)longGet P95 get latency in nanoseconds 获取 P95 获取延迟(纳秒)longGet P99 get latency in nanoseconds 获取 P99 获取延迟(纳秒)doubleGet operations per second for get operations 获取获取操作的每秒操作数longGet total load operation count 获取总加载操作数longGet P50 (median) load latency in nanoseconds 获取 P50(中位数)加载延迟(纳秒)longGet P95 load latency in nanoseconds 获取 P95 加载延迟(纳秒)longGet P99 load latency in nanoseconds 获取 P99 加载延迟(纳秒)longGet maximum get latency in nanoseconds 获取最大获取延迟(纳秒)longGet minimum get latency in nanoseconds 获取最小获取延迟(纳秒)longGet total put operation count 获取总放入操作数longGet P50 (median) put latency in nanoseconds 获取 P50(中位数)放入延迟(纳秒)longGet P95 put latency in nanoseconds 获取 P95 放入延迟(纳秒)longGet P99 put latency in nanoseconds 获取 P99 放入延迟(纳秒)doubleGet operations per second for put operations 获取放入操作的每秒操作数Get uptime duration 获取运行时间voidRecord eviction 记录淘汰voidrecordGetLatency(long latencyNanos) Record get operation latency 记录获取操作延迟voidrecordLoadLatency(long latencyNanos) Record load operation latency 记录加载操作延迟voidrecordPutLatency(long latencyNanos) Record put operation latency 记录放入操作延迟voidreset()Reset all metrics 重置所有指标snapshot()Create immutable snapshot of current metrics 创建当前指标的不可变快照
-
Method Details
-
create
-
recordGetLatency
public void recordGetLatency(long latencyNanos) Record get operation latency 记录获取操作延迟- Parameters:
latencyNanos- latency in nanoseconds | 纳秒延迟
-
recordPutLatency
public void recordPutLatency(long latencyNanos) Record put operation latency 记录放入操作延迟- Parameters:
latencyNanos- latency in nanoseconds | 纳秒延迟
-
recordLoadLatency
public void recordLoadLatency(long latencyNanos) Record load operation latency 记录加载操作延迟- Parameters:
latencyNanos- latency in nanoseconds | 纳秒延迟
-
recordEviction
public void recordEviction()Record eviction 记录淘汰 -
getGetCount
public long getGetCount()Get total get operation count 获取总获取操作数- Returns:
- get count | 获取数
-
getPutCount
public long getPutCount()Get total put operation count 获取总放入操作数- Returns:
- put count | 放入数
-
getLoadCount
public long getLoadCount()Get total load operation count 获取总加载操作数- Returns:
- load count | 加载数
-
getEvictionCount
public long getEvictionCount()Get total eviction count 获取总淘汰数- Returns:
- eviction count | 淘汰数
-
getGetLatencyP50
public long getGetLatencyP50()Get P50 (median) get latency in nanoseconds 获取 P50(中位数)获取延迟(纳秒)- Returns:
- P50 latency | P50 延迟
-
getGetLatencyP95
public long getGetLatencyP95()Get P95 get latency in nanoseconds 获取 P95 获取延迟(纳秒)- Returns:
- P95 latency | P95 延迟
-
getGetLatencyP99
public long getGetLatencyP99()Get P99 get latency in nanoseconds 获取 P99 获取延迟(纳秒)- Returns:
- P99 latency | P99 延迟
-
getPutLatencyP50
public long getPutLatencyP50()Get P50 (median) put latency in nanoseconds 获取 P50(中位数)放入延迟(纳秒)- Returns:
- P50 latency | P50 延迟
-
getPutLatencyP95
public long getPutLatencyP95()Get P95 put latency in nanoseconds 获取 P95 放入延迟(纳秒)- Returns:
- P95 latency | P95 延迟
-
getPutLatencyP99
public long getPutLatencyP99()Get P99 put latency in nanoseconds 获取 P99 放入延迟(纳秒)- Returns:
- P99 latency | P99 延迟
-
getLoadLatencyP50
public long getLoadLatencyP50()Get P50 (median) load latency in nanoseconds 获取 P50(中位数)加载延迟(纳秒)- Returns:
- P50 latency | P50 延迟
-
getLoadLatencyP95
public long getLoadLatencyP95()Get P95 load latency in nanoseconds 获取 P95 加载延迟(纳秒)- Returns:
- P95 latency | P95 延迟
-
getLoadLatencyP99
public long getLoadLatencyP99()Get P99 load latency in nanoseconds 获取 P99 加载延迟(纳秒)- Returns:
- P99 latency | P99 延迟
-
getAverageGetLatency
public double getAverageGetLatency()Get average get latency in nanoseconds 获取平均获取延迟(纳秒)- Returns:
- average latency | 平均延迟
-
getAveragePutLatency
public double getAveragePutLatency()Get average put latency in nanoseconds 获取平均放入延迟(纳秒)- Returns:
- average latency | 平均延迟
-
getAverageLoadLatency
public double getAverageLoadLatency()Get average load latency in nanoseconds 获取平均加载延迟(纳秒)- Returns:
- average latency | 平均延迟
-
getMinGetLatency
public long getMinGetLatency()Get minimum get latency in nanoseconds 获取最小获取延迟(纳秒)- Returns:
- min latency | 最小延迟
-
getMaxGetLatency
public long getMaxGetLatency()Get maximum get latency in nanoseconds 获取最大获取延迟(纳秒)- Returns:
- max latency | 最大延迟
-
getGetThroughput
public double getGetThroughput()Get operations per second for get operations 获取获取操作的每秒操作数- Returns:
- ops/sec | 操作/秒
-
getPutThroughput
public double getPutThroughput()Get operations per second for put operations 获取放入操作的每秒操作数- Returns:
- ops/sec | 操作/秒
-
getUptime
-
snapshot
Create immutable snapshot of current metrics 创建当前指标的不可变快照- Returns:
- metrics snapshot | 指标快照
-
reset
public void reset()Reset all metrics 重置所有指标
-