Github user srowen commented on a diff in the pull request:

    https://github.com/apache/spark/pull/5559#discussion_r28652021
  
    --- Diff: 
streaming/src/main/scala/org/apache/spark/streaming/receiver/RateLimiter.scala 
---
    @@ -33,37 +33,12 @@ import java.util.concurrent.TimeUnit._
       */
     private[receiver] abstract class RateLimiter(conf: SparkConf) extends 
Logging {
     
    -  private var lastSyncTime = System.nanoTime
    -  private var messagesWrittenSinceSync = 0L
       private val desiredRate = 
conf.getInt("spark.streaming.receiver.maxRate", 0)
    -  private val SYNC_INTERVAL = NANOSECONDS.convert(10, SECONDS)
    +  private lazy val rateLimiter = GuavaRateLimiter.create(desiredRate)
     
       def waitToPush() {
    -    if( desiredRate <= 0 ) {
    -      return
    -    }
    -    val now = System.nanoTime
    -    val elapsedNanosecs = math.max(now - lastSyncTime, 1)
    -    val rate = messagesWrittenSinceSync.toDouble * 1000000000 / 
elapsedNanosecs
    -    if (rate < desiredRate) {
    -      // It's okay to write; just update some variables and return
    -      messagesWrittenSinceSync += 1
    -      if (now > lastSyncTime + SYNC_INTERVAL) {
    -        // Sync interval has passed; let's resync
    -        lastSyncTime = now
    -        messagesWrittenSinceSync = 1
    -      }
    -    } else {
    -      // Calculate how much time we should sleep to bring ourselves to the 
desired rate.
    -      val targetTimeInMillis = messagesWrittenSinceSync * 1000 / 
desiredRate
    -      val elapsedTimeInMillis = elapsedNanosecs / 1000000
    -      val sleepTimeInMillis = targetTimeInMillis - elapsedTimeInMillis
    -      if (sleepTimeInMillis > 0) {
    -        logTrace("Natural rate is " + rate + " per second but desired rate 
is " +
    -          desiredRate + ", sleeping for " + sleepTimeInMillis + " ms to 
compensate.")
    -        Thread.sleep(sleepTimeInMillis)
    -      }
    -      waitToPush()
    +    if( desiredRate > 0 ) {
    --- End diff --
    
    Don't change this unless we have to push more changes, and this wasn't your 
change, but the spacing is off here -- should be no space inside parens but 
space outside. But don't bother with it now.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to