Skip to content

Conversation

@ktoso
Copy link
Member

@ktoso ktoso commented Jun 28, 2020

I realized we didn't offer a Dispatch based dispatcher, this implements it naively.

TODO: a few more tests

@ktoso ktoso added this to the 0.5.0 - Cluster Hardening milestone Jun 28, 2020
@ktoso ktoso added the t:actor label Jun 28, 2020
@ktoso ktoso self-assigned this Jun 28, 2020
@ktoso ktoso removed their assignment Jun 28, 2020
Copy link
Member

@yim-lee yim-lee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Can take care of renaming (if wanted) in another PR

import Dispatch
import NIO

// TODO: Consider renaming to "ActorScheduler" perhaps?
Copy link
Member

@yim-lee yim-lee Jun 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does it do though? *Executor (comment right below) might be more fitting?

Copy link
Member Author

@ktoso ktoso Jun 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah good point... The word "scheduler" is sadly very overloaded -- could be "at some point in time scheduler" or those "just thread pool manager" – in libs like Rx or Combine those are called schedulers and technically it's the right word...

Akka wording was always "dispatcher" though I guess it's not necessarily the best... There the other words on the JVM are executors indeed. WDYT @drexin ? I'm somehow not in love with "dispatcher" the more i looked at it; "It schedules the actors execution" is kind of the right phrase, but "it executes the actor" also sounds correct I guess (though a bit macabre 😆 though actor internals often sound like that 😉).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note... we also have Scheduler:

internal protocol Scheduler {
    func scheduleOnce(delay: TimeAmount, _ f: @escaping () -> Void) -> Cancelable

    func scheduleOnce<Message>(delay: TimeAmount, receiver: ActorRef<Message>, message: Message) -> Cancelable

    func schedule(initialDelay: TimeAmount, interval: TimeAmount, _ f: @escaping () -> Void) -> Cancelable

    func schedule<Message>(initialDelay: TimeAmount, interval: TimeAmount, receiver: ActorRef<Message>, message: Message) -> Cancelable
}

which is the time related one, unlike MessageDispatcher today which is the "run the actor" one:

public protocol MessageDispatcher {
    // TODO: we should make it dedicated to dispatch() rather than raw executing perhaps? This way it can take care of fairness things

    var name: String { get }

    /// - Returns: `true` iff the mailbox status indicated that the mailbox should be run (still contains pending messages)
    // func registerForExecution(_ mailbox: Mailbox, status: MailboxStatus, hasMessageHint: Bool, hasSystemMessageHint: Bool) -> Bool

    func execute(_ f: @escaping () -> Void)
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The TODO there deciphered: // TODO: we should make it dedicated to dispatch() rather than raw executing perhaps? This way it can take care of fairness things

What I mean is scheduler.execute(actorShell) rather than scheduler.execute(mailbox.run), since then it knows which actor it's running and we can then in the future to some "locality" and "prefer the same thread as last time" etc tricks...

@ktoso ktoso changed the base branch from main to master June 29, 2020 02:23
@ktoso
Copy link
Member Author

ktoso commented Jun 30, 2020

Made the test do a bit more, will merge; thx for review!

@ktoso
Copy link
Member Author

ktoso commented Jun 30, 2020

Ah, of course... the lovely platform differences 😉

            #if os(Linux)
            try p.expectMessage().shouldStartWith(prefix: "dispatchQueue:<Dispatch.DispatchQueue")
            #else
            try p.expectMessage().shouldStartWith(prefix: "dispatchQueue:<OS_dispatch_queue_global:")
            #endif

@ktoso ktoso merged commit c14361e into apple:master Jun 30, 2020
@ktoso ktoso deleted the wip-dispatch-actors branch June 30, 2020 04:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants