-
Notifications
You must be signed in to change notification settings - Fork 3.4k
HBASE-22975 Add read and write QPS metrics at server level and table level #615
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
Changes from all commits
Commits
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
53 changes: 53 additions & 0 deletions
53
...oop-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsTableQueryMeter.java
This file contains hidden or 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,53 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to you under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.hadoop.hbase.regionserver; | ||
|
|
||
| import org.apache.hadoop.hbase.TableName; | ||
| import org.apache.yetus.audience.InterfaceAudience; | ||
|
|
||
| /** | ||
| * Query Per Second for each table in a RegionServer. | ||
| */ | ||
| @InterfaceAudience.Private | ||
| public interface MetricsTableQueryMeter { | ||
|
|
||
| /** | ||
| * Update table read QPS | ||
| * @param tableName The table the metric is for | ||
| * @param count Number of occurrences to record | ||
| */ | ||
| void updateTableReadQueryMeter(TableName tableName, long count); | ||
|
|
||
| /** | ||
| * Update table read QPS | ||
| * @param tableName The table the metric is for | ||
| */ | ||
| void updateTableReadQueryMeter(TableName tableName); | ||
|
|
||
| /** | ||
| * Update table write QPS | ||
| * @param tableName The table the metric is for | ||
| * @param count Number of occurrences to record | ||
| */ | ||
| void updateTableWriteQueryMeter(TableName tableName, long count); | ||
|
|
||
| /** | ||
| * Update table write QPS | ||
| * @param tableName The table the metric is for | ||
| */ | ||
| void updateTableWriteQueryMeter(TableName tableName); | ||
| } |
This file contains hidden or 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
102 changes: 102 additions & 0 deletions
102
...compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsTableQueryMeterImpl.java
This file contains hidden or 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,102 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to you under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.hadoop.hbase.regionserver; | ||
|
|
||
| import java.util.Map; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
|
|
||
| import org.apache.hadoop.hbase.TableName; | ||
| import org.apache.hadoop.hbase.metrics.Meter; | ||
| import org.apache.hadoop.hbase.metrics.MetricRegistry; | ||
| import org.apache.yetus.audience.InterfaceAudience; | ||
|
|
||
| /** | ||
| * Implementation of {@link MetricsTableQueryMeter} to track query per second for each table in | ||
| * a RegionServer. | ||
| */ | ||
| @InterfaceAudience.Private | ||
| public class MetricsTableQueryMeterImpl implements MetricsTableQueryMeter { | ||
| private final Map<TableName, TableMeters> metersByTable = new ConcurrentHashMap<>(); | ||
| private final MetricRegistry metricRegistry; | ||
|
|
||
| private final static String TABLE_READ_QUERY_PER_SECOND = "tableReadQueryPerSecond"; | ||
| private final static String TABLE_WRITE_QUERY_PER_SECOND = "tableWriteQueryPerSecond"; | ||
|
|
||
| public MetricsTableQueryMeterImpl(MetricRegistry metricRegistry) { | ||
| this.metricRegistry = metricRegistry; | ||
| } | ||
|
|
||
| private static class TableMeters { | ||
| final Meter tableReadQueryMeter; | ||
| final Meter tableWriteQueryMeter; | ||
|
|
||
| TableMeters(MetricRegistry metricRegistry, TableName tableName) { | ||
| this.tableReadQueryMeter = metricRegistry.meter(qualifyMetricsName(tableName, | ||
| TABLE_READ_QUERY_PER_SECOND)); | ||
| this.tableWriteQueryMeter = | ||
| metricRegistry.meter(qualifyMetricsName(tableName, TABLE_WRITE_QUERY_PER_SECOND)); | ||
| } | ||
|
|
||
| public void updateTableReadQueryMeter(long count) { | ||
| tableReadQueryMeter.mark(count); | ||
| } | ||
|
|
||
| public void updateTableReadQueryMeter() { | ||
| tableReadQueryMeter.mark(); | ||
| } | ||
|
|
||
| public void updateTableWriteQueryMeter(long count) { | ||
| tableWriteQueryMeter.mark(count); | ||
| } | ||
|
|
||
| public void updateTableWriteQueryMeter() { | ||
| tableWriteQueryMeter.mark(); | ||
| } | ||
| } | ||
|
|
||
| private static String qualifyMetricsName(TableName tableName, String metric) { | ||
| StringBuilder sb = new StringBuilder(); | ||
| sb.append("Namespace_").append(tableName.getNamespaceAsString()); | ||
| sb.append("_table_").append(tableName.getQualifierAsString()); | ||
| sb.append("_metric_").append(metric); | ||
| return sb.toString(); | ||
| } | ||
|
|
||
| private TableMeters getOrCreateTableMeter(TableName tableName) { | ||
| return metersByTable.computeIfAbsent(tableName, tbn -> new TableMeters(metricRegistry, tbn)); | ||
| } | ||
|
|
||
| @Override | ||
| public void updateTableReadQueryMeter(TableName tableName, long count) { | ||
| getOrCreateTableMeter(tableName).updateTableReadQueryMeter(count); | ||
| } | ||
|
|
||
| @Override | ||
| public void updateTableReadQueryMeter(TableName tableName) { | ||
| getOrCreateTableMeter(tableName).updateTableReadQueryMeter(); | ||
| } | ||
|
|
||
| @Override | ||
| public void updateTableWriteQueryMeter(TableName tableName, long count) { | ||
| getOrCreateTableMeter(tableName).updateTableWriteQueryMeter(count); | ||
| } | ||
|
|
||
| @Override | ||
| public void updateTableWriteQueryMeter(TableName tableName) { | ||
| getOrCreateTableMeter(tableName).updateTableWriteQueryMeter(); | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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.
Doc is wrong? Not for one table?