I think another way to frame my question would be: which is the basic unit of parallel execution in Bastion? A thread? Or a separate process? There are mentions of lightweight processes and subprocesses in the README but it is rather vague what these are.
An actor is:
1. A lightproc, which, per my understanding, are async-spawned threads returning (optional?) Futures [0].
2. A ProcHandle [1] that lets you define process-state (like pid), control process-exec (like cancel, suspend?), listen on progress of a given lightproc that is run by BastianExecutors [2], whilst the message passing / supervisor semantics is handled by Bastion [3].
https://akka.io/ on JVM would be a better comparison to this than BEAM's implementation of actors, I think.
[0] https://github.com/bastion-rs/bastion/blob/2d9dc705962f30fbf...
[1] https://github.com/bastion-rs/bastion/blob/2d9dc705962f30fbf...
[2] https://github.com/bastion-rs/bastion/blob/2d9dc705962f30fbf...
[3] https://docs.rs/bastion/0.3.4/bastion/struct.Bastion.html
https://docs.rs/bastion/0.3.4/bastion/macro.msg.html
Seems less clean to read than Riker (https://riker.rs), though that doesn't really do async well.
The Getting Started example gives some useful insights:
https://github.com/bastion-rs/bastion/blob/master/bastion/ex...
Origin title: `The missing part of actor-model programming in rust`.
If it's 'Erlang for Rust developers' I'd be curious to get a feel for how well it integrates with everything. A lot of what Erlang does is kind of difficult to shoehorn in via a library, but I don't know Rust well so maybe it all integrates in a very natural way.
1. https://github.com/actix/actix 2. https://github.com/rsimmonsjr/axiom
In concurrent programming, there are a few mental models/approaches you can use to achieve it. Each of them have different "values systems" and tradeoffs, if you will.
In a nutshell, you have:
- Locks (Mutex/Semaphore)
- Communicating Sequential Processes
- Software Transactional Memory
- Actor Model
The Actor Model is a particularly powerful paradigm because it isolates processes and works via message passing and spawning. The reason why Erlang/Elixir are fault-tolerant is because of the BEAM's process model, any given process (more or lesss) can fail and it's not a problem due to isolation.
What this library allows you to do is architect applications in ways such that they are much more resilient to failure and easier to scale out + parallelize/distribute.
It doesn't have to be a networked application either, any code process can be an actor. It applies to any software.
If you want a great overview of the Actor model, there are some slides here which do a fantastic job of illustrating it:
https://cs.nyu.edu/wies/teaching/ppc-14/material/lecture10.p...
https://github.com/bastion-rs/bastion/tree/master/bastion/ex...
The JVM manages this - there are many options:
- reading a flag - patching the running - changing memory protection and causing a segfault
ptrace it?
https://pragprog.com/book/pb7con/seven-concurrency-models-in...
It may be wrong to say we need a better Erlang, but for modern web development we certainly could use a fair bit more compiler enforced type safety for writing more correct programs. Mostly due to the lack of a proper type system, Erlang is not particularly expressive as a language, although its primitives (processes & message passing) are well geared exactly for what it focuses on.
Erlang focuses strongly on fault-tolerance and subsequently on high availability, but I'm not sure this perk is so significant benefit anymore compared to various other runtimes spinning the wheels of your typical web server in a cloud setup. We rarely need to write servers anymore that keep running for many years straight without a restart, only patching code via hot reloads.
Just my take but since you asked, trading some fault tolerance for more correct programs would therefore probably be a fair trade-off for a new kind of Erlang.
Yeah; I always added type annotations to my code and ran Dialyzer...I wish there was a stricter compilation mode for that. That said, I really liked the 'optimistic' part of it, so I didn't spend a large amount of time correcting my type specs when proper testing proved it work.
I can agree with bfrog's comment too; Rust's typing can definitely help eliminate a bunch of classes of bugs...but honestly I'm not sure I ever ran into them using Erlang in production anyway. Immutable data + message passing tends to make it easy to implement things correctly, whereas some of Rust's more standout features seem designed to solve problems caused by the language itself picking a different set of tradeoffs (i.e., borrow checking as part of what is necessary to manage memory without risking it going out of scope prematurely, or being unable to be reclaimed at a deterministic time by the compiler). I'm not familiar enough with Rust myself to really comment though; I just know that in two and a half years of production Erlang, the only bug we ever encountered was caused by a C driver (and our own bad design in not circuit breaking calls to it, leading to restarts that trickled up the supervisor chain under heavier load than we'd tested for. None of which would Rust have been able to help us with. In fact, even the driver, the issue was an unnecessary network call that sometimes hit an empty cache, causing a huge network hiccup that led to an unhandled timeout). It got 'correctness' as well as 'fault tolerance'. At least as much as a language can (i.e., we could still implement the wrong things, such as when we implemented an O(N^2), but correct, algorithm, that we had to fix to an O(N) when we noticed certain calls being too slow)
- Strong static typing. It's 2020 and we should all stop pretending that it doesn't eliminate class of bugs. It does.
- Goes without saying since we mention Erlang but still -- full async support for both CPU and I/O intensive tasks. If one actor goes 100% CPU in an infinite loop everybody else should be unaffected (as much as the hardware allows for that). And if the compiler itself can detect infinite loops and just yell at you for them, even better! (But that borders on sci-fi at the moment.)
- Again related to the above: full non-voluntary preemption. You can insert your own yield points if you like but the runtime will choose if it will respect them or not.
- Obviously, raw speed. I love Elixir and with time I learned how to make its code minimally intrusive for the CPU -- most of my Elixir code basically glues things together, does a quick processing and gets the hell out of the way. 100% of my Elixir code always waits on DB or network requests and I am very proud of that. Still, I'd love such an amazing concept like the actor style parallelism and all the BEAM's goodies in general to come in a package that's 10x or 100x faster and make full use of modern hardware! SIMD / AVX included.
---
There could be more but these are just off the top of my head.
A much shorter answer would likely be: a BEAM VM with minimal memory and I/O and CPU overhead, fully utilising the hardware, and bringing correctness and less bugs with strong static typing.
Making it faster for certain things, as long as that doesn't hurt it in other ways, is always going to be a win.
So trying to reach for strong static typing and zero-copy message passing are natural next steps -- and if that's not possible with Elixir itself, we'll search for it in other languages.
At least that's the case for me.
For other types, it's not possible without either adopting Rust's memory model (but that's a huge set of tradeoffs to take on; completely change the language), or giving up the GC benefits of everything being process(stack) allocated, which would entail a whole new set of tradeoffs (and probably not be much faster).
I, personally, don't see that direction as a plus, as such.
Not sure about your third/fourth point; that's Erlang's behavior, no? One actor being busy won't starve others, for CPU or IO. It's pre-emptive; the VM counts reductions and moves on (and not really sure why, given that, you'd want user controlled pre-emption; I never had an issue with one actor starving others, unless calling out to some C code or something, and even that is mitigated with dirty schedulers). Detecting infinite loops could be optimistic, like Dialyzer's typing, I think, but could never be 100% because, yeah, halting problem.
And as above, totally agree on typing, though I personally like Dialyzer's optimistic approach (I just wish type specs were enforced).
But, per the original, I am totally on board with more languages supporting actors...I just was curious what 'a better Erlang' would look like. Some of your bullets seem "a better language (for my use case)", and not really aligned with Erlang's goals.
As for the zero-copy stuff, I am not educated enough to claim anything. I have just seen some claims by Rust and liked the idea of the borrowing -- but I know data in the stack is always going to be faster than data in the heap.
I am just wondering if we can't stop with this whole "copy your data" thing all the time.
My comment was a rant + a general musing of a guy who lately mostly codes Elixir; the lack of strong typing is a major pain at times, and sometimes I also wonder if the BEAM VM can't be much faster.
That's all. Apologies if my comments were off-topic.