Skip to content

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

Merged
merged 8 commits into from
Apr 1, 2020

Conversation

tlrx
Copy link
Member

@tlrx tlrx commented Mar 30, 2020

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.

@tlrx tlrx added >enhancement :Distributed Coordination/Snapshot/Restore Anything directly related to the `_snapshot/*` APIs labels Mar 30, 2020
@tlrx tlrx requested a review from DaveCTurner March 30, 2020 15:51
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-distributed (:Distributed/Snapshot/Restore)

this.fileName = fileName;
this.fileLength = fileLength;
this.openCount = openCount;
this.innerCount = innerCount;
Copy link
Member Author

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;
Copy link
Member Author

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;
Copy link
Member Author

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));
Copy link
Member Author

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)

Copy link
Contributor

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;
Copy link
Member Author

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();
Copy link
Member Author

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) {
Copy link
Member Author

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).

Copy link
Contributor

@DaveCTurner DaveCTurner left a 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);
Copy link
Contributor

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.

Copy link
Member Author

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);
Copy link
Contributor

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?

Copy link
Member Author

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));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch 👍

@tlrx tlrx requested a review from DaveCTurner March 31, 2020 14:50
@tlrx
Copy link
Member Author

tlrx commented Mar 31, 2020

Thanks @DaveCTurner for your feedback. I addressed your comments.

Copy link
Contributor

@DaveCTurner DaveCTurner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@tlrx
Copy link
Member Author

tlrx commented Mar 31, 2020

@elasticmachine update branch

@tlrx
Copy link
Member Author

tlrx commented Apr 1, 2020

Running tests again after a CI failure that should be fixed by #54573

@elasticmachine run elasticsearch-ci/2

@tlrx tlrx merged commit c6e3185 into elastic:feature/searchable-snapshots Apr 1, 2020
@tlrx tlrx deleted the optmized-read-stats branch April 1, 2020 14:05
@tlrx
Copy link
Member Author

tlrx commented Apr 1, 2020

Thanks David! I had to adapt the SearchableSnapshotsIntegTests in ea80078 and 689eb8c now stats are also exposed when the cache is enabled or when a file is explicitely uncached.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Distributed Coordination/Snapshot/Restore Anything directly related to the `_snapshot/*` APIs >enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants