-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Metrics to account for time spent waiting for next chunk #129469
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
8763cd5
6f97068
160aa68
ef7afa4
6472d42
dc16d64
6a6c27a
c6a60b7
6799c5e
f8ca2a0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,6 +42,7 @@ | |
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
| import java.util.concurrent.TimeUnit; | ||
| import java.util.function.Supplier; | ||
|
|
||
| import static org.elasticsearch.rest.RestRequest.Method.POST; | ||
|
|
@@ -165,6 +166,9 @@ static class ChunkHandler implements BaseRestHandler.RequestBodyChunkConsumer { | |
| private final ArrayDeque<ReleasableBytesReference> unParsedChunks = new ArrayDeque<>(4); | ||
| private final ArrayList<DocWriteRequest<?>> items = new ArrayList<>(4); | ||
|
|
||
| private long requestNextChunkTime; | ||
| private long totalChunkWaitTimeInNanos = 0L; | ||
|
|
||
| ChunkHandler(boolean allowExplicitIndex, RestRequest request, Supplier<IncrementalBulkService.Handler> handlerSupplier) { | ||
| this.request = request; | ||
| this.handlerSupplier = handlerSupplier; | ||
|
|
@@ -189,13 +193,20 @@ static class ChunkHandler implements BaseRestHandler.RequestBodyChunkConsumer { | |
| public void accept(RestChannel restChannel) { | ||
| this.restChannel = restChannel; | ||
| this.handler = handlerSupplier.get(); | ||
| requestNextChunkTime = System.nanoTime(); | ||
| request.contentStream().next(); | ||
| } | ||
|
|
||
| @Override | ||
| public void handleChunk(RestChannel channel, ReleasableBytesReference chunk, boolean isLast) { | ||
| assert handler != null; | ||
| assert channel == restChannel; | ||
| long now = System.nanoTime(); | ||
| long elapsedTime = now - requestNextChunkTime; | ||
| if (elapsedTime > 0) { | ||
| totalChunkWaitTimeInNanos += elapsedTime; | ||
| requestNextChunkTime = now; | ||
| } | ||
| if (shortCircuited) { | ||
| chunk.close(); | ||
| return; | ||
|
|
@@ -239,12 +250,18 @@ public void handleChunk(RestChannel channel, ReleasableBytesReference chunk, boo | |
| items.clear(); | ||
| handler.lastItems(toPass, () -> Releasables.close(releasables), new RestRefCountedChunkedToXContentListener<>(channel)); | ||
| } | ||
| handler.updateWaitForChunkMetrics(TimeUnit.NANOSECONDS.toMillis(totalChunkWaitTimeInNanos)); | ||
| totalChunkWaitTimeInNanos = 0L; | ||
| } else if (items.isEmpty() == false) { | ||
| ArrayList<DocWriteRequest<?>> toPass = new ArrayList<>(items); | ||
| items.clear(); | ||
| handler.addItems(toPass, () -> Releasables.close(releasables), () -> request.contentStream().next()); | ||
| handler.addItems(toPass, () -> Releasables.close(releasables), () -> { | ||
| requestNextChunkTime = System.nanoTime(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you know if request.contentStream().next(); immediately calls handleChunk if data is available? Otherwise I wonder if we want to capture the time before calling next.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should do it prior, seems more correct regardless. |
||
| request.contentStream().next(); | ||
| }); | ||
| } else { | ||
| Releasables.close(releasables); | ||
| requestNextChunkTime = System.nanoTime(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also set this before calling |
||
| request.contentStream().next(); | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We often pass LongSupplier instead of the real time measurement method, it makes testing easier.