Skip to content

Commit

Permalink
use nanoTime
Browse files Browse the repository at this point in the history
  • Loading branch information
ywangd committed Sep 27, 2023
1 parent 5c1fdb7 commit 4a4cd4a
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down

0 comments on commit 4a4cd4a

Please sign in to comment.