Live data from Hacker News

Gleam OTP – Fault Tolerant Multicore Programs with Actors

github.com

41–50 of 89 posts

Re: Gleam OTP – Fault Tolerant Multicore Programs with Actors

#41

IMHO the actor model is great until you need to share something across processes, then you have a distributed computing problem inside your program. For developing fault tolerant multicore programs I think I'm better off using a functional effects system with software transactional memory like Scala/ZIO than Gleam/OTP. I can still use the actor model where appropriate. Plus the JVM software ecosystem and runtime obse…

I think it's also worth mentioning - that hasn't been mentioned yet, Erlang (which Gleam is built atop) is ... *the* language that facilitated the nine nines (99.9999999%) uptime; and one of the major components of its ability to do that came with the robust supervising and cross-machine infrastructures that inspired the actor systems later on.

This is, quite literally, Erlang's job. It's one job. And it is proven *excellent* at it.

Re: Gleam OTP – Fault Tolerant Multicore Programs with Actors

#42
post #2

I just started a small project using gleam / lustre, and so far I’m loving it. Worth trying if you’re on the fence, especially if you’re into static types, no nulls, functional, ML type languages. Plus beam of course.

Same and I like it too so far!

Some thoughts so far: Installing gleam installed about 50 packages on my system (possibly all erlang/elixir related). But what if I just wanted to transpile to js? Perhaps this is a packaging issue on my system though.

What I really wish is that Lua would be considered as another transpilation target. I think gleam could shine for DSLs in other programs but embedding Lua is 3x easier than embedding a js runtime imo.

In general, I find the nicest thing so far the community. And I want to say that the quality of libraries and resources in the gleam community seems exceptionally high. It reminds me of the rust community insofar as that for most hard problems someone smarter than me has already worked on it and published a good solution (e.g. lustre, squirrel). Then I would say you can also expect a lot of creativity and experimentation, the things that may fly under the radar in larger language ecosystems stand out here due to the growing and welcoming community.

Re: Gleam OTP – Fault Tolerant Multicore Programs with Actors

#43

Earlier quoted context omitted.

Interesting! I have a F# background, and thought to have read that some constructs I learned to appreciate are not available in Gleam (the one I can think of right now is currying, but I thought there were others). Also, Gleam otp didn't seem to be a priority. What's your experience regarding these 2 points?

The issue isn't that OTP isn't a priority for Gleam, but rather that it doesn't work with the static typing Gleam is implementing. This is why they've had to reimplement their own OTP functionality in gleam_otp . Even then, gleam_otp has some limitations, like being unable to support all of OTP's messages, named processes, etc. gleam_otp is also considered experimental at this point.

Having Erlang-style OTP support (for the most part) is very doable, I've written my own OTP layer instead of the pretty shoddy stuff Gleam ships with. It's not really that challenging of a problem and you can get stuff like typed processes (`Pid(message_type)`, i.e. we can only send `message_type` messages to this process), etc. out of it very easily.

This idea that static typing is such a massive issue for OTP style servers and messaging is a very persistent myth, to be honest; I've created thin layers on top of OTP for both `purerl` (PureScript compiled to Erlang) and Gleam that end up with both type-safe interfaces (we can only send the right messages to the processes) and are type-safe internally (we can only write the process in a type-safe way based on its state and message types).

Re: Gleam OTP – Fault Tolerant Multicore Programs with Actors

#44
post #24

Earlier quoted context omitted.

you are not blocked on response right ?

You can cast or call ( non blocking, or blocking) you can do either.

how would you get a deadlock with non-blocking requests ?

Re: Gleam OTP – Fault Tolerant Multicore Programs with Actors

#45
post #43

Earlier quoted context omitted.

The issue isn't that OTP isn't a priority for Gleam, but rather that it doesn't work with the static typing Gleam is implementing. This is why they've had to reimplement their own OTP functionality in gleam_otp . Even then, gleam_otp has some limitations, like being unable to support all of OTP's messages, named processes, etc. gleam_otp is also considered experimental at this point.

Having Erlang-style OTP support (for the most part) is very doable, I've written my own OTP layer instead of the pretty shoddy stuff Gleam ships with. It's not really that challenging of a problem and you can get stuff like typed processes (`Pid(message_type)`, i.e. we can only send `message_type` messages to this process), etc. out of it very easily. This idea that static typing is such a massive issue for OTP style…

I wholeheartedly agree with you that gleam_otp is janky. Still, actor message passing is only part of the picture. Here are some issues that make static typing difficult in OTP:

