Looking for simple examples showing how to use distributed actors

I find the concept of distributed computing very fascinating, hence my interest in distributed actors.

Currently I rely on XPC services to isolate computations from GUI front ends.

The current documentation on distributed actors is not very generous in what it offers, but provides a link to the TicTacFish, which is all SwiftUI obscuring the important details.

Can anybody provide a simple command-line example that demonstrates how to perform something very simple, such as adding two numbers? (the actor lives in its own process on the same machine as the driver.)

The reason for this is that I want to explore whether I can transition away from XPC services to distributed actors to implement the same functionality.

Thank you for reading this far.

PS: I hope @ktoso is watching. :slight_smile:

Not a simple example, but: https://forums.swift.org/t/swift-chat-showcase-for-distributed-application/

2 Likes

Btw, I’ve wanted to add command-line interface, will get back soon!

1 Like

I found WebSocketActors – Swift Package Index to be an easy way to get started and play around with Distributed Actors.

1 Like

Hello there, thanks for the interest!

Maybe just as a small reminder that the Distributed module is that it's a "bring your own runtime" language feature, so it's somewhat open to "what transport do you want?" You asked about XPC, and there isn't one floating around sadly, but there is a sub-process one which may fit your bill for now :slight_smile:

The implementations folks have listed here -- websockets, subprocess actors (and wasm), cluster or OrdoOne's implementation, are all good examples of a system implementation.

But anyway, you specifically asked about a simple "same machine, different process" example:

how to perform something very simple, such as adding two numbers? (the actor lives in its own process on the same machine as the driver.)

So the simplest system for that will be the swift-subprocess-distributedactors project by @mlienert:

In the root folder launch ./build_and_test.sh. It will build the plugins and launch the host.

Should output the following:

[Subprocess] Hello Swift!
[Subprocess] Bonjour Swift!
[Wasm] Hello Swift!
[Wasm] Bonjour Swift!
  • Two first lines are the host calling distributed actors in the two children processes.
  • Two last lines are the host calling distributed actors in the two WasmKit virtual machine.

I hope this helps :slight_smile:

I should also comment on

The reason for this is that I want to explore whether I can transition away from XPC services to distributed actors to implement the same functionality.

as this isn't quite the right question to be asking. So since distributed actors still need a transport and XPC offers some very integrated in the OS interactions, and how the services are launched etc... "distributed actors" are not really a replacement to XPC, but you could imagine an XPCActorSystem that makes using Swift with XPC much more pleasant :slight_smile: The transport would still be XPC though, even if APIs and ways to interact with it would be different.


And yeah I'd like to acknowladge the annoying missing documentation from the swift book... this has been stuck in processes for a while now but we've finally resolved it and I'll be putting up a proposal to the language book to document the Distributed language feature some more soon. Thanks for your patience on that.

Some of such "general docs about how distributed actors work" can be find in this section of the cluster docs btw: Introducing Distributed Actors perhaps this helps to wrap your head around it.

5 Likes

I've created the XPCDistributedActorSystem, which enables using distributed actors over XPC on macOS.

It's insecure and rough around the edges, but it does work. Some public interest would help motivate me to improve it. :slight_smile:

2 Likes

For those who might be interested I will allow myself to give the correct link to the distributed system that was made by OrdoOne: GitHub - ordo-one/package-distributed-system
(Ktoso apparently made a typo and gave a link to the apple repo)