DfsBlockCache: Update hits to not include contains()
Also expose the underlying hit and miss counters, in addition to the hit ratio. Change-Id: Icea2572d62e59318133b0a88848019f34ad70975
This commit is contained in:
parent
0f8e486a4d
commit
f70ecabb30
|
@ -230,6 +230,21 @@ public long getFillPercentage() {
|
||||||
return getCurrentSize() * 100 / maxBytes;
|
return getCurrentSize() * 100 / maxBytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @return number of requests for items in the cache. */
|
||||||
|
public long getHitCount() {
|
||||||
|
return statHit.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return number of requests for items not in the cache. */
|
||||||
|
public long getMissCount() {
|
||||||
|
return statMiss.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return total number of requests (hit + miss). */
|
||||||
|
public long getTotalRequestCount() {
|
||||||
|
return getHitCount() + getMissCount();
|
||||||
|
}
|
||||||
|
|
||||||
/** @return 0..100, defining number of cache hits. */
|
/** @return 0..100, defining number of cache hits. */
|
||||||
public long getHitRatio() {
|
public long getHitRatio() {
|
||||||
long hits = statHit.get();
|
long hits = statHit.get();
|
||||||
|
@ -315,8 +330,10 @@ DfsBlock getOrLoad(DfsPackFile pack, long position, DfsReader ctx)
|
||||||
int slot = slot(key, position);
|
int slot = slot(key, position);
|
||||||
HashEntry e1 = table.get(slot);
|
HashEntry e1 = table.get(slot);
|
||||||
DfsBlock v = scan(e1, key, position);
|
DfsBlock v = scan(e1, key, position);
|
||||||
if (v != null)
|
if (v != null) {
|
||||||
|
statHit.incrementAndGet();
|
||||||
return v;
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
reserveSpace(blockSize);
|
reserveSpace(blockSize);
|
||||||
ReentrantLock regionLock = lockFor(key, position);
|
ReentrantLock regionLock = lockFor(key, position);
|
||||||
|
@ -326,6 +343,7 @@ DfsBlock getOrLoad(DfsPackFile pack, long position, DfsReader ctx)
|
||||||
if (e2 != e1) {
|
if (e2 != e1) {
|
||||||
v = scan(e2, key, position);
|
v = scan(e2, key, position);
|
||||||
if (v != null) {
|
if (v != null) {
|
||||||
|
statHit.incrementAndGet();
|
||||||
creditSpace(blockSize);
|
creditSpace(blockSize);
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
@ -469,6 +487,8 @@ <T> T get(DfsPackKey key, long position) {
|
||||||
T val = (T) scan(table.get(slot(key, position)), key, position);
|
T val = (T) scan(table.get(slot(key, position)), key, position);
|
||||||
if (val == null)
|
if (val == null)
|
||||||
statMiss.incrementAndGet();
|
statMiss.incrementAndGet();
|
||||||
|
else
|
||||||
|
statHit.incrementAndGet();
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -500,17 +520,8 @@ boolean readAhead(ReadableChannel rc, DfsPackKey key, int size, long pos,
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private <T> T scan(HashEntry n, DfsPackKey pack, long position) {
|
private <T> T scan(HashEntry n, DfsPackKey pack, long position) {
|
||||||
for (; n != null; n = n.next) {
|
Ref<T> r = scanRef(n, pack, position);
|
||||||
Ref<T> r = n.ref;
|
return r != null ? r.get() : null;
|
||||||
if (r.pack != pack || r.position != position)
|
|
||||||
continue;
|
|
||||||
T v = r.get();
|
|
||||||
if (v == null)
|
|
||||||
return null;
|
|
||||||
statHit.incrementAndGet();
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
|
Loading…
Reference in New Issue