Merge pull request #12346 from jasontedor/fix/12345

Use time with nanosecond resolution calculated at the executing node to measure the time that contexts are held open
This commit is contained in:
Jason Tedor 2015-07-20 15:54:54 -04:00
commit 34155ff102
6 changed files with 27 additions and 1 deletions

View File

@ -175,7 +175,7 @@ public final class ShardSearchStats {
public void onFreeScrollContext(SearchContext context) {
totalStats.scrollCurrent.dec();
totalStats.scrollMetric.inc(TimeUnit.MILLISECONDS.toNanos(System.currentTimeMillis() - context.nowInMillis()));
totalStats.scrollMetric.inc(System.nanoTime() - context.getOriginNanoTime());
}
public void onRefreshSettings(Settings settings) {

View File

@ -98,6 +98,7 @@ public class PercolateContext extends SearchContext {
private final ConcurrentMap<BytesRef, Query> percolateQueries;
private final int numberOfShards;
private final Query aliasFilter;
private final long originNanoTime = System.nanoTime();
private final long startTime;
private String[] types;
@ -337,6 +338,11 @@ public class PercolateContext extends SearchContext {
throw new UnsupportedOperationException();
}
@Override
public long getOriginNanoTime() {
return originNanoTime;
}
@Override
protected long nowInMillisImpl() {
return startTime;

View File

@ -122,6 +122,7 @@ public class DefaultSearchContext extends SearchContext {
private boolean queryRewritten;
private volatile long keepAlive;
private ScoreDoc lastEmittedDoc;
private final long originNanoTime = System.nanoTime();
private volatile long lastAccessTime = -1;
private InnerHitsContext innerHitsContext;
@ -269,6 +270,11 @@ public class DefaultSearchContext extends SearchContext {
return this;
}
@Override
public long getOriginNanoTime() {
return originNanoTime;
}
@Override
protected long nowInMillisImpl() {
return request.nowInMillis();

View File

@ -139,6 +139,11 @@ public abstract class FilteredSearchContext extends SearchContext {
return in.queryBoost(queryBoost);
}
@Override
public long getOriginNanoTime() {
return in.getOriginNanoTime();
}
@Override
protected long nowInMillisImpl() {
return in.nowInMillisImpl();

View File

@ -142,6 +142,8 @@ public abstract class SearchContext implements Releasable, HasContextAndHeaders
public abstract SearchContext queryBoost(float queryBoost);
public abstract long getOriginNanoTime();
public final long nowInMillis() {
nowInMillisUsed = true;
return nowInMillisImpl();

View File

@ -82,6 +82,8 @@ public class TestSearchContext extends SearchContext {
private String[] types;
private SearchContextAggregations aggregations;
private final long originNanoTime = System.nanoTime();
public TestSearchContext(ThreadPool threadPool,PageCacheRecycler pageCacheRecycler, BigArrays bigArrays, IndexService indexService, QueryCache filterCache, IndexFieldDataService indexFieldDataService) {
super(ParseFieldMatcher.STRICT);
this.pageCacheRecycler = pageCacheRecycler;
@ -170,6 +172,11 @@ public class TestSearchContext extends SearchContext {
return null;
}
@Override
public long getOriginNanoTime() {
return originNanoTime;
}
@Override
protected long nowInMillisImpl() {
return 0;