• OTP processes communicate via the actor model by sending messages of any type. Each actor is responsible for pattern-matching the incoming message and handling it (or not) based on its type. To implement static typing, you need to know at compile time what type of message an actor can receive, what type it will send back, and how to verify this at compile time.

• OTP's GenServer behaviour uses callbacks that can return various types, depending on runtime conditions. Static typing would require that you predefine all return types for all callbacks, handle type-safe state management, and provide compile-time guarantees when handling these myriad types.

• OTP supervisors manage child processes dynamically, which could be of any type. To implement static typing, you would need to know and define the types of all supervised processes, know how they are going to interact with each other, and implement type-safe restart strategies for each type.

These and other design roadblocks may be why Gleam chose to implement primitives, like statically typed actors, instead of GenServer, GenStage, GenEvent, and other specialized OTP behaviours, full supervisor functionality, DynamicSupervisor, and OTP's Registry, Agent, Task, etc.

OTP and BEAM are Erlang and Elixir's killer features, and have been battle-tested in some of the most demanding environments for decades. I can't see the logic in ditching them or cobbling together a lesser, unproven version of them to gain something as mundane as static typing.

EDIT: I completely missed the word "actor" as the second word in my second sentence, so I added it.

Re: Gleam OTP – Fault Tolerant Multicore Programs with Actors

#46
post #12
post #10

Earlier quoted context omitted.

``` Whenever you message another process and need a reply there is a risk of deadlock. ``` can you please explain how there is risk of deadlock here ? thanks !

Risk of deadlock is real if you have processes calling each-other in a cyclic way. e.g. process A sends GenServer call to process B, that then sends a GenServer call to process A to in order to handle the original call. However, process A is busy waiting on B to reply to it's initial call. This is rarely a problem in practice however.

Wouldn't you just `cast` instead of `call` if you thought this was going to be an issue?

Re: Gleam OTP – Fault Tolerant Multicore Programs with Actors

#47

Earlier quoted context omitted.

Whenever you message another process and need a reply there is a risk of deadlock. I didn't find any primtives in OTP for handling this, you have to structure your actor interaction to avoid it. You can't just have a little bit of shared memory. The actor model doesn't really offer any benefit over other models while bringing significant downsides. Plus, there are major downsides to using an unpopular platform like E…

> Whenever you message another process and need a reply there is a risk of deadlock. There are edge cases, sure, but I have yet to encounter a deadlock after 7 years of professional work with Elixir. > I didn't find any primtives in OTP for handling this See `GenServer.call/2`. This covers 99% of call/return patters in distributed systems. I take it you haven’t written much (any?) Elixir because you would have found…

>> Plus, there are major downsides to using an unpopular platform like Erlang/BEAM.

> The BEAM is popular.

At this point I'd say it's more popular than ZIO, an effects/io/concurrency library basically implementing its own language and threading model on top of Scala

Re: Gleam OTP – Fault Tolerant Multicore Programs with Actors

#48

PureScript is a mature functional programming language with an Erlang back end, if you want another statically typed alternative for BEAM. It is basically a dialect of Haskell with strict evaluation and row polymorphism.

The JS backend is mature, but the Erlang backend and accompanying ecosystem is very small compared to Gleam.

Re: Gleam OTP – Fault Tolerant Multicore Programs with Actors

#49
post #2

I just started a small project using gleam / lustre, and so far I’m loving it. Worth trying if you’re on the fence, especially if you’re into static types, no nulls, functional, ML type languages. Plus beam of course.

Same and I like it too so far! Some thoughts so far: Installing gleam installed about 50 packages on my system (possibly all erlang/elixir related). But what if I just wanted to transpile to js? Perhaps this is a packaging issue on my system though. What I really wish is that Lua would be considered as another transpilation target. I think gleam could shine for DSLs in other programs but embedding Lua is 3x easier th…

> Perhaps this is a packaging issue on my system though.

Gleam is only officially distributed via the releases on GitHub [1] so if you pick up Gleam from a package manager that's always maintained by someone else. I think most of those community distributions do include Erlang and bits which is probably what pulled in all those extra packages!

[1]: https://github.com/gleam-lang/gleam/releases/tag/v1.13.0

Re: Gleam OTP – Fault Tolerant Multicore Programs with Actors

#50
post #2

I just started a small project using gleam / lustre, and so far I’m loving it. Worth trying if you’re on the fence, especially if you’re into static types, no nulls, functional, ML type languages. Plus beam of course.

I like all of the above but have no understanding of the BEAM or OTP. Can you recommend a good place to start learning about that?
Post reply on HN