Add counts of currently executing get operations

This commit is contained in:
Igor Motov 2011-11-14 21:35:51 -05:00 committed by Shay Banon
parent 9bf42fed1b
commit 0d714d580f
2 changed files with 31 additions and 9 deletions

View File

@ -37,15 +37,17 @@ public class GetStats implements Streamable, ToXContent {
private long existsTimeInMillis;
private long missingCount;
private long missingTimeInMillis;
private long current;
public GetStats() {
}
public GetStats(long existsCount, long existsTimeInMillis, long missingCount, long missingTimeInMillis) {
public GetStats(long existsCount, long existsTimeInMillis, long missingCount, long missingTimeInMillis, long current) {
this.existsCount = existsCount;
this.existsTimeInMillis = existsTimeInMillis;
this.missingCount = missingCount;
this.missingTimeInMillis = missingTimeInMillis;
this.current = current;
}
public void add(GetStats stats) {
@ -56,6 +58,7 @@ public class GetStats implements Streamable, ToXContent {
existsTimeInMillis += stats.existsTimeInMillis;
missingCount += stats.missingCount;
missingTimeInMillis += stats.missingTimeInMillis;
current += stats.current;
}
public long count() {
@ -130,6 +133,14 @@ public class GetStats implements Streamable, ToXContent {
return missingTime();
}
public long current() {
return this.current;
}
public long getCurrent() {
return this.current;
}
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(Fields.GET);
builder.field(Fields.TOTAL, count());
@ -141,6 +152,7 @@ public class GetStats implements Streamable, ToXContent {
builder.field(Fields.MISSING_TOTAL, missingCount);
builder.field(Fields.MISSING_TIME, missingTime().toString());
builder.field(Fields.MISSING_TIME_IN_MILLIS, missingTimeInMillis);
builder.field(Fields.CURRENT, current);
builder.endObject();
return builder;
}
@ -156,6 +168,7 @@ public class GetStats implements Streamable, ToXContent {
static final XContentBuilderString MISSING_TOTAL = new XContentBuilderString("missing_total");
static final XContentBuilderString MISSING_TIME = new XContentBuilderString("missing_time");
static final XContentBuilderString MISSING_TIME_IN_MILLIS = new XContentBuilderString("missing_time_in_millis");
static final XContentBuilderString CURRENT = new XContentBuilderString("current");
}
public static GetStats readGetStats(StreamInput in) throws IOException {
@ -169,6 +182,7 @@ public class GetStats implements Streamable, ToXContent {
existsTimeInMillis = in.readVLong();
missingCount = in.readVLong();
missingTimeInMillis = in.readVLong();
current = in.readVLong();
}
@Override public void writeTo(StreamOutput out) throws IOException {
@ -176,5 +190,6 @@ public class GetStats implements Streamable, ToXContent {
out.writeVLong(existsTimeInMillis);
out.writeVLong(missingCount);
out.writeVLong(missingTimeInMillis);
out.writeVLong(current);
}
}

View File

@ -26,6 +26,7 @@ import org.elasticsearch.common.BytesHolder;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.lucene.document.ResetFieldSelector;
import org.elasticsearch.common.lucene.uid.UidField;
import org.elasticsearch.common.metrics.CounterMetric;
import org.elasticsearch.common.metrics.MeanMetric;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.cache.IndexCache;
@ -72,6 +73,7 @@ public class ShardGetService extends AbstractIndexShardComponent {
private final MeanMetric existsMetric = new MeanMetric();
private final MeanMetric missingMetric = new MeanMetric();
private final CounterMetric currentMetric = new CounterMetric();
@Inject public ShardGetService(ShardId shardId, @IndexSettings Settings indexSettings, ScriptService scriptService,
MapperService mapperService, IndexCache indexCache) {
@ -82,7 +84,7 @@ public class ShardGetService extends AbstractIndexShardComponent {
}
public GetStats stats() {
return new GetStats(existsMetric.count(), TimeUnit.NANOSECONDS.toMillis(existsMetric.sum()), missingMetric.count(), TimeUnit.NANOSECONDS.toMillis(missingMetric.sum()));
return new GetStats(existsMetric.count(), TimeUnit.NANOSECONDS.toMillis(existsMetric.sum()), missingMetric.count(), TimeUnit.NANOSECONDS.toMillis(missingMetric.sum()), currentMetric.count());
}
// sadly, to overcome cyclic dep, we need to do this and inject it ourselves...
@ -92,6 +94,8 @@ public class ShardGetService extends AbstractIndexShardComponent {
}
public GetResult get(String type, String id, String[] gFields, boolean realtime) throws ElasticSearchException {
currentMetric.inc();
try {
long now = System.nanoTime();
GetResult getResult = innerGet(type, id, gFields, realtime);
if (getResult.exists()) {
@ -100,6 +104,9 @@ public class ShardGetService extends AbstractIndexShardComponent {
missingMetric.inc(System.nanoTime() - now);
}
return getResult;
} finally {
currentMetric.dec();
}
}
public GetResult innerGet(String type, String id, String[] gFields, boolean realtime) throws ElasticSearchException {