pranavsaxena-microsoft commented on code in PR #5034: URL: https://github.com/apache/hadoop/pull/5034#discussion_r999250421
########## hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsClientThrottlingInterceptFactory.java: ########## @@ -0,0 +1,71 @@ +/** + * 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.fs.azurebfs.services; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import org.apache.hadoop.fs.azurebfs.AbfsConfiguration; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Class to get an instance of throttling intercept class per account. + */ +final class AbfsClientThrottlingInterceptFactory { + + private AbfsClientThrottlingInterceptFactory() { + } + + private static final Logger LOG = LoggerFactory.getLogger( + AbfsClientThrottlingInterceptFactory.class); + + // Map which stores instance of ThrottlingIntercept class per account + private static Map<String, AbfsClientThrottlingIntercept> instanceMapping + = new ConcurrentHashMap<>(); + + /** + * Returns an instance of AbfsClientThrottlingIntercept. + * + * @param accountName The account for which we need instance of throttling intercept + @param abfsConfiguration The object of abfsconfiguration class + * @return Instance of AbfsClientThrottlingIntercept class + */ + static synchronized AbfsClientThrottlingIntercept getInstance(String accountName, + AbfsConfiguration abfsConfiguration) { + AbfsClientThrottlingIntercept instance; + if (!abfsConfiguration.isAutoThrottlingEnabled()) { + return null; + } + // If singleton is enabled use a static instance of the intercept class for all accounts + if (!abfsConfiguration.isAccountThrottlingEnabled()) { + instance = AbfsClientThrottlingIntercept.initializeSingleton(abfsConfiguration); + } else { + // Return the instance from the map + if (instanceMapping.get(accountName) == null) { + LOG.debug("The accountName is: {} ", accountName); + instance = new AbfsClientThrottlingIntercept(accountName, abfsConfiguration); + instanceMapping.put(accountName, instance); + } else { + instance = instanceMapping.get(accountName); + } Review Comment: Lets have something like: ``` AbfsClientThrottlingIntercept intercept = instanceMapping.get(accountName); if(intercept == null) { intercept = new AbfsClientThrottlingIntercept(accountName, abfsConfiguration); instanceMapping.put(accountName, intercept); } return intercept ; ``` ########## hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsClientThrottlingAnalyzer.java: ########## @@ -104,19 +113,24 @@ private AbfsClientThrottlingAnalyzer() { public void addBytesTransferred(long count, boolean isFailedOperation) { AbfsOperationMetrics metrics = blobMetrics.get(); if (isFailedOperation) { - metrics.bytesFailed.addAndGet(count); - metrics.operationsFailed.incrementAndGet(); + metrics.getBytesFailed().addAndGet(count); + metrics.getOperationsFailed().incrementAndGet(); } else { - metrics.bytesSuccessful.addAndGet(count); - metrics.operationsSuccessful.incrementAndGet(); + metrics.getBytesSuccessful().addAndGet(count); + metrics.getOperationsSuccessful().incrementAndGet(); } + blobMetrics.set(metrics); } /** * Suspends the current storage operation, as necessary, to reduce throughput. * @return true if Thread sleeps(Throttling occurs) else false. */ public boolean suspendIfNecessary() { + if (isOperationOnAccountIdle.get()) { + resumeTimer(); + } Review Comment: Race condition alert: Should we recall this piece of code after sleep. Reason being, lets say the timerTask is going to setIdle as true, and just before that, another thread comes into suspendIfNecessary -> if will read false and go on to sleep. Now after sleep, what ever metric will be created due to API call, that shall be dropped as on the next API call, resumeTimer would have been called which would need to creation of new blobMetrics. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
