org.apache.flink.runtime.resourcemanager.autoscale.plugins.detectors.ClusterUnfulfilledQueueDetector Maven / Gradle / Ivy
/*
* 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.flink.runtime.resourcemanager.autoscale.plugins.detectors;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.configuration.ConfigOption;
import org.apache.flink.configuration.ConfigOptions;
import org.apache.flink.metrics.Histogram;
import org.apache.flink.runtime.clusterframework.types.ResourceProfile;
import org.apache.flink.runtime.metrics.SimpleHistogram;
import org.apache.flink.runtime.resourcemanager.autoscale.ResourceAutoScaler;
import org.apache.flink.runtime.resourcemanager.autoscale.plugins.ResourceDetector;
import org.apache.flink.runtime.resourcemanager.autoscale.plugins.ResourceSymptom;
import org.apache.flink.runtime.resourcemanager.autoscale.plugins.symptoms.ClusterLongUnfulfilledQueue;
import org.apache.flink.runtime.resourcemanager.autoscale.plugins.symptoms.ClusterShortUnfulfilledQueue;
import org.apache.flink.runtime.resourcemanager.autoscale.utils.SlotManagerInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Collection;
/**
* ClusterUnfulfilledQueueDetector detects cluster unfulfilled request state.
* Detects {@link ClusterLongUnfulfilledQueue} if the max avg unfulfilled queue len
* is higher than threshold.
* Detects {@link ClusterShortUnfulfilledQueue} if the max avg unfulfilled queue len
* is lower than threshold.
*/
public class ClusterUnfulfilledQueueDetector implements ResourceDetector {
private static final Logger LOGGER = LoggerFactory.getLogger(ClusterUnfulfilledQueueDetector.class);
public static final ConfigOption HIGH_UNFULFILLED_QUEUE_LENGTH_THRESHOLD =
ConfigOptions.key("session-auto-scale.cluster-unfulfilled-queue-detector.threashold.high").defaultValue(100);
public static final ConfigOption LOW_UNFULFILLED_QUEUE_LENGTH_THRESHOLD =
ConfigOptions.key("session-auto-scale.cluster-unfulfilled-queue-detector.threashold.low").defaultValue(10);
private ResourceAutoScaler resourceAutoScaler;
private int checkInterval;
private double highThreshold;
private double lowThreshold;
private Histogram clusterUnfulfilledQueueLengthHistogram;
@Override
public void open(ResourceAutoScaler resourceAutoScaler) {
this.resourceAutoScaler = resourceAutoScaler;
checkInterval = resourceAutoScaler.getConfig().getInteger(ResourceAutoScaler.METRIC_UPDATE_INTERVAL);
highThreshold = resourceAutoScaler.getConfig().getInteger(HIGH_UNFULFILLED_QUEUE_LENGTH_THRESHOLD);
lowThreshold = resourceAutoScaler.getConfig().getInteger(LOW_UNFULFILLED_QUEUE_LENGTH_THRESHOLD);
clusterUnfulfilledQueueLengthHistogram = new SimpleHistogram(checkInterval);
}
@Override
public void close() {
}
@Override
public void update(SlotManagerInfo slotManagerInfo, Collection> taskManagersProfiles) {
clusterUnfulfilledQueueLengthHistogram.update(slotManagerInfo.getUnfulfilledQueueLength());
}
@Override
public ResourceSymptom detect() throws Exception {
LOGGER.debug("Start detecting");
double length = clusterUnfulfilledQueueLengthHistogram.getStatistics().getMean();
LOGGER.debug("Cluster unfulfilled queue average length {}.", length);
if (length >= highThreshold) {
LOGGER.debug("Long unfulfilled queue detected for Cluster, length {}", length);
return new ClusterLongUnfulfilledQueue(length);
} else if (length <= lowThreshold) {
LOGGER.debug("Short unfulfilled queue detected for Cluster, length {}", length);
return new ClusterShortUnfulfilledQueue(length);
}
return null;
}
}