-
Couldn't load subscription status.
- Fork 3.4k
HBASE-27389 Add cost function in balancer to consider the cost of bui… #4799
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
Open
ragarkar
wants to merge
16
commits into
apache:master
Choose a base branch
from
ragarkar:prefetchcost
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
aa22468
HBASE-27389 Add cost function in balancer to consider the cost of bui…
ragarkar 54bacff
HBASE-27389 Add cost function in balancer to consider the cost of bui…
ragarkar 5c201ed
HBASE-27389 Add cost function in balancer to consider the cost of bui…
ragarkar 1669025
Merge branch 'master' into prefetchcost
ragarkar a53a3fc
HBASE-27389 Add cost function in balancer to consider the cost of bui…
ragarkar 826db46
HBASE-27389 Add cost function in balancer to consider the cost of bui…
ragarkar ab870c0
HBASE-27389 Add cost function in balancer to consider the cost of bui…
ragarkar a8dbcef
HBASE-27389 Add cost function in balancer to consider the cost of bui…
ragarkar 8645e93
HBASE-27389 Add cost function in balancer to consider the cost of bui…
ragarkar 3fcaa56
HBASE-27389 Add cost function in balancer to consider the cost of bui…
ragarkar e70cc66
Merge branch 'master' into prefetchcost
ragarkar af0181b
HBASE-27389 Add cost function in balancer to consider the cost of bui…
ragarkar cf7b3d2
HBASE-27389 Add cost function in balancer to consider the cost of bui…
ragarkar 1a7d728
HBASE-27389 Add cost function in balancer to consider the cost of bui…
ragarkar 160f484
HBASE-27389 Add cost function in balancer to consider the cost of bui…
ragarkar 55e55ea
HBASE-27389 Add cost function in balancer to consider the cost of bui…
ragarkar 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 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
56 changes: 56 additions & 0 deletions
56
...rc/main/java/org/apache/hadoop/hbase/master/balancer/PrefetchBasedCandidateGenerator.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,56 @@ | ||
| /* | ||
| * 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.concurrent.ThreadLocalRandom; | ||
| import org.apache.yetus.audience.InterfaceAudience; | ||
|
|
||
| @InterfaceAudience.Private | ||
| class PrefetchBasedCandidateGenerator extends CandidateGenerator { | ||
wchevreuil marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| private static float PREFETCH_RATIO_DIFF_FACTOR = 1.25f; | ||
|
|
||
| @Override | ||
| BalanceAction generate(BalancerClusterState cluster) { | ||
| // iterate through regions until you find one that is not on ideal host | ||
| // start from a random point to avoid always balance the regions in front | ||
| if (cluster.numRegions > 0) { | ||
| int startRegionIndex = ThreadLocalRandom.current().nextInt(cluster.numRegions); | ||
| int toServerIndex; | ||
| for (int i = 0; i < cluster.numRegions; i++) { | ||
| int region = (startRegionIndex + i) % cluster.numRegions; | ||
| int currentServerIndex = cluster.regionIndexToServerIndex[region]; | ||
| float currentPrefetchRatio = | ||
| cluster.getOrComputeWeightedPrefetchRatio(region, currentServerIndex); | ||
|
|
||
| // Check if there is a server with a better historical prefetch ratio | ||
| toServerIndex = pickOtherRandomServer(cluster, currentServerIndex); | ||
| float toServerPrefetchRatio = | ||
| cluster.getOrComputeWeightedPrefetchRatio(region, toServerIndex); | ||
|
|
||
| // If the prefetch ratio on the target server is significantly higher, move the region. | ||
| if ( | ||
| currentPrefetchRatio > 0 | ||
| && (toServerPrefetchRatio / currentPrefetchRatio) > PREFETCH_RATIO_DIFF_FACTOR | ||
| ) { | ||
| return getAction(currentServerIndex, region, toServerIndex, -1); | ||
| } | ||
| } | ||
| } | ||
| return BalanceAction.NULL_ACTION; | ||
| } | ||
| } | ||
89 changes: 89 additions & 0 deletions
89
...ncer/src/main/java/org/apache/hadoop/hbase/master/balancer/PrefetchCacheCostFunction.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,89 @@ | ||
| /* | ||
| * 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.hadoop.hbase.HConstants; | ||
| 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 static final String PREFETCH_CACHE_COST_KEY = | ||
| "hbase.master.balancer.stochastic.prefetchCacheCost"; | ||
| private static final float DEFAULT_PREFETCH_COST = 500; | ||
|
|
||
| private String prefetchedFileListPath; | ||
| private double prefetchRatio; | ||
| private double bestPrefetchRatio; | ||
|
|
||
| /** | ||
| * The prefetch cache cost function is enabled only when the prefetch file list persistence is | ||
| * enabled by setting the parameter PREFETCH_PERSISTENCE_PATH_KEY. The prefetch file list | ||
| * persistence is disabled by default. The prefetch cache cost function is also disabled if the | ||
| * multiplier is set to 0. The prefetch cache ratio function would be most relevant for non-hdfs | ||
| * deployments, which then makes locality irrelevant. In those cases, prefetch and region skewness | ||
| * would be competing to prevail over the final balancer decision. | ||
| * @param conf Cluster configuration | ||
| */ | ||
| PrefetchCacheCostFunction(Configuration conf) { | ||
| prefetchedFileListPath = conf.get(HConstants.PREFETCH_PERSISTENCE_PATH_KEY); | ||
| this.setMultiplier(prefetchedFileListPath == null | ||
| ? 0.0f | ||
| : conf.getFloat(PREFETCH_CACHE_COST_KEY, DEFAULT_PREFETCH_COST)); | ||
| prefetchRatio = 0.0; | ||
| bestPrefetchRatio = 0.0; | ||
| } | ||
|
|
||
| @Override | ||
| void prepare(BalancerClusterState cluster) { | ||
| super.prepare(cluster); | ||
| prefetchRatio = 0.0; | ||
| bestPrefetchRatio = 0.0; | ||
|
|
||
| for (int region = 0; region < cluster.numRegions; region++) { | ||
| prefetchRatio += | ||
| cluster.getOrComputeWeightedPrefetchRatio(region, cluster.regionIndexToServerIndex[region]); | ||
| bestPrefetchRatio += cluster.getOrComputeWeightedPrefetchRatio(region, | ||
| cluster.getOrComputeServerWithBestPrefetchRatio()[region]); | ||
| } | ||
| prefetchRatio = bestPrefetchRatio == 0.0 ? 1.0 : prefetchRatio / bestPrefetchRatio; | ||
| } | ||
|
|
||
| @Override | ||
| protected double cost() { | ||
| return scale(0, 1, (1 - prefetchRatio)); | ||
| } | ||
|
|
||
| @Override | ||
| protected void regionMoved(int region, int oldServer, int newServer) { | ||
| double oldServerPrefetch = cluster.getOrComputeWeightedPrefetchRatio(region, oldServer); | ||
| double newServerPrefetch = cluster.getOrComputeWeightedPrefetchRatio(region, newServer); | ||
| double prefetchDelta = newServerPrefetch - oldServerPrefetch; | ||
| double normalizeDelta = bestPrefetchRatio == 0.0 ? 0.0 : prefetchDelta / bestPrefetchRatio; | ||
| prefetchRatio += normalizeDelta; | ||
| } | ||
|
|
||
| @Override | ||
| public final void updateWeight(double[] weights) { | ||
| weights[StochasticLoadBalancer.GeneratorType.PREFETCH.ordinal()] += cost(); | ||
| } | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.