Skip to content

Commit

Permalink
added test entries metric for on heap
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Alfonsi committed Oct 18, 2023
1 parent 7155afd commit c760594
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class RequestCacheStats implements Writeable, ToXContentFragment {
private long evictions;
private long hitCount;
private long missCount;
private long entries; // number of entries in the cache

public RequestCacheStats() {}

Expand All @@ -60,20 +61,23 @@ public RequestCacheStats(StreamInput in) throws IOException {
evictions = in.readVLong();
hitCount = in.readVLong();
missCount = in.readVLong();
entries = in.readVLong();
}

public RequestCacheStats(long memorySize, long evictions, long hitCount, long missCount) {
public RequestCacheStats(long memorySize, long evictions, long hitCount, long missCount, long entries) { //
this.memorySize = memorySize;
this.evictions = evictions;
this.hitCount = hitCount;
this.missCount = missCount;
this.entries = entries;
}

public void add(RequestCacheStats stats) {
this.memorySize += stats.memorySize;
this.evictions += stats.evictions;
this.hitCount += stats.hitCount;
this.missCount += stats.missCount;
this.entries += stats.entries;
}

public long getMemorySizeInBytes() {
Expand All @@ -96,12 +100,17 @@ public long getMissCount() {
return this.missCount;
}

public long getEntries() {
return this.entries;
}

@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeVLong(memorySize);
out.writeVLong(evictions);
out.writeVLong(hitCount);
out.writeVLong(missCount);
out.writeVLong(entries);
}

@Override
Expand All @@ -111,6 +120,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
builder.field(Fields.EVICTIONS, getEvictions());
builder.field(Fields.HIT_COUNT, getHitCount());
builder.field(Fields.MISS_COUNT, getMissCount());
builder.field(Fields.ENTRIES, getEntries());
builder.endObject();
return builder;
}
Expand All @@ -127,5 +137,6 @@ static final class Fields {
static final String EVICTIONS = "evictions";
static final String HIT_COUNT = "hit_count";
static final String MISS_COUNT = "miss_count";
static final String ENTRIES = "entries";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ public RequestCacheStats stats(TierType tierType) {
statsHolder.get(tierType).totalMetric.count(),
statsHolder.get(tierType).evictionsMetric.count(),
statsHolder.get(tierType).hitCount.count(),
statsHolder.get(tierType).missCount.count()
statsHolder.get(tierType).missCount.count(),
statsHolder.get(tierType).entries.count()
);
}

Expand All @@ -74,17 +75,20 @@ public RequestCacheStats overallStats() {
long totalEvictions = 0;
long totalHits = 0;
long totalMisses = 0;
long totalEntries = 0;
for (TierType tierType : TierType.values()) {
totalSize += statsHolder.get(tierType).totalMetric.count();
totalEvictions += statsHolder.get(tierType).evictionsMetric.count();
totalHits += statsHolder.get(tierType).hitCount.count();
totalMisses += statsHolder.get(tierType).missCount.count();
totalEntries += statsHolder.get(tierType).entries.count();
}
return new RequestCacheStats(
totalSize,
totalEvictions,
totalHits,
totalMisses
totalMisses,
totalEntries
);
}

Expand All @@ -98,6 +102,7 @@ public void onMiss(TierType tierType) {

public void onCached(Accountable key, BytesReference value, TierType tierType) {
statsHolder.get(tierType).totalMetric.inc(key.ramBytesUsed() + value.ramBytesUsed());
statsHolder.get(tierType).entries.inc();
}

public void onRemoval(Accountable key, BytesReference value, boolean evicted, TierType tierType) {
Expand All @@ -112,6 +117,7 @@ public void onRemoval(Accountable key, BytesReference value, boolean evicted, Ti
dec += value.ramBytesUsed();
}
statsHolder.get(tierType).totalMetric.dec(dec);
statsHolder.get(tierType).entries.dec();
}

static class StatsHolder implements Serializable {
Expand All @@ -120,5 +126,6 @@ static class StatsHolder implements Serializable {
final CounterMetric totalMetric = new CounterMetric();
final CounterMetric hitCount = new CounterMetric();
final CounterMetric missCount = new CounterMetric();
final CounterMetric entries = new CounterMetric();
}
}

0 comments on commit c760594

Please sign in to comment.