-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Add optimized / direct read stats for non-cached files #54439
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
Add optimized / direct read stats for non-cached files #54439
Conversation
Pinging @elastic/es-distributed (:Distributed/Snapshot/Restore) |
this.fileName = fileName; | ||
this.fileLength = fileLength; | ||
this.openCount = openCount; | ||
this.innerCount = innerCount; |
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.
The "inner open count" information is obsolete since #53860 and has been removed
@@ -158,13 +156,13 @@ public CacheIndexInputStats(String fileName, long fileLength, long openCount, lo | |||
this.cachedBytesRead = cachedBytesRead; | |||
this.cachedBytesWritten = cachedBytesWritten; | |||
this.directBytesRead = directBytesRead; | |||
this.optimizedBytesRead = optimizedBytesRead; |
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.
This new timed counter is added to track information about optimized read operations executed in DirectBlobContainerIndexInput
protected final BlobContainer blobContainer; | ||
protected final FileInfo fileInfo; | ||
protected final IOContext context; | ||
protected final IndexInputStats stats; | ||
protected final long offset; | ||
protected final long length; |
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.
offset and length are common attributes and that's why they are added to BaseSearchableSnapshotIndexInput (sorry for the extra noise in ctors)
@@ -244,7 +244,7 @@ public IndexInput openInput(final String name, final IOContext context) throws I | |||
if (useCache && isExcludedFromCache(name) == false) { | |||
return new CachedBlobContainerIndexInput(this, fileInfo, context, inputStats); | |||
} else { | |||
return new DirectBlobContainerIndexInput(blobContainer, fileInfo, context, uncachedChunkSize, BufferedIndexInput.BUFFER_SIZE); | |||
return new DirectBlobContainerIndexInput(this, fileInfo, context, inputStats, uncachedChunkSize, bufferSize(context)); |
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.
I noticed this while writing tests: we don't align the buffer size in the same way than BufferedIndexInput would do (ie, based on the IOContext)
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.
Good catch 👍
this.offset + offset, length, true, cacheFileReference); | ||
final CachedBlobContainerIndexInput slice = new CachedBlobContainerIndexInput(getFullSliceDescription(sliceDescription), directory, | ||
fileInfo, context, stats, this.offset + offset, length, cacheFileReference); | ||
slice.isClone = true; |
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.
This is not necessary but I added it for consistency
@@ -118,12 +119,15 @@ private void readInternalBytes(final int part, long pos, final byte[] b, int off | |||
|
|||
if (optimizedReadSize < length) { | |||
// we did not read everything in an optimized fashion, so read the remainder directly | |||
final long startTimeNanos = directory.statsCurrentTimeNanos(); |
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.
This is were "direct_read_bytes" are captured for direct index inputs.
// if we open a stream of length streamLength then it will not be completely consumed by this read, so it is worthwhile to open | ||
// it and keep it open for future reads | ||
final InputStream inputStream = openBlobStream(part, pos, streamLength); | ||
streamForSequentialReads = new StreamForSequentialReads(inputStream, part, pos, streamLength); | ||
streamForSequentialReads = new StreamForSequentialReads(new FilterInputStream(inputStream) { |
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.
This is were "optimized_read_bytes" are captured for direct index inputs. Note that they are only added to stats when the stream is closed. This is useful in case the inner input stream reads all remaining bytes on closing (though there is no test for this).
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.
I left a couple of suggestions. Thanks for the commentary.
@@ -94,7 +96,9 @@ public int read(byte[] b, int off, int len) throws IOException { | |||
}; | |||
} | |||
}); | |||
return new DirectBlobContainerIndexInput(blobContainer, fileInfo, newIOContext(random()), minimumReadSize, | |||
final SearchableSnapshotDirectory directory = mock(SearchableSnapshotDirectory.class); |
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.
As far as I can see, we pass the whole SearchableSnapshotDirectory
into the IndexInput
so that the IndexInput
has access to the current time for stats purposes, leading to this mocking here -- otherwise we could continue to pass in just the BlobContainer
. I think it would be neater to keep passing the BlobContainer
and either pass in a LongSupplier
for the current time, or else attach the current time supplier to the IndexInputStats
.
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.
attach the current time supplier to the IndexInputStats
I like this one, so I pushed 47d7e4c
@Override | ||
public void close() throws IOException { | ||
super.close(); | ||
stats.addOptimizedBytesRead(bytesRead, directory.statsCurrentTimeNanos() - startTimeNanos); |
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.
This also includes the time spent waiting for sequential reads to be requested by the caller. What do you think about timing each read
call instead and adding all those timings up?
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.
You're right. I pushed a940930 which accumulates numbers for each read operation before adding the sums when the stream is closed. This way the stat will reflect a single read operation that consumed the total bytes of the stream with a more accurate timing.
I adapted the test.
@@ -244,7 +244,7 @@ public IndexInput openInput(final String name, final IOContext context) throws I | |||
if (useCache && isExcludedFromCache(name) == false) { | |||
return new CachedBlobContainerIndexInput(this, fileInfo, context, inputStats); | |||
} else { | |||
return new DirectBlobContainerIndexInput(blobContainer, fileInfo, context, uncachedChunkSize, BufferedIndexInput.BUFFER_SIZE); | |||
return new DirectBlobContainerIndexInput(this, fileInfo, context, inputStats, uncachedChunkSize, bufferSize(context)); |
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.
Good catch 👍
Thanks @DaveCTurner for your feedback. I addressed your comments. |
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.
LGTM
@elasticmachine update branch |
Running tests again after a CI failure that should be fixed by #54573 @elasticmachine run elasticsearch-ci/2 |
This pull request adds support for tracking stats about optimized (ie read ahead) and non optimized (ie direct) read operations executed for non cached Lucene files of searchable snapshot directories.