Skip to content

Commit

Permalink
EntityStoreStatistics mbean exposes EntityIterableCache's countsCache…
Browse files Browse the repository at this point in the history
… data
  • Loading branch information
penemue committed Feb 13, 2020
1 parent 5f4f55c commit 42b2346
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,14 @@ public final class EntityIterableCache {
// the value is updated by PersistentEntityStoreSettingsListener
public boolean isCachingDisabled;

public EntityIterableCache(@NotNull final PersistentEntityStoreImpl store) {
EntityIterableCache(@NotNull final PersistentEntityStoreImpl store) {
this.store = store;
config = store.getConfig();
cacheAdapter = new EntityIterableCacheAdapter(config);
stats = new EntityIterableCacheStatistics();
clear();
final int cacheSize = config.getEntityIterableCacheSize();
deferredIterablesCache = new ConcurrentObjectCache<>(cacheSize);
iterableCountsCache = new ConcurrentObjectCache<>(config.getEntityIterableCacheCountsCacheSize());
processor = new EntityStoreSharedAsyncProcessor(config.getEntityIterableCacheThreadCount());
processor.start();
isCachingDisabled = config.isCachingDisabled();
Expand All @@ -67,6 +69,11 @@ public float hitRate() {
return cacheAdapter.hitRate();
}

public float countsCacheHitRate() {
return iterableCountsCache.hitRate();
}

@NotNull
public EntityIterableCacheStatistics getStats() {
return stats;
}
Expand Down Expand Up @@ -141,7 +148,13 @@ public EntityIterableBase putIfNotCached(@NotNull final EntityIterableBase it) {

@Nullable
public Long getCachedCount(@NotNull final EntityIterableHandle handle) {
return iterableCountsCache.tryKey(handle.getIdentity());
final Long result = iterableCountsCache.tryKey(handle.getIdentity());
if (result == null) {
stats.incTotalCountMisses();
} else {
stats.incTotalCountHits();
}
return result;
}

public long getCachedCount(@NotNull final EntityIterableBase it) {
Expand All @@ -152,7 +165,7 @@ public long getCachedCount(@NotNull final EntityIterableBase it) {
}
if (it.isThreadSafe() && !isCachingQueueFull()) {
new EntityIterableAsyncInstantiation(handle, it, false).queue(
result == null ? Priority.normal : Priority.below_normal);
result == null ? Priority.normal : Priority.below_normal);
}
return result == null ? -1 : result;
}
Expand Down Expand Up @@ -202,7 +215,7 @@ private EntityIterableAsyncInstantiation(@NotNull final EntityIterableHandle han
setProcessor(processor);
stats.incTotalJobsEnqueued();
if (!isConsistent) {
stats.incTotalCountJobs();
stats.incTotalCountJobsEnqueued();
}
}

Expand Down Expand Up @@ -282,7 +295,7 @@ private CachingCancellingPolicy(final boolean isConsistent) {
this.isConsistent = isConsistent;
startTime = System.currentTimeMillis();
cachingTimeout = isConsistent ?
config.getEntityIterableCacheCachingTimeout() : config.getEntityIterableCacheCountsCachingTimeout();
config.getEntityIterableCacheCachingTimeout() : config.getEntityIterableCacheCountsCachingTimeout();
}

private boolean isOverdue(final long currentMillis) {
Expand Down Expand Up @@ -357,6 +370,6 @@ public void run() {

public static String getStringPresentation(@NotNull final PersistentEntityStoreConfig config, @NotNull final EntityIterableHandle handle) {
return config.getEntityIterableCacheUseHumanReadable() ?
EntityIterableBase.getHumanReadablePresentation(handle) : handle.toString();
EntityIterableBase.getHumanReadablePresentation(handle) : handle.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ public long getTotalCachingJobsNotStarted() {
}

@Override
public long getTotalCachingCountJobs() {
return store.getEntityIterableCache().getStats().getTotalCountJobs();
public long getTotalCachingCountJobsEnqueued() {
return store.getEntityIterableCache().getStats().getTotalCountJobsEnqueued();
}

@Override
Expand All @@ -79,11 +79,26 @@ public long getTotalEntityIterableCacheMisses() {
return store.getEntityIterableCache().getStats().getTotalMisses();
}

@Override
public long getTotalEntityIterableCacheCountHits() {
return store.getEntityIterableCache().getStats().getTotalCountHits();
}

@Override
public long getTotalEntityIterableCacheCountMisses() {
return store.getEntityIterableCache().getStats().getTotalCountMisses();
}

@Override
public float getEntityIterableCacheHitRate() {
return store.getEntityIterableCache().hitRate();
}

@Override
public float getEntityIterableCacheCountHitRate() {
return store.getEntityIterableCache().countsCacheHitRate();
}

@Override
public float getBlobStringsCacheHitRate() {
return store.getBlobVault().getStringContentCacheHitRate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,19 @@ public interface EntityStoreStatisticsMBean {

long getTotalCachingJobsNotStarted();

long getTotalCachingCountJobs();
long getTotalCachingCountJobsEnqueued();

long getTotalEntityIterableCacheHits();

long getTotalEntityIterableCacheMisses();

long getTotalEntityIterableCacheCountHits();

long getTotalEntityIterableCacheCountMisses();

float getEntityIterableCacheHitRate();

float getEntityIterableCacheCountHitRate();

float getBlobStringsCacheHitRate();
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@ class EntityIterableCacheStatistics {
private set
var totalJobsNotStarted = 0L
private set
var totalCountJobs = 0L
var totalCountJobsEnqueued = 0L
private set
var totalHits = 0L
private set
var totalMisses = 0L
private set
var totalCountHits = 0L
private set
var totalCountMisses = 0L
private set

fun incTotalJobsEnqueued() = ++totalJobsEnqueued

Expand All @@ -40,9 +44,13 @@ class EntityIterableCacheStatistics {

fun incTotalJobsNotStarted() = ++totalJobsNotStarted

fun incTotalCountJobs() = ++totalCountJobs
fun incTotalCountJobsEnqueued() = ++totalCountJobsEnqueued

fun incTotalHits() = ++totalHits

fun incTotalMisses() = ++totalMisses

fun incTotalCountHits() = ++totalCountHits

fun incTotalCountMisses() = ++totalCountMisses
}

0 comments on commit 42b2346

Please sign in to comment.