Skip to content

Commit

Permalink
cache metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
n5nk committed Dec 7, 2023
1 parent d88e2a4 commit 7db1a67
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ on:
push:
branches:
- atlan-v0.6.0
- atlan-v0.6.test

env:
ES_JAVA_OPTS: "-Xms256m -Xmx512m"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package org.janusgraph.diskstorage.keycolumnvalue.cache;

import com.codahale.metrics.Timer;
import com.google.common.base.Preconditions;
import com.google.common.cache.CacheLoader;
import org.janusgraph.core.JanusGraphException;
Expand All @@ -26,6 +27,7 @@
import org.janusgraph.diskstorage.keycolumnvalue.SliceQuery;
import org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction;
import org.janusgraph.diskstorage.util.CacheMetricsAction;
import org.janusgraph.util.stats.MetricManager;
import org.nustaq.serialization.FSTConfiguration;
import org.redisson.api.EvictionMode;
import org.redisson.api.RLock;
Expand Down Expand Up @@ -69,6 +71,7 @@ public ExpirationKCVSRedisCache(final KeyColumnValueStore store, String metricsN
redisCache = redissonClient.getMapCache(String.join("-", configuration.get(CACHE_KEYSPACE_PREFIX), metricsName));
redisIndexKeys = redissonClient.getMapCache(String.join("-", configuration.get(CACHE_KEYSPACE_PREFIX), REDIS_INDEX_CACHE_PREFIX, metricsName));
redisCache.setMaxSize(configuration.get(REDIS_MAX_CACHE_SIZE), EvictionMode.LFU);
redisIndexKeys.setMaxSize(configuration.get(REDIS_MAX_CACHE_SIZE), EvictionMode.LFU);
logger.info("********************** Configurations are loaded **********************");
}

Expand All @@ -88,7 +91,11 @@ public EntryList getSlice(final KeySliceQuery query, final StoreTransaction txh)
}

private EntryList get(KeySliceQuery query, Callable<EntryList> valueLoader) {
long d = System.currentTimeMillis();
byte[] bytQuery = redisCache.get(query);
MetricManager.INSTANCE.getTimer("getCacheKey", "name", getMetricsName()).update(System.currentTimeMillis() - d, TimeUnit.MILLISECONDS);
long timeTaken = System.currentTimeMillis() - d;
logger.info("CacheMetrics:getCacheKey:"+getMetricsName()+":"+timeTaken);
EntryList entries = bytQuery != null ? (EntryList) fastConf.asObject(bytQuery) : null;
if (entries == null) {
logger.log(Level.INFO, "Reading from the store.................");
Expand All @@ -97,7 +104,12 @@ private EntryList get(KeySliceQuery query, Callable<EntryList> valueLoader) {
if (entries == null) {
throw new CacheLoader.InvalidCacheLoadException("valueLoader must not return null, key=" + query);
} else {
d = System.currentTimeMillis();
redisCache.fastPutAsync(query, fastConf.asByteArray(entries), this.cacheTimeMS,TimeUnit.MILLISECONDS);
timeTaken = System.currentTimeMillis() - d;
MetricManager.INSTANCE.getTimer("putCacheKey", "name", getMetricsName()).update(timeTaken, TimeUnit.MILLISECONDS);
logger.info("CacheMetrics:putCacheKey:"+getMetricsName()+":"+timeTaken);
d = System.currentTimeMillis();
RLock lock = redisIndexKeys.getLock(query.getKey());
try {
lock.tryLock(1, 3, TimeUnit.SECONDS);
Expand All @@ -110,6 +122,9 @@ private EntryList get(KeySliceQuery query, Callable<EntryList> valueLoader) {
e.printStackTrace();
} finally {
lock.unlock();
timeTaken = System.currentTimeMillis() - d;
MetricManager.INSTANCE.getTimer("lockTime", "name", getMetricsName()).update(timeTaken, TimeUnit.MILLISECONDS);
logger.info("CacheMetrics:lockTime:"+getMetricsName()+":"+timeTaken);
}
}
} catch (Exception e) {
Expand Down Expand Up @@ -177,13 +192,21 @@ public void clearCache() {

@Override
public void invalidate(StaticBuffer key, List<CachableStaticBuffer> entries) {
long d = System.currentTimeMillis();
List<KeySliceQuery> keySliceQueryList = redisIndexKeys.get(key);
long timeTaken = System.currentTimeMillis() - d;
MetricManager.INSTANCE.getTimer("getKeyInvalidate", "name", getMetricsName()).update(timeTaken, TimeUnit.MILLISECONDS);
logger.info("CacheMetrics:getKeyInvalidate:"+getMetricsName()+":"+timeTaken);
if (keySliceQueryList != null) {
d = System.currentTimeMillis();
for (KeySliceQuery keySliceQuery : keySliceQueryList) {
if (key.equals(keySliceQuery.getKey())) {
redisCache.fastRemoveAsync(keySliceQuery);
}
}
timeTaken = System.currentTimeMillis() - d;
MetricManager.INSTANCE.getTimer("removeasync", "name", getMetricsName()).update(timeTaken, TimeUnit.MILLISECONDS);
logger.info("CacheMetrics:getKeyInvalidate:"+getMetricsName()+":"+timeTaken);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public abstract class KCVSCache extends KCVSProxy {

private final String metricsName;

protected String getMetricsName(){return this.metricsName;}
protected KCVSCache(KeyColumnValueStore store, String metricsName) {
super(store);
this.metricsName = metricsName;
Expand Down

0 comments on commit 7db1a67

Please sign in to comment.