forked from apache/flink
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FLINK-10253] Run MetricQueryService with lower priority
- Loading branch information
1 parent
2c53a17
commit 3932433
Showing
8 changed files
with
248 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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 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 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
38 changes: 38 additions & 0 deletions
38
flink-runtime/src/main/scala/akka/dispatch/PriorityThreadFactory.scala
This file contains 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,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:https://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 akka.dispatch | ||
|
||
import java.util.concurrent.ThreadFactory | ||
|
||
/** | ||
* Composition over the [[DispatcherPrerequisites.threadFactory]] that set priority | ||
* for newly created threads. | ||
* | ||
* @param newThreadPriority priority that will be set to each newly created thread | ||
* should be between Thread.MIN_PRIORITY and Thread.MAX_PRIORITY | ||
*/ | ||
class PriorityThreadFactory( | ||
prerequisites: DispatcherPrerequisites, | ||
newThreadPriority: Int) extends ThreadFactory { | ||
override def newThread(r: Runnable): Thread = { | ||
val newThread = prerequisites.threadFactory.newThread(r) | ||
newThread.setPriority(newThreadPriority) | ||
newThread | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
flink-runtime/src/main/scala/akka/dispatch/PriorityThreadsDispatcher.scala
This file contains 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,64 @@ | ||
/* | ||
* 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:https://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 akka.dispatch | ||
|
||
import com.typesafe.config.Config | ||
|
||
/** | ||
* Akka Dispatcher that creates thread with configurable priority. | ||
* | ||
* Example of configuration: | ||
* | ||
* low-priority-threads-dispatcher { | ||
* type = akka.dispatch.PriorityThreadsDispatcher | ||
* executor = "thread-pool-executor" | ||
* # should be between Thread.MIN_PRIORITY (which is 1) and Thread.MAX_PRIORITY (which is 10) | ||
* threads-priority = 1 | ||
* thread-pool-executor { | ||
* core-pool-size-min = 0 | ||
* core-pool-size-factor = 2.0 | ||
* core-pool-size-max = 10 | ||
* } | ||
* } | ||
* | ||
* Two arguments constructor (the primary constructor) is automatically called by Akka | ||
* when it founds: | ||
* abcde-dispatcher { | ||
* type = akka.dispatch.PriorityThreadsDispatcher <-- the class that Akka will instantiate | ||
* ... | ||
* } | ||
* | ||
* @param config passed automatically by Akka, should contains information about threads priority | ||
* @param prerequisites passed automatically by Akka | ||
*/ | ||
class PriorityThreadsDispatcher(config: Config, prerequisites: DispatcherPrerequisites) | ||
extends DispatcherConfigurator( | ||
config, | ||
new PriorityThreadsDispatcherPrerequisites( | ||
prerequisites, | ||
config.getInt(PriorityThreadsDispatcher.threadPriorityConfigKey) | ||
) | ||
) | ||
|
||
object PriorityThreadsDispatcher { | ||
/** | ||
* Configuration key under which int value should be placed. | ||
*/ | ||
val threadPriorityConfigKey = "thread-priority" | ||
} |
78 changes: 78 additions & 0 deletions
78
flink-runtime/src/main/scala/akka/dispatch/PriorityThreadsDispatcherPrerequisites.scala
This file contains 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,78 @@ | ||
/* | ||
* 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:https://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 akka.dispatch | ||
|
||
/** | ||
* Composition over [[DefaultDispatcherPrerequisites]] that replaces thread factory with one that | ||
* allow to configure thread priority. | ||
* | ||
* @param newThreadPriority priority that will be set to each newly created thread | ||
* should be between Thread.MIN_PRIORITY and Thread.MAX_PRIORITY | ||
*/ | ||
class PriorityThreadsDispatcherPrerequisites( | ||
prerequisites: DispatcherPrerequisites, | ||
newThreadPriority: Int) extends DispatcherPrerequisites { | ||
|
||
private val defaultDispatcherPrerequisites : DefaultDispatcherPrerequisites = | ||
new DefaultDispatcherPrerequisites( | ||
eventStream = prerequisites.eventStream, | ||
scheduler = prerequisites.scheduler, | ||
dynamicAccess = prerequisites.dynamicAccess, | ||
settings = prerequisites.settings, | ||
mailboxes = prerequisites.mailboxes, | ||
defaultExecutionContext = prerequisites.defaultExecutionContext, | ||
threadFactory = new PriorityThreadFactory(prerequisites, newThreadPriority) | ||
) | ||
|
||
override def threadFactory : java.util.concurrent.ThreadFactory = { | ||
defaultDispatcherPrerequisites.threadFactory | ||
} | ||
|
||
override def eventStream : akka.event.EventStream = { | ||
defaultDispatcherPrerequisites.eventStream | ||
} | ||
|
||
override def scheduler : akka.actor.Scheduler = { | ||
defaultDispatcherPrerequisites.scheduler | ||
} | ||
|
||
override def dynamicAccess : akka.actor.DynamicAccess = { | ||
defaultDispatcherPrerequisites.dynamicAccess | ||
} | ||
|
||
override def settings : akka.actor.ActorSystem.Settings = { | ||
defaultDispatcherPrerequisites.settings | ||
} | ||
|
||
override def mailboxes : akka.dispatch.Mailboxes = { | ||
defaultDispatcherPrerequisites.mailboxes | ||
} | ||
|
||
override def defaultExecutionContext : scala.Option[scala.concurrent.ExecutionContext] = { | ||
defaultDispatcherPrerequisites.defaultExecutionContext | ||
} | ||
} | ||
|
||
object PriorityThreadsDispatcherPrerequisites { | ||
def apply(prerequisites: DispatcherPrerequisites, newThreadPriority: Int): | ||
PriorityThreadsDispatcherPrerequisites = | ||
new PriorityThreadsDispatcherPrerequisites(prerequisites, newThreadPriority) | ||
} | ||
|
||
|
This file contains 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 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