-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix endless loop race condition in NodeQueue, #19949
- also fixed some forgotten copy-pasta between peekNode and pollNode - also added JavaDoc to all methods, explaining which can be used from what thread - did not fix the JDK8 improvement of using Unsafe instead of inheriting from AtomicReference since that inheritance is not a bad thing, actually
- Loading branch information
Showing
5 changed files
with
182 additions
and
39 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
72 changes: 72 additions & 0 deletions
72
akka-bench-jmh/src/main/scala/akka/dispatch/NodeQueueBenchmark.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,72 @@ | ||
/** | ||
* Copyright (C) 2016 Lightbend Inc. <http://www.lightbend.com> | ||
*/ | ||
package akka.dispatch | ||
|
||
import akka.actor._ | ||
import org.openjdk.jmh.annotations._ | ||
import com.typesafe.config.ConfigFactory | ||
import java.util.concurrent.TimeUnit | ||
import scala.concurrent.Await | ||
import scala.concurrent.duration._ | ||
import akka.testkit.TestProbe | ||
|
||
object NodeQueueBenchmark { | ||
final val burst = 100000 | ||
case object Stop | ||
} | ||
|
||
@State(Scope.Benchmark) | ||
@BenchmarkMode(Array(Mode.Throughput)) | ||
@Fork(2) | ||
@Warmup(iterations = 5) | ||
@Measurement(iterations = 10) | ||
@OutputTimeUnit(TimeUnit.MICROSECONDS) | ||
class NodeQueueBenchmark { | ||
import NodeQueueBenchmark._ | ||
|
||
val config = ConfigFactory.parseString(""" | ||
dispatcher { | ||
executor = "thread-pool-executor" | ||
throughput = 1000 | ||
thread-pool-executor { | ||
fixed-pool-size = 1 | ||
} | ||
} | ||
mailbox { | ||
mailbox-type = "akka.dispatch.SingleConsumerOnlyUnboundedMailbox" | ||
mailbox-capacity = 1000000 | ||
} | ||
""").withFallback(ConfigFactory.load()) | ||
implicit val sys = ActorSystem("ANQ", config) | ||
val ref = sys.actorOf(Props(new Actor { | ||
def receive = { | ||
case Stop => sender() ! Stop | ||
case _ => | ||
} | ||
}).withDispatcher("dispatcher").withMailbox("mailbox"), "receiver") | ||
|
||
@TearDown | ||
def teardown(): Unit = Await.result(sys.terminate(), 5.seconds) | ||
|
||
@TearDown(Level.Invocation) | ||
def waitInBetween(): Unit = { | ||
val probe = TestProbe() | ||
probe.send(ref, Stop) | ||
probe.expectMsg(Stop) | ||
System.gc() | ||
System.gc() | ||
System.gc() | ||
} | ||
|
||
@Benchmark | ||
@OperationsPerInvocation(burst) | ||
def send(): Unit = { | ||
var todo = burst | ||
while (todo > 0) { | ||
ref ! "hello" | ||
todo -= 1 | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.