somandal commented on code in PR #14894: URL: https://github.com/apache/pinot/pull/14894#discussion_r1927893736
########## pinot-segment-local/src/main/java/org/apache/pinot/segment/local/utils/SegmentPreprocessThrottler.java: ########## @@ -0,0 +1,147 @@ +/** + * 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.pinot.segment.local.utils; + +import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Preconditions; +import java.util.Map; +import org.apache.pinot.common.concurrency.AdjustableSemaphore; +import org.apache.pinot.spi.config.provider.PinotClusterConfigChangeListener; +import org.apache.pinot.spi.utils.CommonConstants; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * Used to throttle the total concurrent index rebuilds that can happen on a given Pinot server. + * Code paths that do no need to rebuild the index or which don't happen on the server need not utilize this throttler. + */ +public class SegmentPreprocessThrottler implements PinotClusterConfigChangeListener { + private static final Logger LOGGER = LoggerFactory.getLogger(SegmentPreprocessThrottler.class); + + /** + * _maxPreprocessConcurrency must be >= 0. To effectively disable throttling, this can be set to a very high value + */ + private int _maxPreprocessConcurrency; + private boolean _relaxThrottling; + private final AdjustableSemaphore _semaphore; + + /** + * @param maxPreprocessConcurrency configured preprocessing concurrency + * @param maxConcurrentPreprocessesBeforeServingQueries configured preprocessing concurrency before serving queries + * @param relaxThrottling whether to relax throttling prior to serving queries + */ + public SegmentPreprocessThrottler(int maxPreprocessConcurrency, int maxConcurrentPreprocessesBeforeServingQueries, + boolean relaxThrottling) { + LOGGER.info("Initializing SegmentPreprocessThrottler, maxPreprocessConcurrency: {}, " + + "maxConcurrentPreprocessesBeforeServingQueries: {}, relaxThrottling: {}", + maxPreprocessConcurrency, maxConcurrentPreprocessesBeforeServingQueries, relaxThrottling); + Preconditions.checkArgument(maxPreprocessConcurrency > 0, + "Max preprocess parallelism must be >= 0, but found to be: " + maxPreprocessConcurrency); + Preconditions.checkArgument(maxConcurrentPreprocessesBeforeServingQueries > 0, + "Max preprocess parallelism before serving queries must be >= 0, but found to be: " + + maxConcurrentPreprocessesBeforeServingQueries); + + _maxPreprocessConcurrency = maxPreprocessConcurrency; + _relaxThrottling = relaxThrottling; + + // maxConcurrentPreprocessesBeforeServingQueries is only used prior to serving queries and once the server is + // ready to serve queries this is not used again. Thus, it is safe to only pick up this configuration during + // server startup. There is no need to allow updates to this via the ZK CLUSTER config handler + int relaxThrottlingThreshold = Math.max(_maxPreprocessConcurrency, maxConcurrentPreprocessesBeforeServingQueries); + int preprocessConcurrency = _maxPreprocessConcurrency; + if (relaxThrottling) { Review Comment: The idea is to use a higher threshold for the preprocess parallelism before the server starts serving queries. Just before we mark the server as available to handle queries, we want to reduce the parallelism, and in that call I set this `relaxThrottling` to `false`. Internally I use this flag to track whether I can safely change the ZK cluster config value or not (I don't change it until we have marked this flag as false). Does that make sense? I've kept this as an option to pass in for testing purposes (e.g. to ensure the correct values are set when this is set to 'true' vs. 'false'). Also in case there is a scenario where we don't want to allow this kind of toggle, I thought Iet the caller configure (if we use this class elsewhere in the future) Let me know if you think I shouldn't expose this flag and just keep it internal to the class, I can do that too if preferred. -- 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: commits-unsubscr...@pinot.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org