All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.flink.runtime.healthmanager.plugins.policies.TargetRpsPolicy Maven / Gradle / Ivy

There is a newer version: 1.5.1
Show newest version
/*
 * 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.healthmanager.plugins.policies;

import org.apache.flink.configuration.Configuration;
import org.apache.flink.runtime.healthmanager.HealthMonitor;
import org.apache.flink.runtime.healthmanager.plugins.detectors.DirectOOMDetector;
import org.apache.flink.runtime.healthmanager.plugins.detectors.FailoverDetector;
import org.apache.flink.runtime.healthmanager.plugins.detectors.FrequentFullGCDetector;
import org.apache.flink.runtime.healthmanager.plugins.detectors.HeapOOMDetector;
import org.apache.flink.runtime.healthmanager.plugins.detectors.HighCpuDetector;
import org.apache.flink.runtime.healthmanager.plugins.detectors.HighDelayDetector;
import org.apache.flink.runtime.healthmanager.plugins.detectors.HighNativeMemoryDetector;
import org.apache.flink.runtime.healthmanager.plugins.detectors.JobStableDetector;
import org.apache.flink.runtime.healthmanager.plugins.detectors.KilledDueToMemoryExceedDetector;
import org.apache.flink.runtime.healthmanager.plugins.detectors.LargeTimerCountDetector;
import org.apache.flink.runtime.healthmanager.plugins.detectors.LongTimeFullGCDetector;
import org.apache.flink.runtime.healthmanager.plugins.detectors.RpsUnsatisfiedDetector;
import org.apache.flink.runtime.healthmanager.plugins.resolvers.CpuAdjuster;
import org.apache.flink.runtime.healthmanager.plugins.resolvers.DirectMemoryAdjuster;
import org.apache.flink.runtime.healthmanager.plugins.resolvers.HeapMemoryAdjuster;
import org.apache.flink.runtime.healthmanager.plugins.resolvers.NativeMemoryAdjuster;
import org.apache.flink.runtime.healthmanager.plugins.resolvers.ParallelismScaler;
import org.apache.flink.runtime.healthmanager.plugins.utils.HealthMonitorOptions;

import java.util.HashSet;
import java.util.Set;

/**
 * Target Rps policy.
 */
public class TargetRpsPolicy extends DefaultPolicy {

	@Override
	public void apply(HealthMonitor monitor) {
		setDetectors(monitor.getConfig());
		setResolvers(monitor.getConfig());
	}

	private void setDetectors(Configuration config) {

		Set detectorClazzs = new HashSet<>();
		if (config.getBoolean(HealthMonitorOptions.ENABLE_PARALLELISM_RESCALE)) {

			// detector which will trigger rescale
			detectorClazzs.add(LargeTimerCountDetector.class.getCanonicalName());

			// currently support by either target TPS or delay.
			detectorClazzs.add(HighDelayDetector.class.getCanonicalName());
			detectorClazzs.add(RpsUnsatisfiedDetector.class.getCanonicalName());

			// detectors which will check state of job
			detectorClazzs.add(JobStableDetector.class.getCanonicalName());
			detectorClazzs.add(FailoverDetector.class.getCanonicalName());
			detectorClazzs.add(FrequentFullGCDetector.class.getCanonicalName());
			detectorClazzs.add(LongTimeFullGCDetector.class.getCanonicalName());
		}
		if (config.getBoolean(HealthMonitorOptions.ENABLE_RESOURCE_RESCALE)) {
			detectorClazzs.add(HighCpuDetector.class.getCanonicalName());
			detectorClazzs.add(HeapOOMDetector.class.getCanonicalName());
			detectorClazzs.add(FrequentFullGCDetector.class.getCanonicalName());
			detectorClazzs.add(LongTimeFullGCDetector.class.getCanonicalName());
			detectorClazzs.add(DirectOOMDetector.class.getCanonicalName());
			detectorClazzs.add(HighNativeMemoryDetector.class.getCanonicalName());
			detectorClazzs.add(KilledDueToMemoryExceedDetector.class.getCanonicalName());
			detectorClazzs.add(JobStableDetector.class.getCanonicalName());
		}

		config.setString(HealthMonitor.DETECTOR_CLASSES, String.join(",", detectorClazzs));
	}

	public void setResolvers(Configuration config) {
		Set resolverClazzs = new HashSet<>();
		if (config.getBoolean(HealthMonitorOptions.ENABLE_PARALLELISM_RESCALE)) {
			resolverClazzs.add(ParallelismScaler.class.getCanonicalName());
		}
		if (config.getBoolean(HealthMonitorOptions.ENABLE_RESOURCE_RESCALE)) {
			if (config.getBoolean(HealthMonitorOptions.ENABLE_CPU_RESCALE)) {
				resolverClazzs.add(CpuAdjuster.class.getCanonicalName());
			}
			if (config.getBoolean(HealthMonitorOptions.ENABLE_MEMORY_RESCALE)) {
				resolverClazzs.add(HeapMemoryAdjuster.class.getCanonicalName());
				resolverClazzs.add(DirectMemoryAdjuster.class.getCanonicalName());
				resolverClazzs.add(NativeMemoryAdjuster.class.getCanonicalName());
			}
		}
		config.setString(HealthMonitor.RESOLVER_CLASSES, String.join(",", resolverClazzs));
	}

	public static boolean isEnabled(Configuration config) {
		return config.contains(HealthMonitorOptions.TARGET_TPS_VALUES) && (config.contains(HealthMonitorOptions.TARGET_TPS_IDS) || config.contains(HealthMonitorOptions.TARGET_TPS_NAMES));
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy