-
Notifications
You must be signed in to change notification settings - Fork 28.4k
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
[SPARK-24918][Core] Executor Plugin api #21923
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* 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.spark; | ||
|
||
import org.apache.spark.annotation.DeveloperApi; | ||
|
||
/** | ||
* A plugin which can be automaticaly instantiated within each Spark executor. Users can specify | ||
* plugins which should be created with the "spark.executor.plugins" configuration. An instance | ||
* of each plugin will be created for every executor, including those created by dynamic allocation, | ||
* before the executor starts running any tasks. | ||
* | ||
* The specific api exposed to the end users still considered to be very unstable. We will | ||
* *hopefully* be able to keep compatability by providing default implementations for any methods | ||
* added, but make no guarantees this will always be possible across all spark releases. | ||
* | ||
* Spark does nothing to verify the plugin is doing legitimate things, or to manage the resources | ||
* it uses. A plugin acquires the same privileges as the user running the task. A bad plugin | ||
* could also intefere with task execution and make the executor fail in unexpected ways. | ||
*/ | ||
@DeveloperApi | ||
public interface ExecutorPlugin { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,6 +130,12 @@ private[spark] class Executor( | |
private val urlClassLoader = createClassLoader() | ||
private val replClassLoader = addReplClassLoaderIfNeeded(urlClassLoader) | ||
|
||
Thread.currentThread().setContextClassLoader(replClassLoader) | ||
conf.get(EXECUTOR_PLUGINS).foreach { classes => | ||
Utils.loadExtensions(classOf[ExecutorPlugin], classes, conf) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For all cluster managers would this properly load plugins deployed via In fact - I wonder if we should even move this extension loading further up in the lifecycle, simply so that the plugin can be around for a larger percentage of the executor JVM's uptime. |
||
} | ||
|
||
|
||
// Set the classloader for serializer | ||
env.serializer.setDefaultClassLoader(replClassLoader) | ||
// SPARK-21928. SerializerManager's internal instance of Kryo might get used in netty threads | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -567,4 +567,15 @@ package object config { | |
.intConf | ||
.checkValue(v => v > 0, "The value should be a positive integer.") | ||
.createWithDefault(2000) | ||
|
||
private[spark] val EXECUTOR_PLUGINS = | ||
ConfigBuilder("spark.executor.plugins") | ||
.internal() | ||
.doc("Comma-separated list of class names for \"plugins\" implementing " + | ||
"org.apache.spark.AbstractExecutorPlugin. Plugins have the same privileges as any task " + | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
"in a spark executor. They can also interfere with task execution and fail in " + | ||
"unexpected ways. So be sure to only use this for trusted plugins.") | ||
.stringConf | ||
.toSequence | ||
.createOptional | ||
} |
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.
do we want to do it in the same thread? It might be safer in a separate thread. Does that affect your memory monitor?
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.
My memory monitor would be fine if the constructor were called in another thread. (It actually creates its own thread -- it has to, as its going to continually poll.)
What would be the advantage to calling the constructor in a separate thread? If its just protect against exceptions, we could just do a try/catch. If its to ensure that we don't tie up the main executor threads ... well, even in another thread, the plugin could do something arbitrary to tie up all the resources associated with this executor (eg. launch 30 threads and do something intensive in each one).
Not opposed to having another thread, just want to understand why.
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.
I was thinking another thread would at least prevent them from not allowing the executor to run/start. If someone added a plugin that just blocked or did something that took time and then you started to see timeouts during start, those might not be as obvious what is going on. If we start it in a separate thread, yes it still uses resources but it doesn't completely block the executor from starting and trying to take tasks. It also just seems safer to me as you could try to catch exceptions from there and possibly ignore them so it doesn't affect the main running.
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.
makes sense. probably something I should have at least a basic test for as well ... will need to think about how to do that.