Add to node stats the number of times field cache was evicted due to memory constraints, closes #603.

This commit is contained in:
kimchy 2011-01-05 22:37:15 +02:00
parent 754b0d7a0f
commit 66d63055df
7 changed files with 58 additions and 6 deletions

View File

@ -42,6 +42,8 @@ public interface FieldDataCache extends IndexComponent, CloseableComponent {
void clearUnreferenced(); void clearUnreferenced();
long evictions();
long sizeInBytes(); long sizeInBytes();
long sizeInBytes(String fieldName); long sizeInBytes(String fieldName);

View File

@ -69,4 +69,8 @@ public class NoneFieldDataCache extends AbstractIndexComponent implements FieldD
@Override public long sizeInBytes(String fieldName) { @Override public long sizeInBytes(String fieldName) {
return 0; return 0;
} }
@Override public long evictions() {
return 0;
}
} }

View File

@ -45,4 +45,8 @@ public class ResidentFieldDataCache extends AbstractConcurrentMapFieldDataCache
@Override public String type() { @Override public String type() {
return "resident"; return "resident";
} }
@Override public long evictions() {
return 0;
}
} }

View File

@ -19,6 +19,7 @@
package org.elasticsearch.index.cache.field.data.soft; package org.elasticsearch.index.cache.field.data.soft;
import org.elasticsearch.common.collect.MapEvictionListener;
import org.elasticsearch.common.collect.MapMaker; import org.elasticsearch.common.collect.MapMaker;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
@ -27,22 +28,34 @@ import org.elasticsearch.index.cache.field.data.support.AbstractConcurrentMapFie
import org.elasticsearch.index.field.data.FieldData; import org.elasticsearch.index.field.data.FieldData;
import org.elasticsearch.index.settings.IndexSettings; import org.elasticsearch.index.settings.IndexSettings;
import javax.annotation.Nullable;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicLong;
/** /**
* @author kimchy (shay.banon) * @author kimchy (shay.banon)
*/ */
public class SoftFieldDataCache extends AbstractConcurrentMapFieldDataCache { public class SoftFieldDataCache extends AbstractConcurrentMapFieldDataCache implements MapEvictionListener<String, FieldData> {
private final AtomicLong evictions = new AtomicLong();
@Inject public SoftFieldDataCache(Index index, @IndexSettings Settings indexSettings) { @Inject public SoftFieldDataCache(Index index, @IndexSettings Settings indexSettings) {
super(index, indexSettings); super(index, indexSettings);
} }
@Override protected ConcurrentMap<String, FieldData> buildFieldDataMap() { @Override protected ConcurrentMap<String, FieldData> buildFieldDataMap() {
return new MapMaker().softValues().makeMap(); return new MapMaker().softValues().evictionListener(this).makeMap();
}
@Override public long evictions() {
return evictions.get();
} }
@Override public String type() { @Override public String type() {
return "soft"; return "soft";
} }
@Override public void onEviction(@Nullable String s, @Nullable FieldData fieldData) {
evictions.incrementAndGet();
}
} }

View File

@ -19,6 +19,7 @@
package org.elasticsearch.index.cache.field.data.weak; package org.elasticsearch.index.cache.field.data.weak;
import org.elasticsearch.common.collect.MapEvictionListener;
import org.elasticsearch.common.collect.MapMaker; import org.elasticsearch.common.collect.MapMaker;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
@ -27,22 +28,34 @@ import org.elasticsearch.index.cache.field.data.support.AbstractConcurrentMapFie
import org.elasticsearch.index.field.data.FieldData; import org.elasticsearch.index.field.data.FieldData;
import org.elasticsearch.index.settings.IndexSettings; import org.elasticsearch.index.settings.IndexSettings;
import javax.annotation.Nullable;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicLong;
/** /**
* @author kimchy (shay.banon) * @author kimchy (shay.banon)
*/ */
public class WeakFieldDataCache extends AbstractConcurrentMapFieldDataCache { public class WeakFieldDataCache extends AbstractConcurrentMapFieldDataCache implements MapEvictionListener<String, FieldData> {
private final AtomicLong evictions = new AtomicLong();
@Inject public WeakFieldDataCache(Index index, @IndexSettings Settings indexSettings) { @Inject public WeakFieldDataCache(Index index, @IndexSettings Settings indexSettings) {
super(index, indexSettings); super(index, indexSettings);
} }
@Override protected ConcurrentMap<String, FieldData> buildFieldDataMap() { @Override protected ConcurrentMap<String, FieldData> buildFieldDataMap() {
return new MapMaker().weakValues().makeMap(); return new MapMaker().weakValues().evictionListener(this).makeMap();
} }
@Override public String type() { @Override public String type() {
return "weak"; return "weak";
} }
@Override public long evictions() {
return evictions.get();
}
@Override public void onEviction(@Nullable String s, @Nullable FieldData fieldData) {
evictions.incrementAndGet();
}
} }

View File

