Fly-Style commented on code in PR #18819: URL: https://github.com/apache/druid/pull/18819#discussion_r2605800955
########## indexing-service/src/main/java/org/apache/druid/indexing/seekablestream/supervisor/autoscaler/CostBasedAutoScalerConfig.java: ########## @@ -0,0 +1,410 @@ +/* + * 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.druid.indexing.seekablestream.supervisor.autoscaler; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.google.common.base.Preconditions; +import org.apache.druid.indexing.overlord.supervisor.Supervisor; +import org.apache.druid.indexing.overlord.supervisor.SupervisorSpec; +import org.apache.druid.indexing.overlord.supervisor.autoscaler.SupervisorTaskAutoScaler; +import org.apache.druid.indexing.seekablestream.supervisor.SeekableStreamSupervisor; +import org.apache.druid.java.util.emitter.service.ServiceEmitter; + +import javax.annotation.Nullable; +import java.util.Objects; + +/** + * Configuration for cost-based auto-scaling of seekable stream supervisor tasks. + * Uses a cost function combining lag and idle time metrics to determine optimal task counts. + * Task counts are constrained to be factors/divisors of the partition count. + */ +@JsonInclude(JsonInclude.Include.NON_NULL) +public class CostBasedAutoScalerConfig implements AutoScalerConfig +{ + private static final long DEFAULT_METRICS_COLLECTION_INTERVAL_MILLIS = 60 * 1000; // 1 minute + private static final long DEFAULT_METRICS_COLLECTION_RANGE_MILLIS = 10 * 60 * 1000; // 10 minutes + private static final long DEFAULT_SCALE_ACTION_START_DELAY_MILLIS = 5 * 60 * 1000; // 5 minutes + private static final long DEFAULT_SCALE_ACTION_PERIOD_MILLIS = 10 * 60 * 1000; // 10 minutes + private static final long DEFAULT_MIN_TRIGGER_SCALE_ACTION_FREQUENCY_MILLIS = 1200000; // 20 minutes + private static final double DEFAULT_LAG_WEIGHT = 0.25; + private static final double DEFAULT_IDLE_WEIGHT = 0.75; + + private final boolean enableTaskAutoScaler; + private final int taskCountMax; + private final int taskCountMin; + private Integer taskCountStart; + private final long minTriggerScaleActionFrequencyMillis; + private final Double stopTaskCountRatio; + + private final long metricsCollectionIntervalMillis; + private final long metricsCollectionRangeMillis; + private final long scaleActionStartDelayMillis; + private final long scaleActionPeriodMillis; + + private final double lagWeight; + private final double idleWeight; + + @JsonCreator + public CostBasedAutoScalerConfig( + @JsonProperty("taskCountMax") Integer taskCountMax, + @JsonProperty("taskCountMin") Integer taskCountMin, + @Nullable @JsonProperty("enableTaskAutoScaler") Boolean enableTaskAutoScaler, + @Nullable @JsonProperty("taskCountStart") Integer taskCountStart, + @Nullable @JsonProperty("minTriggerScaleActionFrequencyMillis") Long minTriggerScaleActionFrequencyMillis, + @Nullable @JsonProperty("stopTaskCountRatio") Double stopTaskCountRatio, + @Nullable @JsonProperty("metricsCollectionIntervalMillis") Long metricsCollectionIntervalMillis, + @Nullable @JsonProperty("metricsCollectionRangeMillis") Long metricsCollectionRangeMillis, + @Nullable @JsonProperty("scaleActionStartDelayMillis") Long scaleActionStartDelayMillis, + @Nullable @JsonProperty("scaleActionPeriodMillis") Long scaleActionPeriodMillis, + @Nullable @JsonProperty("lagWeight") Double lagWeight, + @Nullable @JsonProperty("idleWeight") Double idleWeight + ) + { + this.enableTaskAutoScaler = enableTaskAutoScaler != null ? enableTaskAutoScaler : false; + + // Timing configuration with defaults + this.metricsCollectionIntervalMillis = metricsCollectionIntervalMillis != null + ? metricsCollectionIntervalMillis + : DEFAULT_METRICS_COLLECTION_INTERVAL_MILLIS; + this.metricsCollectionRangeMillis = metricsCollectionRangeMillis != null + ? metricsCollectionRangeMillis + : DEFAULT_METRICS_COLLECTION_RANGE_MILLIS; + this.scaleActionStartDelayMillis = scaleActionStartDelayMillis != null + ? scaleActionStartDelayMillis + : DEFAULT_SCALE_ACTION_START_DELAY_MILLIS; + this.scaleActionPeriodMillis = scaleActionPeriodMillis != null + ? scaleActionPeriodMillis + : DEFAULT_SCALE_ACTION_PERIOD_MILLIS; + this.minTriggerScaleActionFrequencyMillis = minTriggerScaleActionFrequencyMillis != null + ? minTriggerScaleActionFrequencyMillis + : DEFAULT_MIN_TRIGGER_SCALE_ACTION_FREQUENCY_MILLIS; + + // Cost function weights with defaults + this.lagWeight = lagWeight != null ? lagWeight : DEFAULT_LAG_WEIGHT; Review Comment: Oh nice!! -- 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]
