-
Notifications
You must be signed in to change notification settings - Fork 9.2k
HDFS-14750. RBF: Support dynamic handler allocation in routers #4199
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 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4649fdb
Add DynamicRouterRpcFairnessPolicyController
0f02090
Minor changes and add config to hdfs-rbf-default.xml
80aa59d
Fix checkstyle
50f18c0
Add metrics for max handler capacity per ns
0f83aa3
Add configurable minimum handler count per namespace
60f7b03
Minor config fixes
8f31e08
Remove unused import
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
139 changes: 139 additions & 0 deletions
139
...ache/hadoop/hdfs/server/federation/fairness/DynamicRouterRpcFairnessPolicyController.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,139 @@ | ||
| /** | ||
| * 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 | ||
| * <p> | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * <p> | ||
| * 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.hdfs.server.federation.fairness; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import java.util.concurrent.ScheduledExecutorService; | ||
| import java.util.concurrent.ScheduledFuture; | ||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| import org.apache.hadoop.thirdparty.com.google.common.util.concurrent.ThreadFactoryBuilder; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import org.apache.hadoop.classification.VisibleForTesting; | ||
| import org.apache.hadoop.conf.Configuration; | ||
| import org.apache.hadoop.hdfs.server.federation.utils.AdjustableSemaphore; | ||
| import org.apache.hadoop.util.concurrent.HadoopExecutors; | ||
|
|
||
| import static org.apache.hadoop.hdfs.server.federation.router.RBFConfigKeys.DFS_ROUTER_DYNAMIC_FAIRNESS_CONTROLLER_REFRESH_INTERVAL_DEFAULT; | ||
| import static org.apache.hadoop.hdfs.server.federation.router.RBFConfigKeys.DFS_ROUTER_DYNAMIC_FAIRNESS_CONTROLLER_REFRESH_INTERVAL_KEY; | ||
| import static org.apache.hadoop.hdfs.server.federation.router.RBFConfigKeys.DFS_ROUTER_HANDLER_COUNT_DEFAULT; | ||
| import static org.apache.hadoop.hdfs.server.federation.router.RBFConfigKeys.DFS_ROUTER_HANDLER_COUNT_KEY; | ||
|
|
||
| /** | ||
| * Dynamic fairness policy extending {@link StaticRouterRpcFairnessPolicyController} | ||
| * and fetching handlers from configuration for all available name services. | ||
| * The handlers count changes according to traffic to namespaces. | ||
| * Total handlers might NOT strictly add up to the value defined by DFS_ROUTER_HANDLER_COUNT_KEY. | ||
| */ | ||
| public class DynamicRouterRpcFairnessPolicyController | ||
| extends StaticRouterRpcFairnessPolicyController { | ||
|
|
||
| private static final Logger LOG = | ||
| LoggerFactory.getLogger(DynamicRouterRpcFairnessPolicyController.class); | ||
|
|
||
| private static final ScheduledExecutorService scheduledExecutor = HadoopExecutors | ||
| .newSingleThreadScheduledExecutor(new ThreadFactoryBuilder().setDaemon(true) | ||
| .setNameFormat("DynamicRouterRpcFairnessPolicyControllerPermitsResizer").build()); | ||
| private PermitsResizerService permitsResizerService; | ||
| private ScheduledFuture<?> refreshTask; | ||
| private int handlerCount; | ||
|
|
||
| /** | ||
| * Initializes using the same logic as {@link StaticRouterRpcFairnessPolicyController} | ||
| * and starts a periodic semaphore resizer thread | ||
| * | ||
| * @param conf configuration | ||
| */ | ||
| public DynamicRouterRpcFairnessPolicyController(Configuration conf) { | ||
| super(conf); | ||
| handlerCount = conf.getInt(DFS_ROUTER_HANDLER_COUNT_KEY, DFS_ROUTER_HANDLER_COUNT_DEFAULT); | ||
| long refreshInterval = | ||
| conf.getTimeDuration(DFS_ROUTER_DYNAMIC_FAIRNESS_CONTROLLER_REFRESH_INTERVAL_KEY, | ||
| DFS_ROUTER_DYNAMIC_FAIRNESS_CONTROLLER_REFRESH_INTERVAL_DEFAULT, TimeUnit.MILLISECONDS); | ||
| permitsResizerService = new PermitsResizerService(); | ||
| refreshTask = scheduledExecutor | ||
| .scheduleWithFixedDelay(permitsResizerService, refreshInterval, refreshInterval, | ||
| TimeUnit.MILLISECONDS); | ||
| } | ||
|
|
||
| @VisibleForTesting | ||
| public DynamicRouterRpcFairnessPolicyController(Configuration conf, long refreshInterval) { | ||
| super(conf); | ||
| handlerCount = conf.getInt(DFS_ROUTER_HANDLER_COUNT_KEY, DFS_ROUTER_HANDLER_COUNT_DEFAULT); | ||
| permitsResizerService = new PermitsResizerService(); | ||
| refreshTask = scheduledExecutor | ||
| .scheduleWithFixedDelay(permitsResizerService, refreshInterval, refreshInterval, | ||
| TimeUnit.MILLISECONDS); | ||
| } | ||
|
|
||
| @VisibleForTesting | ||
| public void refreshPermitsCap() { | ||
| permitsResizerService.run(); | ||
| } | ||
|
|
||
| @Override | ||
| public void shutdown() { | ||
| super.shutdown(); | ||
| if (refreshTask != null) { | ||
| refreshTask.cancel(true); | ||
| } | ||
| if (scheduledExecutor != null) { | ||
| scheduledExecutor.shutdown(); | ||
| } | ||
| } | ||
|
|
||
| class PermitsResizerService implements Runnable { | ||
|
|
||
| @Override | ||
| public synchronized void run() { | ||
| long totalOps = 0; | ||
| Map<String, Long> nsOps = new HashMap<>(); | ||
| for (Map.Entry<String, AdjustableSemaphore> entry : permits.entrySet()) { | ||
| long ops = (rejectedPermitsPerNs.containsKey(entry.getKey()) ? | ||
| rejectedPermitsPerNs.get(entry.getKey()).longValue() : | ||
| 0) + (acceptedPermitsPerNs.containsKey(entry.getKey()) ? | ||
| acceptedPermitsPerNs.get(entry.getKey()).longValue() : | ||
| 0); | ||
| nsOps.put(entry.getKey(), ops); | ||
| totalOps += ops; | ||
| } | ||
|
|
||
| for (Map.Entry<String, AdjustableSemaphore> entry : permits.entrySet()) { | ||
| String ns = entry.getKey(); | ||
| AdjustableSemaphore semaphore = entry.getValue(); | ||
| int oldPermitCap = permitSizes.get(ns); | ||
| int newPermitCap = (int) Math.ceil((float) nsOps.get(ns) / totalOps * handlerCount); | ||
| // Leave at least 1 handler even if there's no traffic | ||
| if (newPermitCap == 0) { | ||
| newPermitCap = 1; | ||
|
kokonguyen191 marked this conversation as resolved.
Outdated
|
||
| } | ||
| permitSizes.put(ns, newPermitCap); | ||
| if (newPermitCap > oldPermitCap) { | ||
| semaphore.release(newPermitCap - oldPermitCap); | ||
| } else if (newPermitCap < oldPermitCap) { | ||
| semaphore.reducePermits(oldPermitCap - newPermitCap); | ||
| } | ||
| LOG.info("Resized handlers for nsId {} from {} to {}", ns, oldPermitCap, newPermitCap); | ||
| } | ||
| } | ||
| } | ||
| } | ||
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
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
36 changes: 36 additions & 0 deletions
36
...rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/utils/AdjustableSemaphore.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,36 @@ | ||
| /** | ||
| * 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 | ||
| * <p> | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * <p> | ||
| * 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.hdfs.server.federation.utils; | ||
|
|
||
| import java.util.concurrent.Semaphore; | ||
|
|
||
| public class AdjustableSemaphore extends Semaphore { | ||
|
|
||
| public AdjustableSemaphore(int permits) { | ||
| super(permits); | ||
| } | ||
|
|
||
| public AdjustableSemaphore(int permits, boolean fair) { | ||
| super(permits, fair); | ||
| } | ||
|
|
||
| public void reducePermits(int reduction) { | ||
| super.reducePermits(reduction); | ||
| } | ||
| } |
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.