forked from apache/samza
-
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.
SAMZA-146: Throughput degrades unreasonably as the number of topic-pa…
…rtitions increases.
- Loading branch information
Showing
6 changed files
with
170 additions
and
24 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
62 changes: 62 additions & 0 deletions
62
samza-core/src/main/scala/org/apache/samza/util/DoublingBackOff.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,62 @@ | ||
/* | ||
* 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.samza.util | ||
|
||
/** | ||
* Perform the provided action (via the call method) and, if it returns true, | ||
* perform it again, the next time. If, however, call returns false, do not | ||
* perform call the next time, instead wait 2*n calls before actually calling, | ||
* with n increasing to the maximum specified in the constructor. | ||
* @param maxBackOff Absolute maximum number of calls to call before actually performing call. | ||
*/ | ||
abstract class DoublingBackOff(maxBackOff:Int = 64) { | ||
var invocationsBeforeCall = 0 | ||
var currentBackOff = 0 | ||
|
||
/** | ||
* Method to invoke and whose return value will determine the next time | ||
* it is called again. | ||
*/ | ||
def call():Boolean | ||
|
||
/** | ||
* Possibly execute the call method, based on the result of the previous run. | ||
*/ | ||
def maybeCall():Unit = { | ||
if(invocationsBeforeCall == 0) { | ||
if (call()) { | ||
// call succeeded so reset backoff | ||
currentBackOff = 0 | ||
} else { | ||
// Call failed, so start backing off | ||
currentBackOff = scala.math.min(maxBackOff, nextBackOff(currentBackOff)) | ||
invocationsBeforeCall = currentBackOff | ||
} | ||
} else { | ||
invocationsBeforeCall -= 1 | ||
} | ||
|
||
} | ||
|
||
// 2 * 0 == 0, making getting started a wee bit hard, so we need a little help with that first back off | ||
private def nextBackOff(i:Int) = if(i == 0) 1 else 2 * i | ||
|
||
} | ||
|
61 changes: 61 additions & 0 deletions
61
samza-core/src/test/scala/org/apache/samza/util/TestDoublingBackOff.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,61 @@ | ||
/* | ||
* 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.samza.util | ||
|
||
import org.junit.Test | ||
import org.junit.Assert._ | ||
|
||
class TestDoublingBackOff { | ||
@Test def zeroBackOffWorks() { | ||
var counter = 0 | ||
val zeroBackOff = new DoublingBackOff(0) { | ||
def call(): Boolean = { | ||
counter += 1 | ||
true | ||
} | ||
} | ||
|
||
for(i <- 0 to 1000) { | ||
assertEquals(i, counter) | ||
zeroBackOff.maybeCall() | ||
} | ||
} | ||
|
||
@Test def backOffWorks() { | ||
val toReturn = List(true, false, true, true) | ||
var counter = 0 | ||
val ebo = new DoublingBackOff() { | ||
def call(): Boolean = { | ||
counter += 1 | ||
toReturn(counter - 1) | ||
} | ||
} | ||
|
||
ebo.maybeCall() // will get back true | ||
assertEquals(1, counter) | ||
ebo.maybeCall() // will get back false | ||
assertEquals(2, counter) | ||
ebo.maybeCall() // last false means we won't actually call, will hold off for one iteration | ||
assertEquals(2, counter) | ||
ebo.maybeCall() // and call on this one, which gives back true | ||
assertEquals(3, counter) | ||
ebo.maybeCall() // so we immediately call again and increment | ||
assertEquals(4, counter) | ||
} | ||
} |
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