You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hbase.apache.org by GitBox <gi...@apache.org> on 2022/09/26 11:22:07 UTC

[GitHub] [hbase] wchevreuil commented on a diff in pull request #4799: HBASE-27389 Add cost function in balancer to consider the cost of bui…

wchevreuil commented on code in PR #4799:
URL: https://github.com/apache/hbase/pull/4799#discussion_r979840582


##########
hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/PrefetchCacheCostFunction.java:
##########
@@ -0,0 +1,79 @@
+/*
+ * 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.master.balancer;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.yetus.audience.InterfaceAudience;
+
+/**
+ * Compute the cost of a potential cluster configuration based on the number of HFile's already
+ * cached in the bucket cache
+ */
+@InterfaceAudience.Private
+public class PrefetchCacheCostFunction extends CostFunction {
+  private String prefetchedFileListPath;
+  private float prefetchRatio;
+  private float bestPrefetchRatio;
+
+  public static final String PREFETCH_PERSISTENCE_PATH_KEY = "hbase.prefetch.file-list.path";

Review Comment:
   nit: import static CacheConfig.PREFETCH_PERSISTENCE_PATH_KEY



##########
hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/BalancerClusterState.java:
##########
@@ -553,6 +558,61 @@ enum LocalityType {
     RACK
   }
 
+  public float getOrComputeWeightedPrefetchRatio(int region, int server) {
+    return getRegionSizeMB(region) * getOrComputeRegionPrefetchRatio()[region][server];
+  }
+
+  private float[][] getOrComputeRegionPrefetchRatio() {
+    if (regionServerWithBestPrefetchRatio == null || regionServerPrefetchRatio == null) {
+      computeRegionServerPrefetchRatio();
+    }
+    return regionServerPrefetchRatio;
+  }
+
+  public int[] getOrComputeServerWithBestPrefetchRatio() {
+    if (regionServerWithBestPrefetchRatio == null || regionServerPrefetchRatio == null) {
+      computeRegionServerPrefetchRatio();
+    }
+    return regionServerWithBestPrefetchRatio;
+  }
+
+  private void computeRegionServerPrefetchRatio() {
+    regionServerPrefetchRatio = new float[numRegions][numServers];
+    regionServerWithBestPrefetchRatio = new int[numRegions];
+
+    for (int region = 0; region < numRegions; region++) {
+      float bestPrefetchRatio = 0.0f;
+      int serverWithBestPrefetchRatio = 0;
+      for (int server = 0; server < numServers; server++) {

Review Comment:
   Shouldn't we be iterating through servers first, then going through the regions on each of the servers? The way we are doing now, we may be over iterating through servers that don't hold the current region.



##########
hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/StochasticLoadBalancer.java:
##########
@@ -256,6 +262,7 @@ protected void loadConf(Configuration conf) {
     addCostFunction(new WriteRequestCostFunction(conf));
     addCostFunction(new MemStoreSizeCostFunction(conf));
     addCostFunction(new StoreFileCostFunction(conf));
+    addCostFunction(prefetchCacheCost);

Review Comment:
   Please update the class JavaDoc to mention this additional cost function.



##########
hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/PrefetchCacheCostFunction.java:
##########
@@ -0,0 +1,79 @@
+/*
+ * 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.master.balancer;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.yetus.audience.InterfaceAudience;
+
+/**
+ * Compute the cost of a potential cluster configuration based on the number of HFile's already
+ * cached in the bucket cache
+ */
+@InterfaceAudience.Private
+public class PrefetchCacheCostFunction extends CostFunction {
+  private String prefetchedFileListPath;
+  private float prefetchRatio;
+  private float bestPrefetchRatio;
+
+  public static final String PREFETCH_PERSISTENCE_PATH_KEY = "hbase.prefetch.file-list.path";
+
+  PrefetchCacheCostFunction(Configuration conf) {
+    prefetchedFileListPath = conf.get(PREFETCH_PERSISTENCE_PATH_KEY);
+    this.setMultiplier(prefetchedFileListPath == null ? 0 : 1);

Review Comment:
   Is this effectively disabling the feature if "hbase.prefetch.file-list.path" isn't set?



##########
hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/PrefetchBasedCandidateGenerator.java:
##########
@@ -0,0 +1,76 @@
+/*
+ * 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.master.balancer;
+
+import java.util.Optional;
+import java.util.concurrent.ThreadLocalRandom;
+import org.apache.yetus.audience.InterfaceAudience;
+
+@InterfaceAudience.Private
+class PrefetchBasedCandidateGenerator extends CandidateGenerator {

Review Comment:
   How the StochasticLoadBalancer picks this generator? From my readings, it seems it's selecting random generators. If so, does this mean we'll not always have an accurate prefetch ratio for the related cost function?



##########
hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/StochasticLoadBalancer.java:
##########
@@ -452,7 +459,10 @@ protected List<RegionPlan> balanceTable(TableName tableName,
     // Allow turning this feature off if the locality cost is not going to
     // be used in any computations.
     RegionHDFSBlockLocationFinder finder = null;
-    if ((this.localityCost != null) || (this.rackLocalityCost != null)) {
+    if (
+      (this.localityCost != null) || (this.rackLocalityCost != null)
+        || (this.prefetchCacheCost != null)

Review Comment:
   Do we need to care about locality for the prefetchCacheCost ?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hbase.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org