This repository was archived by the owner on May 9, 2024. It is now read-only.
forked from apache/spark
-
Couldn't load subscription status.
- Fork 3
[WIP] Adds back-pressure based congestion handling and a Reactive Streams endpoint to Spark Streaming #13
Closed
huitseeker
wants to merge
14
commits into
lightbend:ReactiveStreaming
from
huitseeker:ReactiveStreamingBackPressureControl
Closed
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
5975632
Adds a LatestSpeed(Streaming)Listener for processing speed computation
huitseeker 9345f17
Exercising the receiver's endpoint.
huitseeker f1fb911
Trigger sending of speed updates
huitseeker 7943250
Add debug message for number of elements per batch
huitseeker 9221ef8
Adds a CongestionStrategy to customize control.
huitseeker af130b9
Putting test in ignore because of long running time
huitseeker 67bfc03
Added congestion control strategies
huitseeker e61a82c
Switch pushBack Strategy to throttling
huitseeker 2373489
Making RNG more efficient for Bernoulli usage in sampling
huitseeker 3b8622e
Introduce integration tests for congestion strategies
huitseeker 4fef476
Fold "block generator throttling" in test framework.
huitseeker 21d53f6
Putting tests in ignore because of their undeterministic behavior in …
huitseeker 5b39d95
Adds logging of ratio for destructive strategies
huitseeker e38edfb
Adds ReactiveReceiver abstract class
huitseeker 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
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
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
47 changes: 47 additions & 0 deletions
47
streaming/src/main/scala/org/apache/spark/streaming/receiver/CongestionStrategy.scala
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,47 @@ | ||
| /* | ||
| * 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.streaming.receiver | ||
|
|
||
| import scala.collection.mutable.ArrayBuffer | ||
|
|
||
| /** | ||
| * This trait provides a strategy to deal with a large amount of data seen | ||
| * at a Receiver, possibly ensuing an exhaustion of resources. | ||
| * See SPARK-7398 | ||
| * Any long blocking operation in this class will hurt the throughput. | ||
| */ | ||
| trait CongestionStrategy { | ||
|
|
||
| /** | ||
| * Called on every batch interval with the estimated maximum number of | ||
| * elements per block that can been processed in a batch interval, | ||
| * based on the processing speed observed over the last batch. | ||
| */ | ||
| def onBlockBoundUpdate(bound: Int): Unit | ||
|
|
||
| /** | ||
| * Given data buffers intended for a block, and for the following block | ||
| * mutates those buffers to an amount appropriate with respect to the | ||
| * back-pressure information provided through `onBlockBoundUpdate`. | ||
| */ | ||
| def restrictCurrentBuffer(currentBuffer: ArrayBuffer[Any], nextBuffer: ArrayBuffer[Any]): Unit | ||
|
|
||
| } | ||
|
|
||
| abstract class ThrottlingCongestionStrategy(private[receiver] val rateLimiter: RateLimiter) | ||
| extends CongestionStrategy |
103 changes: 103 additions & 0 deletions
103
streaming/src/main/scala/org/apache/spark/streaming/receiver/CongestionStrategyImpl.scala
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,103 @@ | ||
| /* | ||
| * 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.streaming.receiver | ||
|
|
||
| import scala.collection.mutable.ArrayBuffer | ||
| import java.util.concurrent.atomic.AtomicInteger | ||
| import java.util.Random | ||
| import org.apache.spark.Logging | ||
| import org.apache.spark.util.random.{RandomSampler, BernoulliSampler} | ||
|
|
||
| /** | ||
| * This class provides a congestion strategy that ignores | ||
| * any back-pressure information. | ||
| * @see CongestionStrategy | ||
| */ | ||
| class IgnoreCongestionStrategy extends CongestionStrategy { | ||
|
|
||
| override def onBlockBoundUpdate(bound: Int): Unit = {} | ||
|
|
||
| override def restrictCurrentBuffer(currentBuffer: ArrayBuffer[Any], | ||
| nextBuffer: ArrayBuffer[Any]): Unit = {} | ||
| } | ||
|
|
||
| class PushBackCongestionStrategy(blockGenerator: BlockGenerator) | ||
| extends ThrottlingCongestionStrategy(blockGenerator) { | ||
|
|
||
| private val latestBound = new AtomicInteger(-1) | ||
|
|
||
| override def onBlockBoundUpdate(bound: Int): Unit = { | ||
| if (bound > 0) rateLimiter.updateRate(bound * 1000 / blockGenerator.blockIntervalMs.toInt) | ||
| latestBound.set(bound) | ||
| } | ||
|
|
||
| override def restrictCurrentBuffer(currentBuffer: ArrayBuffer[Any], | ||
| nextBuffer: ArrayBuffer[Any]): Unit = { | ||
| val bound = latestBound.get() | ||
| val difference = currentBuffer.size - bound | ||
| if (bound > 0 && difference > 0) { | ||
| nextBuffer ++=: currentBuffer.takeRight(difference) | ||
| currentBuffer.reduceToSize(bound) | ||
| } | ||
| } | ||
|
|
||
| } | ||
|
|
||
| class DropCongestionStrategy extends CongestionStrategy with Logging { | ||
|
|
||
| private val latestBound = new AtomicInteger(-1) | ||
|
|
||
| override def onBlockBoundUpdate(bound: Int): Unit = latestBound.set(bound) | ||
|
|
||
| override def restrictCurrentBuffer(currentBuffer: ArrayBuffer[Any], | ||
| nextBuffer: ArrayBuffer[Any]): Unit = { | ||
| val bound = latestBound.get() | ||
| val difference = currentBuffer.size - bound | ||
| if (bound > 0 && difference > 0) { | ||
| currentBuffer.reduceToSize(bound) | ||
|
|
||
| val f = bound.toDouble / currentBuffer.size | ||
| logDebug(f"Prepared block by dropping with ratio of $f%2.2f.") | ||
| } | ||
| } | ||
|
|
||
| } | ||
|
|
||
| class SamplingCongestionStrategy extends CongestionStrategy with Logging { | ||
|
|
||
| private val rng = RandomSampler.newDefaultRNG | ||
|
|
||
| private val latestBound = new AtomicInteger(-1) | ||
|
|
||
| override def onBlockBoundUpdate(bound: Int): Unit = latestBound.set(bound) | ||
|
|
||
| override def restrictCurrentBuffer(currentBuffer: ArrayBuffer[Any], | ||
| nextBuffer: ArrayBuffer[Any]): Unit = { | ||
| val bound = latestBound.get() | ||
| val f = bound.toDouble / currentBuffer.size | ||
| if (f > 0 && f < 1){ | ||
| val sampled = new BernoulliSampler(f, rng).sample(currentBuffer.toIterator).toArray | ||
|
|
||
| currentBuffer.clear() | ||
| currentBuffer ++= sampled | ||
|
|
||
| logDebug(f"Prepared sampled block with ratio of $f%2.2f.") | ||
| } | ||
| } | ||
|
|
||
| } |
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.
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.
Please do no add additional dependencies to streaming module. Any additional dependencies can be separate modules