Skip to content

Commit

Permalink
HDFS-17713. [ARR] Throtting asynchronous calls for each nameservice.
Browse files Browse the repository at this point in the history
  • Loading branch information
hfutatzhanghb committed Jan 21, 2025
1 parent 8efd978 commit 54fa4eb
Show file tree
Hide file tree
Showing 5 changed files with 237 additions and 50 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* 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.hdfs.server.federation.fairness;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hdfs.server.federation.router.FederationUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Set;

import static org.apache.hadoop.hdfs.server.federation.router.RBFConfigKeys.
DFS_ROUTER_ASYNC_RPC_MAX_ASYNCCALL_PERMIT_KEY;
import static org.apache.hadoop.hdfs.server.federation.router.RBFConfigKeys.
DFS_ROUTER_ASYNC_RPC_MAX_ASYNC_CALL_PERMIT_DEFAULT;

public class RouterAsyncRpcFairnessPolicyController extends
AbstractRouterRpcFairnessPolicyController {

private static final Logger LOG =
LoggerFactory.getLogger(RouterAsyncRpcFairnessPolicyController.class);

public RouterAsyncRpcFairnessPolicyController(Configuration conf) {
init(conf);
}

public void init(Configuration conf) throws IllegalArgumentException {
super.init(conf);

int maxAsyncCallPermit = conf.getInt(DFS_ROUTER_ASYNC_RPC_MAX_ASYNCCALL_PERMIT_KEY,
DFS_ROUTER_ASYNC_RPC_MAX_ASYNC_CALL_PERMIT_DEFAULT);
if (maxAsyncCallPermit <= 0) {
maxAsyncCallPermit = DFS_ROUTER_ASYNC_RPC_MAX_ASYNC_CALL_PERMIT_DEFAULT;
}
LOG.info("Max async call permits per nameservice: {}", maxAsyncCallPermit);

// Get all name services configured
Set<String> allConfiguredNS = FederationUtil.getAllConfiguredNS(conf);

for (String nsId : allConfiguredNS) {
LOG.info("Dedicated permits {} for ns {} ", maxAsyncCallPermit, nsId);
insertNameServiceWithPermits(nsId, maxAsyncCallPermit);
logAssignment(nsId, maxAsyncCallPermit);
}
}

private static void logAssignment(String nsId, int count) {
LOG.info("Assigned {} permits to nsId {} ", count, nsId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ public class RBFConfigKeys extends CommonConfigurationKeysPublic {
public static final String DFS_ROUTER_ASYNC_RPC_RESPONDER_COUNT_KEY =
FEDERATION_ROUTER_ASYNC_RPC_PREFIX + "responder.count";
public static final int DFS_ROUTER_ASYNCRPC_RESPONDER_COUNT_DEFAULT = 10;
public static final String DFS_ROUTER_ASYNC_RPC_MAX_ASYNCCALL_PERMIT_KEY =
FEDERATION_ROUTER_ASYNC_RPC_PREFIX + "max.asynccall.permit";
public static final int DFS_ROUTER_ASYNC_RPC_MAX_ASYNC_CALL_PERMIT_DEFAULT = 20000;

public static final String DFS_ROUTER_METRICS_ENABLE =
FEDERATION_ROUTER_PREFIX + "metrics.enable";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1880,7 +1880,7 @@ protected void releasePermit(final String nsId, final UserGroupInformation ugi,
return routerRpcFairnessPolicyController;
}

private void incrRejectedPermitForNs(String ns) {
protected void incrRejectedPermitForNs(String ns) {
rejectedPermitsPerNs.computeIfAbsent(ns, k -> new LongAdder()).increment();
}

Expand All @@ -1889,7 +1889,7 @@ public Long getRejectedPermitForNs(String ns) {
rejectedPermitsPerNs.get(ns).longValue() : 0L;
}

private void incrAcceptedPermitForNs(String ns) {
protected void incrAcceptedPermitForNs(String ns) {
acceptedPermitsPerNs.computeIfAbsent(ns, k -> new LongAdder()).increment();
}

Expand Down
Loading

0 comments on commit 54fa4eb

Please sign in to comment.