Make SingleConsumerMultiProducer the default mail box for typed
This commit is contained in:
parent
7ac4bde963
commit
dd5a3875ba
5 changed files with 42 additions and 32 deletions
|
|
@ -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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -189,12 +189,12 @@ abstract class MailboxSelector extends Props
|
||||||
object MailboxSelector {
|
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()
|
def defaultMailbox(): MailboxSelector = default()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,22 +23,22 @@ import akka.dispatch.Mailboxes
|
||||||
rethrowTypedFailure: Boolean = true): akka.actor.Props = {
|
rethrowTypedFailure: Boolean = true): akka.actor.Props = {
|
||||||
val props = akka.actor.Props(new ActorAdapter(behavior(), rethrowTypedFailure))
|
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 _: DispatcherDefault => props
|
||||||
case DispatcherFromConfig(name, _) => props.withDispatcher(name)
|
case DispatcherFromConfig(name, _) => props.withDispatcher(name)
|
||||||
case _: DispatcherSameAsParent => props.withDispatcher(Deploy.DispatcherSameAsParent)
|
case _: DispatcherSameAsParent => props.withDispatcher(Deploy.DispatcherSameAsParent)
|
||||||
}).withDeploy(Deploy.local) // disallow remote deployment for typed actors
|
}).withDeploy(Deploy.local) // disallow remote deployment for typed actors
|
||||||
|
|
||||||
val p2 = deploy.firstOrElse[MailboxSelector](MailboxSelector.default()) match {
|
val mailboxProps = deploy.firstOrElse[MailboxSelector](MailboxSelector.default()) match {
|
||||||
case _: DefaultMailboxSelector => p1
|
case _: DefaultMailboxSelector => dispatcherProps
|
||||||
case BoundedMailboxSelector(capacity, _) =>
|
case BoundedMailboxSelector(capacity, _) =>
|
||||||
// specific support in classic Mailboxes
|
// specific support in classic Mailboxes
|
||||||
p1.withMailbox(s"${Mailboxes.BoundedCapacityPrefix}$capacity")
|
dispatcherProps.withMailbox(s"${Mailboxes.BoundedCapacityPrefix}$capacity")
|
||||||
case MailboxFromConfigSelector(path, _) =>
|
case MailboxFromConfigSelector(path, _) =>
|
||||||
props.withMailbox(path)
|
props.withMailbox(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
p2.withDeploy(Deploy.local) // disallow remote deployment for typed actors
|
mailboxProps.withDeploy(Deploy.local) // disallow remote deployment for typed actors
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ import akka.actor.typed.scaladsl.AskPattern._
|
||||||
|
|
||||||
object TypedActorBenchmark {
|
object TypedActorBenchmark {
|
||||||
// Constants because they are used in annotations
|
// 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 numMessagesPerActorPair = 1000000 // messages per actor pair
|
||||||
|
|
||||||
final val numActors = 512
|
final val numActors = 512
|
||||||
|
|
|
||||||
|
|
@ -83,20 +83,7 @@ be used.
|
||||||
|
|
||||||
### Default Mailbox
|
### Default Mailbox
|
||||||
|
|
||||||
The default mailbox is used when the mailbox is not specified.
|
The default mailbox is used when the mailbox is not specified and is the **SingleConsumerOnlyUnboundedMailbox**>
|
||||||
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"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### Which Configuration is passed to the Mailbox Type
|
### 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:
|
Akka ships with a number of mailbox implementations:
|
||||||
|
|
||||||
*
|
*
|
||||||
**UnboundedMailbox** (default)
|
**SingleConsumerOnlyUnboundedMailbox** (default)
|
||||||
* The default mailbox
|
* This is the default
|
||||||
* 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!
|
|
||||||
* Backed by a Multiple-Producer Single-Consumer queue, cannot be used with `BalancingDispatcher`
|
* Backed by a Multiple-Producer Single-Consumer queue, cannot be used with `BalancingDispatcher`
|
||||||
* Blocking: No
|
* Blocking: No
|
||||||
* Bounded: No
|
* Bounded: No
|
||||||
* Configuration name: `"akka.dispatch.SingleConsumerOnlyUnboundedMailbox"`
|
* 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**
|
**NonBlockingBoundedMailbox**
|
||||||
* Backed by a very efficient Multiple-Producer Single-Consumer queue
|
* Backed by a very efficient Multiple-Producer Single-Consumer queue
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue