Skip to content

Commit

Permalink
Index Cache Stats / JVM Stats: Add a refresh_interval to control when…
Browse files Browse the repository at this point in the history
… it gets refreshed, closes elastic#1200.
  • Loading branch information
kimchy committed Aug 3, 2011
1 parent 4a0b010 commit b938784
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
Expand Up @@ -28,6 +28,7 @@
import org.elasticsearch.common.component.CloseableComponent;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.index.AbstractIndexComponent;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.cache.bloom.BloomCache;
Expand All @@ -52,8 +53,13 @@ public class IndexCache extends AbstractIndexComponent implements CloseableCompo

private final BloomCache bloomCache;

private final TimeValue refreshInterval;

private ClusterService clusterService;

private long latestCacheStatsTimestamp = -1;
private CacheStats latestCacheStats;

@Inject public IndexCache(Index index, @IndexSettings Settings indexSettings, FilterCache filterCache, FieldDataCache fieldDataCache,
QueryParserCache queryParserCache, IdCache idCache, BloomCache bloomCache) {
super(index, indexSettings);
Expand All @@ -62,6 +68,10 @@ public class IndexCache extends AbstractIndexComponent implements CloseableCompo
this.queryParserCache = queryParserCache;
this.idCache = idCache;
this.bloomCache = bloomCache;

this.refreshInterval = componentSettings.getAsTime("stats.refresh_interval", TimeValue.timeValueSeconds(1));

logger.debug("Using stats.refresh_interval [{}]", refreshInterval);
}

@Inject(optional = true)
Expand All @@ -72,9 +82,14 @@ public void setClusterService(@Nullable ClusterService clusterService) {
}
}

public CacheStats stats() {
FilterCache.EntriesStats filterEntriesStats = filterCache.entriesStats();
return new CacheStats(fieldDataCache.evictions(), filterCache.evictions(), fieldDataCache.sizeInBytes(), filterEntriesStats.sizeInBytes, filterEntriesStats.count, bloomCache.sizeInBytes());
public synchronized CacheStats stats() {
long timestamp = System.currentTimeMillis();
if ((timestamp - latestCacheStatsTimestamp) > refreshInterval.millis()) {
FilterCache.EntriesStats filterEntriesStats = filterCache.entriesStats();
latestCacheStats = new CacheStats(fieldDataCache.evictions(), filterCache.evictions(), fieldDataCache.sizeInBytes(), filterEntriesStats.sizeInBytes, filterEntriesStats.count, bloomCache.sizeInBytes());
latestCacheStatsTimestamp = timestamp;
}
return latestCacheStats;
}

public FilterCache filter() {
Expand Down
Expand Up @@ -22,6 +22,7 @@
import org.elasticsearch.common.component.AbstractComponent;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;

/**
* @author kimchy (shay.banon)
Expand All @@ -30,16 +31,28 @@ public class JvmService extends AbstractComponent {

private final JvmInfo jvmInfo;

private final TimeValue refreshInterval;

private JvmStats jvmStats;

@Inject public JvmService(Settings settings) {
super(settings);
this.jvmInfo = JvmInfo.jvmInfo();
this.jvmStats = JvmStats.jvmStats();

this.refreshInterval = componentSettings.getAsTime("refresh_interval", TimeValue.timeValueSeconds(1));

logger.debug("Using refresh_interval [{}]", refreshInterval);
}

public JvmInfo info() {
return this.jvmInfo;
}

public JvmStats stats() {
return JvmStats.jvmStats();
public synchronized JvmStats stats() {
if ((System.currentTimeMillis() - jvmStats.timestamp()) > refreshInterval.millis()) {
jvmStats = JvmStats.jvmStats();
}
return jvmStats;
}
}
Expand Up @@ -41,7 +41,7 @@ public class OsService extends AbstractComponent {
super(settings);
this.probe = probe;

this.refreshInterval = componentSettings.getAsTime("refresh_interval", TimeValue.timeValueSeconds(5));
this.refreshInterval = componentSettings.getAsTime("refresh_interval", TimeValue.timeValueSeconds(1));

this.info = probe.osInfo();
this.info.refreshInterval = refreshInterval.millis();
Expand Down
Expand Up @@ -41,7 +41,7 @@ public class ProcessService extends AbstractComponent {
super(settings);
this.probe = probe;

this.refreshInterval = componentSettings.getAsTime("refresh_interval", TimeValue.timeValueSeconds(5));
this.refreshInterval = componentSettings.getAsTime("refresh_interval", TimeValue.timeValueSeconds(1));

this.info = probe.processInfo();
this.info.refreshInterval = refreshInterval.millis();
Expand Down

0 comments on commit b938784

Please sign in to comment.