@ -43,13 +43,17 @@ public class IndicesStats implements Streamable, Serializable, ToXContent {
private ByteSizeValue filterCacheSize; private ByteSizeValue filterCacheSize;
private long fieldCacheEvictions;
IndicesStats() { IndicesStats() {
} }
public IndicesStats(ByteSizeValue storeSize, ByteSizeValue fieldCacheSize, ByteSizeValue filterCacheSize) { public IndicesStats(ByteSizeValue storeSize, ByteSizeValue fieldCacheSize, ByteSizeValue filterCacheSize,
long fieldCacheEvictions) {
this.storeSize = storeSize; this.storeSize = storeSize;
this.fieldCacheSize = fieldCacheSize; this.fieldCacheSize = fieldCacheSize;
this.filterCacheSize = filterCacheSize; this.filterCacheSize = filterCacheSize;
this.fieldCacheEvictions = fieldCacheEvictions;
} }
/** /**
@ -82,6 +86,14 @@ public class IndicesStats implements Streamable, Serializable, ToXContent {
return this.filterCacheSize; return this.filterCacheSize;
} }
public long fieldCacheEvictions() {
return this.fieldCacheEvictions;
}
public long getFieldCacheEvictions() {
return fieldCacheEvictions();
}
public static IndicesStats readIndicesStats(StreamInput in) throws IOException { public static IndicesStats readIndicesStats(StreamInput in) throws IOException {
IndicesStats stats = new IndicesStats(); IndicesStats stats = new IndicesStats();
stats.readFrom(in); stats.readFrom(in);
@ -104,6 +116,7 @@ public class IndicesStats implements Streamable, Serializable, ToXContent {
builder.startObject(Fields.INDICES); builder.startObject(Fields.INDICES);
builder.field(Fields.STORE_SIZE, storeSize.toString()); builder.field(Fields.STORE_SIZE, storeSize.toString());
builder.field(Fields.STORE_SIZE_IN_BYTES, storeSize.bytes()); builder.field(Fields.STORE_SIZE_IN_BYTES, storeSize.bytes());
builder.field(Fields.FIELD_CACHE_EVICTIONS, fieldCacheEvictions);
builder.field(Fields.FIELD_CACHE_SIZE, fieldCacheSize.toString()); builder.field(Fields.FIELD_CACHE_SIZE, fieldCacheSize.toString());
builder.field(Fields.FIELD_CACHE_SIZE_IN_BYTES, fieldCacheSize.bytes()); builder.field(Fields.FIELD_CACHE_SIZE_IN_BYTES, fieldCacheSize.bytes());
builder.field(Fields.FILTER_CACHE_SIZE, filterCacheSize.toString()); builder.field(Fields.FILTER_CACHE_SIZE, filterCacheSize.toString());
@ -117,6 +130,7 @@ public class IndicesStats implements Streamable, Serializable, ToXContent {
static final XContentBuilderString STORE_SIZE_IN_BYTES = new XContentBuilderString("store_size_in_bytes"); static final XContentBuilderString STORE_SIZE_IN_BYTES = new XContentBuilderString("store_size_in_bytes");
static final XContentBuilderString FIELD_CACHE_SIZE = new XContentBuilderString("field_cache_size"); static final XContentBuilderString FIELD_CACHE_SIZE = new XContentBuilderString("field_cache_size");
static final XContentBuilderString FIELD_CACHE_SIZE_IN_BYTES = new XContentBuilderString("field_cache_size_in_bytes"); static final XContentBuilderString FIELD_CACHE_SIZE_IN_BYTES = new XContentBuilderString("field_cache_size_in_bytes");
static final XContentBuilderString FIELD_CACHE_EVICTIONS = new XContentBuilderString("field_cache_evictions");
static final XContentBuilderString FILTER_CACHE_SIZE = new XContentBuilderString("filter_cache_size"); static final XContentBuilderString FILTER_CACHE_SIZE = new XContentBuilderString("filter_cache_size");
static final XContentBuilderString FILTER_CACHE_SIZE_IN_BYTES = new XContentBuilderString("filter_cache_size_in_bytes"); static final XContentBuilderString FILTER_CACHE_SIZE_IN_BYTES = new XContentBuilderString("filter_cache_size_in_bytes");
} }

View File

@ -156,6 +156,7 @@ public class InternalIndicesService extends AbstractLifecycleComponent<IndicesSe
@Override public IndicesStats stats() { @Override public IndicesStats stats() {
long storeTotalSize = 0; long storeTotalSize = 0;
long fieldCacheEvictions = 0;
long fieldCacheTotalSize = 0; long fieldCacheTotalSize = 0;
long filterCacheTotalSize = 0; long filterCacheTotalSize = 0;
for (IndexService indexService : indices.values()) { for (IndexService indexService : indices.values()) {
@ -166,10 +167,11 @@ public class InternalIndicesService extends AbstractLifecycleComponent<IndicesSe
// ignore // ignore
} }
} }
fieldCacheEvictions += indexService.cache().fieldData().evictions();
fieldCacheTotalSize += indexService.cache().fieldData().sizeInBytes(); fieldCacheTotalSize += indexService.cache().fieldData().sizeInBytes();
filterCacheTotalSize += indexService.cache().filter().sizeInBytes(); filterCacheTotalSize += indexService.cache().filter().sizeInBytes();
} }
return new IndicesStats(new ByteSizeValue(storeTotalSize), new ByteSizeValue(fieldCacheTotalSize), new ByteSizeValue(filterCacheTotalSize)); return new IndicesStats(new ByteSizeValue(storeTotalSize), new ByteSizeValue(fieldCacheTotalSize), new ByteSizeValue(filterCacheTotalSize), fieldCacheEvictions);
} }
/** /**