Skip to content

Commit

Permalink
Merge pull request #12346 from jasontedor/fix/12345
Browse files Browse the repository at this point in the history
Use time with nanosecond resolution calculated at the executing node to measure the time that contexts are held open
  • Loading branch information
jasontedor committed Jul 20, 2015
2 parents 068fae2 + 3af763e commit 34155ff
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 1 deletion.
Expand Up @@ -175,7 +175,7 @@ public void onNewScrollContext(SearchContext context) {

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) {
Expand Down
Expand Up @@ -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;

Expand Down Expand Up @@ -337,6 +338,11 @@ public SearchContext queryBoost(float queryBoost) {
throw new UnsupportedOperationException();
}

@Override
public long getOriginNanoTime() {
return originNanoTime;
}

@Override
protected long nowInMillisImpl() {
return startTime;
Expand Down
Expand Up @@ -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;

Expand Down Expand Up @@ -269,6 +270,11 @@ public SearchContext queryBoost(float queryBoost) {
return this;
}

@Override
public long getOriginNanoTime() {
return originNanoTime;
}

@Override
protected long nowInMillisImpl() {
return request.nowInMillis();
Expand Down
Expand Up @@ -139,6 +139,11 @@ public SearchContext queryBoost(float queryBoost) {
return in.queryBoost(queryBoost);
}

@Override
public long getOriginNanoTime() {
return in.getOriginNanoTime();
}

@Override
protected long nowInMillisImpl() {
return in.nowInMillisImpl();
Expand Down
Expand Up @@ -142,6 +142,8 @@ public final void close() {

public abstract SearchContext queryBoost(float queryBoost);

public abstract long getOriginNanoTime();

public final long nowInMillis() {
nowInMillisUsed = true;
return nowInMillisImpl();
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -170,6 +172,11 @@ public SearchContext queryBoost(float queryBoost) {
return null;
}

@Override
public long getOriginNanoTime() {
return originNanoTime;
}

@Override
protected long nowInMillisImpl() {
return 0;
Expand Down

0 comments on commit 34155ff

Please sign in to comment.