diff --git a/core/src/main/java/org/elasticsearch/action/bulk/TransportBulkAction.java b/core/src/main/java/org/elasticsearch/action/bulk/TransportBulkAction.java index b2d58203954..4b53ee25e0c 100644 --- a/core/src/main/java/org/elasticsearch/action/bulk/TransportBulkAction.java +++ b/core/src/main/java/org/elasticsearch/action/bulk/TransportBulkAction.java @@ -61,6 +61,7 @@ import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Set; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; /** @@ -195,16 +196,15 @@ public class TransportBulkAction extends HandledTransportAction listener) { - final long startTime = System.currentTimeMillis(); - executeBulk(bulkRequest, startTime, listener, new AtomicArray<>(bulkRequest.requests.size())); + final long startTimeNanos = System.nanoTime(); + executeBulk(bulkRequest, startTimeNanos, listener, new AtomicArray<>(bulkRequest.requests.size())); } - private long buildTookInMillis(long startTime) { - // protect ourselves against time going backwards - return Math.max(1, System.currentTimeMillis() - startTime); + private long buildTookInMillis(long startTimeNanos) { + return TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTimeNanos); } - private void executeBulk(final BulkRequest bulkRequest, final long startTime, final ActionListener listener, final AtomicArray responses ) { + private void executeBulk(final BulkRequest bulkRequest, final long startTimeNanos, final ActionListener listener, final AtomicArray responses ) { final ClusterState clusterState = clusterService.state(); // TODO use timeout to wait here if its blocked... clusterState.blocks().globalBlockedRaiseException(ClusterBlockLevel.WRITE); @@ -302,7 +302,7 @@ public class TransportBulkAction extends HandledTransportAction