-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Fix cacheMissPercentage metric #18208
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1f08bae
try to fix metrics
juanjuan2 bb4a5aa
1
juanjuan2 ba4b9b9
fix cachemiss metric
juanjuan2 e99322e
fix metric
juanjuan2 cf2957e
fix cachemiss metrics
juanjuan2 2e74aa5
fix cachemiss metrics v2
juanjuan2 2c42671
fix cachemiss metrics v3
juanjuan2 2ca2b2f
fix cachemiss metrics v4
juanjuan2 11dddd6
fix cachemiss metrics v5
juanjuan2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
core/server/worker/src/main/java/alluxio/worker/block/io/MetricAccountingBlockReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* | ||
* The Alluxio Open Foundation licenses this work under the Apache License, version 2.0 | ||
* (the "License"). You may not use this work except in compliance with the License, which is | ||
* available at www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
* either express or implied, as more fully set forth in the License. | ||
* | ||
* See the NOTICE file distributed with this work for information regarding copyright ownership. | ||
*/ | ||
|
||
package alluxio.worker.block.io; | ||
|
||
import alluxio.metrics.MetricKey; | ||
import alluxio.metrics.MetricsSystem; | ||
|
||
import io.netty.buffer.ByteBuf; | ||
|
||
import java.io.IOException; | ||
import java.nio.ByteBuffer; | ||
import java.nio.channels.ReadableByteChannel; | ||
|
||
/** | ||
* An reader class with metrics. | ||
*/ | ||
public class MetricAccountingBlockReader extends BlockReader { | ||
private final LocalFileBlockReader mBlockReader; | ||
|
||
/** | ||
* A decorator of BlockReader. | ||
* @param mblockReader block reader | ||
*/ | ||
public MetricAccountingBlockReader(LocalFileBlockReader mblockReader) { | ||
mBlockReader = mblockReader; | ||
} | ||
|
||
@Override | ||
public ByteBuffer read(long offset, long length) throws IOException { | ||
ByteBuffer buffer = mBlockReader.read(offset, length); | ||
int bytesReadFromCache = buffer.limit() - buffer.position(); | ||
MetricsSystem.counter(MetricKey.WORKER_BYTES_READ_CACHE.getName()).inc(bytesReadFromCache); | ||
return buffer; | ||
} | ||
|
||
@Override | ||
public long getLength() { | ||
return mBlockReader.getLength(); | ||
} | ||
|
||
@Override | ||
public ReadableByteChannel getChannel() { | ||
return new ReadableByteChannel() { | ||
private final ReadableByteChannel mDelegate = mBlockReader.getChannel(); | ||
@Override | ||
public int read(ByteBuffer dst) throws IOException { | ||
int bytesRead = mDelegate.read(dst); | ||
if (bytesRead != -1) { | ||
MetricsSystem.counter(MetricKey.WORKER_BYTES_READ_CACHE.getName()).inc(bytesRead); | ||
} | ||
return bytesRead; | ||
} | ||
|
||
@Override | ||
public boolean isOpen() { | ||
return mDelegate.isOpen(); | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
mDelegate.close(); | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
public int transferTo(ByteBuf buf) throws IOException { | ||
int bytesReadFromCache = mBlockReader.transferTo(buf); | ||
if (bytesReadFromCache != -1) { | ||
MetricsSystem.counter(MetricKey.WORKER_BYTES_READ_CACHE.getName()).inc(bytesReadFromCache); | ||
} | ||
return bytesReadFromCache; | ||
} | ||
|
||
@Override | ||
public boolean isClosed() { | ||
return mBlockReader.isClosed(); | ||
} | ||
|
||
@Override | ||
public String getLocation() { | ||
return mBlockReader.getLocation(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return mBlockReader.toString(); | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
mBlockReader.close(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,16 +12,24 @@ | |
package alluxio.worker.page; | ||
|
||
import alluxio.conf.PropertyKey; | ||
import alluxio.exception.runtime.AlluxioRuntimeException; | ||
import alluxio.exception.status.NotFoundException; | ||
import alluxio.exception.status.UnavailableException; | ||
import alluxio.metrics.MetricInfo; | ||
import alluxio.metrics.MetricKey; | ||
import alluxio.metrics.MetricsSystem; | ||
import alluxio.network.protocol.databuffer.NioDirectBufferPool; | ||
import alluxio.resource.CloseableResource; | ||
import alluxio.underfs.UfsManager; | ||
import alluxio.underfs.UnderFileSystem; | ||
import alluxio.underfs.options.OpenOptions; | ||
import alluxio.util.IdUtils; | ||
import alluxio.worker.block.UfsInputStreamCache; | ||
import alluxio.worker.block.UnderFileSystemBlockStore.BytesReadMetricKey; | ||
import alluxio.worker.block.io.BlockReader; | ||
import alluxio.worker.block.meta.BlockMeta; | ||
|
||
import com.codahale.metrics.Counter; | ||
import com.google.common.base.Preconditions; | ||
import io.netty.buffer.ByteBuf; | ||
|
||
|
@@ -31,6 +39,8 @@ | |
import java.nio.channels.Channels; | ||
import java.nio.channels.ClosedChannelException; | ||
import java.nio.channels.ReadableByteChannel; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.ConcurrentMap; | ||
|
||
/** | ||
* Block reader that reads from UFS. | ||
|
@@ -47,6 +57,9 @@ public class PagedUfsBlockReader extends BlockReader { | |
private long mLastPageIndex = -1; | ||
private boolean mClosed = false; | ||
private long mPosition; | ||
private final ConcurrentMap<BytesReadMetricKey, Counter> mUfsBytesReadMetrics = | ||
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. elements are only inserted into this map, but never queried 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. This map is used by mUfsBytesReadMetrics.computeIfAbsent(). |
||
new ConcurrentHashMap<>(); | ||
private final Counter mUfsBytesRead; | ||
|
||
/** | ||
* @param ufsManager | ||
|
@@ -70,6 +83,23 @@ public PagedUfsBlockReader(UfsManager ufsManager, | |
mInitialOffset = offset; | ||
mLastPage = ByteBuffer.allocateDirect((int) mPageSize); | ||
mPosition = offset; | ||
try { | ||
UfsManager.UfsClient ufsClient = mUfsManager.get(mUfsBlockOptions.getMountId()); | ||
mUfsBytesRead = mUfsBytesReadMetrics.computeIfAbsent( | ||
new BytesReadMetricKey(ufsClient.getUfsMountPointUri(), mUfsBlockOptions.getUser()), | ||
key -> key.mUser == null | ||
? MetricsSystem.counterWithTags( | ||
MetricKey.WORKER_BYTES_READ_UFS.getName(), | ||
MetricKey.WORKER_BYTES_READ_UFS.isClusterAggregated(), | ||
MetricInfo.TAG_UFS, MetricsSystem.escape(key.mUri)) | ||
: MetricsSystem.counterWithTags( | ||
MetricKey.WORKER_BYTES_READ_UFS.getName(), | ||
MetricKey.WORKER_BYTES_READ_UFS.isClusterAggregated(), | ||
MetricInfo.TAG_UFS, MetricsSystem.escape(key.mUri), | ||
MetricInfo.TAG_USER, key.mUser)); | ||
} catch (UnavailableException | NotFoundException e) { | ||
throw AlluxioRuntimeException.from(e); | ||
} | ||
} | ||
|
||
@Override | ||
|
@@ -145,6 +175,7 @@ public int readPageAtIndex(ByteBuffer buffer, long pageIndex) throws IOException | |
mLastPage.flip(); | ||
mLastPageIndex = pageIndex; | ||
fillWithCachedPage(buffer, pageIndex * mPageSize, totalBytesRead); | ||
mUfsBytesRead.inc(totalBytesRead); | ||
return totalBytesRead; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 see the metrics are updated in page store only. If the user uses the block store, then these
bytesReadCache + bytesReadUfs
will be zero. Can you also update the metrics in the block store?