diff --git a/server/src/main/java/org/elasticsearch/rest/RestController.java b/server/src/main/java/org/elasticsearch/rest/RestController.java index a376b15f2f243..0efb03c3db1a3 100644 --- a/server/src/main/java/org/elasticsearch/rest/RestController.java +++ b/server/src/main/java/org/elasticsearch/rest/RestController.java @@ -28,6 +28,7 @@ import org.elasticsearch.core.Nullable; import org.elasticsearch.core.RestApiVersion; import org.elasticsearch.core.Streams; +import org.elasticsearch.core.TimeValue; import org.elasticsearch.http.HttpHeadersValidationException; import org.elasticsearch.http.HttpRouteStats; import org.elasticsearch.http.HttpServerTransport; @@ -719,7 +720,7 @@ private static final class ResourceHandlingHttpChannel implements RestChannel { this.circuitBreakerService = circuitBreakerService; this.contentLength = contentLength; this.methodHandlers = methodHandlers; - this.startTime = System.currentTimeMillis(); + this.startTime = rawRelativeTimeInMillis(); } @Override @@ -779,7 +780,7 @@ public void sendResponse(RestResponse response) { try { close(); methodHandlers.addRequestStats(contentLength); - methodHandlers.addResponseTime(System.currentTimeMillis() - startTime); + methodHandlers.addResponseTime(rawRelativeTimeInMillis() - startTime); if (response.isChunked() == false) { methodHandlers.addResponseStats(response.content().length()); } else { @@ -797,6 +798,10 @@ public void sendResponse(RestResponse response) { } } + private static long rawRelativeTimeInMillis() { + return TimeValue.nsecToMSec(System.nanoTime()); + } + private void close() { // attempt to close once atomically if (closed.compareAndSet(false, true) == false) {