Make SingleConsumerMultiProducer the default mail box for typed

This commit is contained in:
Christopher Batey 2019-10-02 11:25:07 +01:00
parent 7ac4bde963
commit dd5a3875ba
5 changed files with 42 additions and 32 deletions

View file

@ -0,0 +1,23 @@
/*
* Copyright (C) 2019 Lightbend Inc. <https://www.lightbend.com>
*/
package akka.actor.typed.internal.adpater
import akka.actor
import akka.actor.typed.Props
import akka.actor.typed.internal.adapter.PropsAdapter
import akka.actor.typed.scaladsl.Behaviors
import org.scalatest.Matchers
import org.scalatest.WordSpec
class PropsAdapterSpec extends WordSpec with Matchers {
"PropsAdapter" should {
"default to akka.dispatch.SingleConsumerOnlyUnboundedMailbox" in {
val props: Props = Props.empty
val pa: actor.Props = PropsAdapter(() => Behaviors.empty, props)
pa.mailbox shouldEqual "akka.dispatch.SingleConsumerOnlyUnboundedMailbox"
}
}
}

View file

@ -189,12 +189,12 @@ abstract class MailboxSelector extends Props
object MailboxSelector {
/**
* Scala API: The default mailbox is unbounded and backed by a [[java.util.concurrent.ConcurrentLinkedQueue]]
* Scala API: The default mailbox is SingleConsumerOnlyUnboundedMailbox
*/
def default(): MailboxSelector = DefaultMailboxSelector.empty
def default(): MailboxSelector = fromConfig("akka.dispatch.SingleConsumerOnlyUnboundedMailbox")
/**
* Java API: The default mailbox is unbounded and backed by a [[java.util.concurrent.ConcurrentLinkedQueue]]
* Java API: The default mailbox is SingleConsumerOnlyUnboundedMailbox
*/
def defaultMailbox(): MailboxSelector = default()

View file

@ -23,22 +23,22 @@ import akka.dispatch.Mailboxes
rethrowTypedFailure: Boolean = true): akka.actor.Props = {
val props = akka.actor.Props(new ActorAdapter(behavior(), rethrowTypedFailure))
val p1 = (deploy.firstOrElse[DispatcherSelector](DispatcherDefault.empty) match {
val dispatcherProps = (deploy.firstOrElse[DispatcherSelector](DispatcherDefault.empty) match {
case _: DispatcherDefault => props
case DispatcherFromConfig(name, _) => props.withDispatcher(name)
case _: DispatcherSameAsParent => props.withDispatcher(Deploy.DispatcherSameAsParent)
}).withDeploy(Deploy.local) // disallow remote deployment for typed actors
val p2 = deploy.firstOrElse[MailboxSelector](MailboxSelector.default()) match {
case _: DefaultMailboxSelector => p1
val mailboxProps = deploy.firstOrElse[MailboxSelector](MailboxSelector.default()) match {
case _: DefaultMailboxSelector => dispatcherProps
case BoundedMailboxSelector(capacity, _) =>
// specific support in classic Mailboxes
p1.withMailbox(s"${Mailboxes.BoundedCapacityPrefix}$capacity")
dispatcherProps.withMailbox(s"${Mailboxes.BoundedCapacityPrefix}$capacity")
case MailboxFromConfigSelector(path, _) =>
props.withMailbox(path)
}
p2.withDeploy(Deploy.local) // disallow remote deployment for typed actors
mailboxProps.withDeploy(Deploy.local) // disallow remote deployment for typed actors
}
}

View file

@ -15,7 +15,7 @@ import akka.actor.typed.scaladsl.AskPattern._
object TypedActorBenchmark {
// Constants because they are used in annotations
final val threads = 12 // update according to cpu
final val threads = 8 // update according to cpu
final val numMessagesPerActorPair = 1000000 // messages per actor pair
final val numActors = 512

View file

@ -83,20 +83,7 @@ be used.
### Default Mailbox
The default mailbox is used when the mailbox is not specified.
This is an unbounded mailbox, backed by a
`java.util.concurrent.ConcurrentLinkedQueue`.
`SingleConsumerOnlyUnboundedMailbox` is an even more efficient mailbox, and
it can be used as the default mailbox, but it cannot be used with a BalancingDispatcher.
Configuration of `SingleConsumerOnlyUnboundedMailbox` as default mailbox:
```
akka.actor.default-mailbox {
mailbox-type = "akka.dispatch.SingleConsumerOnlyUnboundedMailbox"
}
```
The default mailbox is used when the mailbox is not specified and is the **SingleConsumerOnlyUnboundedMailbox**>
### Which Configuration is passed to the Mailbox Type
@ -112,19 +99,19 @@ fall-back to the default mailbox configuration section.
Akka ships with a number of mailbox implementations:
*
**UnboundedMailbox** (default)
* The default mailbox
* Backed by a `java.util.concurrent.ConcurrentLinkedQueue`
* Blocking: No
* Bounded: No
* Configuration name: `"unbounded"` or `"akka.dispatch.UnboundedMailbox"`
*
**SingleConsumerOnlyUnboundedMailbox**
Depending on your use case, this queue may or may not be faster than the default one — be sure to benchmark properly!
**SingleConsumerOnlyUnboundedMailbox** (default)
* This is the default
* Backed by a Multiple-Producer Single-Consumer queue, cannot be used with `BalancingDispatcher`
* Blocking: No
* Bounded: No
* Configuration name: `"akka.dispatch.SingleConsumerOnlyUnboundedMailbox"`
*
**UnboundedMailbox**
* Backed by a `java.util.concurrent.ConcurrentLinkedQueue`
* Blocking: No
* Bounded: No
* Configuration name: `"unbounded"` or `"akka.dispatch.UnboundedMailbox"`
*
**NonBlockingBoundedMailbox**
* Backed by a very efficient Multiple-Producer Single-Consumer queue