-
Notifications
You must be signed in to change notification settings - Fork 3.8k
feat: Multi-cluster Kubernetes Task Runner #19433
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
GWphua
wants to merge
16
commits into
apache:master
Choose a base branch
from
GWphua:multiple-k8s-clusters
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 13 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
8567229
Multi-K8s task scheduling
GWphua f6ee5e9
Register multik8s task runner factory
GWphua b424c40
Support shared executor in Kubernetes task runner
GWphua d96b6ae
Build per-cluster Kubernetes runners
GWphua 57fe609
Support task report streaming for multik8s
GWphua d063f0c
Honor shared informers in multik8s factory
GWphua acb6292
Style changes
GWphua 2249b24
Tighten multik8s tag map test types
GWphua 2da2eb6
Fix forbidden APIs
GWphua 336f551
Annotate nullable methods
GWphua 3bdf28d
Licenses fix
GWphua cfcdddb
Propagate pod template selection in multik8s
GWphua f4504f6
Harden multik8s capacity executor
GWphua 623f9fd
Docs for multik8s
GWphua 627e694
Merge remote-tracking branch 'origin/master' into multiple-k8s-clusters
GWphua 3a88773
Fix multik8s overlord pod source lookup
GWphua File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
...xtensions/src/main/java/org/apache/druid/k8s/overlord/AutoscalableThreadPoolExecutor.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| /* | ||
| * 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.k8s.overlord; | ||
|
|
||
|
|
||
| import org.apache.druid.common.config.ConfigManager; | ||
| import org.apache.druid.java.util.common.StringUtils; | ||
| import org.apache.druid.java.util.common.concurrent.Execs; | ||
| import org.apache.druid.java.util.emitter.EmittingLogger; | ||
| import org.apache.druid.k8s.overlord.execution.KubernetesTaskRunnerDynamicConfig; | ||
|
|
||
| import javax.annotation.Nullable; | ||
| import java.util.List; | ||
| import java.util.concurrent.LinkedBlockingQueue; | ||
| import java.util.concurrent.ThreadPoolExecutor; | ||
| import java.util.concurrent.TimeUnit; | ||
| import java.util.function.Consumer; | ||
|
|
||
| public class AutoscalableThreadPoolExecutor extends ThreadPoolExecutor | ||
| { | ||
| private static final EmittingLogger log = new EmittingLogger(AutoscalableThreadPoolExecutor.class); | ||
|
|
||
| @Nullable | ||
| private final ConfigManager configManager; | ||
| private final String listenerKey; | ||
| private final Consumer<KubernetesTaskRunnerDynamicConfig> configListener; | ||
|
|
||
| public AutoscalableThreadPoolExecutor(int initialCapacity, @Nullable ConfigManager configManager) | ||
| { | ||
| super( | ||
| initialCapacity, | ||
| initialCapacity, | ||
| 0L, | ||
| TimeUnit.MILLISECONDS, | ||
| new LinkedBlockingQueue<>(), | ||
| Execs.makeThreadFactory("k8s-task-runner-%d", null) | ||
| ); | ||
|
|
||
| this.configManager = configManager; | ||
| this.listenerKey = StringUtils.format("AutoscalableThreadPoolExecutor-%d", System.identityHashCode(this)); | ||
| this.configListener = this::onConfigurationChange; | ||
|
|
||
| // Monitor the configuration change | ||
| if (configManager != null && !configManager.addListener( | ||
| KubernetesTaskRunnerDynamicConfig.CONFIG_KEY, | ||
| listenerKey, | ||
| configListener)) { | ||
| log.error("Failed to add configuration listener for AutoscalableThreadPoolExecutor"); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void shutdown() | ||
| { | ||
| removeConfigListener(); | ||
| super.shutdown(); | ||
| } | ||
|
|
||
| @Override | ||
| public List<Runnable> shutdownNow() | ||
| { | ||
| removeConfigListener(); | ||
| return super.shutdownNow(); | ||
| } | ||
|
|
||
| private void removeConfigListener() | ||
| { | ||
| if (configManager == null) { | ||
| return; | ||
| } | ||
|
|
||
| if (!configManager.removeListener( | ||
| KubernetesTaskRunnerDynamicConfig.CONFIG_KEY, | ||
| listenerKey, | ||
| configListener | ||
| )) { | ||
| log.warn("Failed to remove configuration listener[%s] for AutoscalableThreadPoolExecutor", listenerKey); | ||
| } | ||
| } | ||
|
|
||
| private void onConfigurationChange(KubernetesTaskRunnerDynamicConfig config) | ||
| { | ||
| if (config.getCapacity() == null) { | ||
| return; | ||
| } | ||
|
|
||
| final int curCapacity = this.getCorePoolSize(); | ||
| final int newCapacity = config.getCapacity(); | ||
| if (newCapacity == curCapacity) { | ||
| return; | ||
| } | ||
|
|
||
| log.info("Adjusting k8s task runner capacity from [%d] to [%d]", curCapacity, newCapacity); | ||
| // maximum pool size must always be greater than or equal to the core pool size | ||
| if (newCapacity < curCapacity) { | ||
| // decrease capacity | ||
| setCorePoolSize(newCapacity); | ||
| setMaximumPoolSize(newCapacity); | ||
| } else { | ||
| // increase capacity | ||
| setMaximumPoolSize(newCapacity); | ||
| setCorePoolSize(newCapacity); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The updated
Thread.threadIdis the replacement, introduced in Java 19. I didn't get to see any PR that drops jdk17 support yet, (correct me if im wrong), so we should still use this deprecated method.