Live data from Hacker News

Gleam OTP – Fault Tolerant Multicore Programs with Actors

github.com

31–40 of 89 posts

Re: Gleam OTP – Fault Tolerant Multicore Programs with Actors

#31
post #5

Earlier quoted context omitted.

In Elixir/Gleam/OTP.., the entire program is a collection of progresses which are isolated from each other. Even if you don’t implement the actor pattern, passing state between processes and coordinating is a solved problem. We have primitives like tasks, agents, GenServer, Supervisors etc.

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. 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.

I see a lot of people that dislike Erlang that run into this or are afraid of running into it.

Receive with timeout is certainly a primative to handle this, and there's things like process aliases so that late responses can be more easily ignored. But, there's nothing structural preventing it. It's just that when you do it, it hurts, so hopefully you stop doing it.

But when you're in a situation whete you've setup circular messaging, it's very easy to identify. You see a process (A) that has is making no progress and/or has a large mailbox. You see the stack trace shows it is messaging process B, you inspect process B to see why it didn't respond and see it is messaging process A and there you go. Or you look at process A's mailbox and see that it has requests related to the request it's already trying to fill.

> The actor model doesn't really offer any benefit over other models while bringing significant downsides.

I find the actor model makes many types of request/response for persistent state to become very simple. A process owns the state, and application level read/write messages are sent to that process. The mailbox serializes access to provide an ordering and to make changes atomic. You certainly have choose your messages; if you have a counter and do a get and a set message, you will lose updates; you need to do increment/decrement/add kind of messages; same thing for larger/more complex datastructures. Linked datastructures are still tricky.

It's also super nice for request/response connection handling. Just write straight line code that reads from the connection when it needs a request and writes to it when the response has been computed. When you need to be asynchronous, it's more complex, but not so terrible. The process becomes a loop waiting for a fully formed request from the client (which then gets sent off to a request processor) or a reply from a processor (which then gets sent to the client) ... Java's Loom green threads will likely socialize this further than Erlang has.

This kind of feeds into your other question, but IMHO, Actors let you focus on a process owning state and the messages it receives and how they change the state. You don't need to model for the computer where those messages come from, that's emergent system behavior. BEAM doesn't need to know, and doesn't ask, in part because as a changable distributed system, there's not really a way to know. What sends what to who is essential complexity of the system, but the system doesn't need to know about it. If you had a full accounting of how messages are sent, then you potentially find message loops, but ... it's easier to just find and fix any loops at runtime. (hotloading code can make it very low cost to deploy changes, which makes it more reasonable to spend less effort finding issues before release)

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

Sure, you have to do more work yourself. On the otherhand, relying on the work of others isn't always less work than doing it yourself. There are at least a few Erlang consulting shops you can go to if you really need something and are unwilling or unable to do it. You can't find a lot of answers on stackexchange, but you also don't find a lot of wrong or outdated answers either.

Re: Gleam OTP – Fault Tolerant Multicore Programs with Actors

#32
post #30

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 I'm better off using a functional effects system with software transactional memory like Scala/ZIO than Gleam/OTP Translation: I think I'm better off using needlessly complex overengineered monstrosity that takes insane effort to do even the simplest of things, and that still gives me no actual guarantees, than a simple system that has been battle tested over decades of actual hardcore industrial use.

This sounds like a "I could not get my head around ZIO/Fuctional Effects ergo it's a needlessly complex overengineered monstrosity" argument.

In fact, functional effects provide another elegant solution to problems requiring structured concurrency. You might like it, you might not. But there are many engineers in the Scala community who were bitten by the exact issues of actor deadlocking / difficulty of debugging compared to functional effects that refactored enterprise codebases from Akka (Scala actors) to functional effects.

"A simple system that has been battle tested over decades of actual hardcore industrial use". The JVM certainly is not far from that.

Re: Gleam OTP – Fault Tolerant Multicore Programs with Actors

#33
post #26
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.

For someone who hasn’t worked with either, is it better to learn gleam/lustre better or elixir/phoenix?

My path is a little different. I have used Haskell, and I'm looking to get into OTP.

My original plan was either Elixir or vanilla Erlang depending on which one suits my sensibilities better. Reading about Gleam recently has me super, super excited. That's definitely going to be my path now.

I don't know if Gleam is the best entry into the world of rich types that you find in a language like Haskell--I'm yet to actually build something with it.

What I can tell you is that Haskell is a complete joy to use and it honestly ruins most other programming for me. So as a direction, I cannot recommend it enough, and I'm hoping, for my sake and yours, that Gleam offers a similarly stimulating sandbox.

Just a warning that it will take time to get used to "higher-kinded" types. It's an exercise in head scratching and frustration at first. The reward part arrives when you start thinking in types yourself and you know which ones to reach for and when you find the libraries you want by entering a signature on Hoogle.

Re: Gleam OTP – Fault Tolerant Multicore Programs with Actors

#34
post #30

Earlier quoted context omitted.

> I think I'm better off using a functional effects system with software transactional memory like Scala/ZIO than Gleam/OTP Translation: I think I'm better off using needlessly complex overengineered monstrosity that takes insane effort to do even the simplest of things, and that still gives me no actual guarantees, than a simple system that has been battle tested over decades of actual hardcore industrial use.

This sounds like a "I could not get my head around ZIO/Fuctional Effects ergo it's a needlessly complex overengineered monstrosity" argument. In fact, functional effects provide another elegant solution to problems requiring structured concurrency. You might like it, you might not. But there are many engineers in the Scala community who were bitten by the exact issues of actor deadlocking / difficulty of debugging co…

> In fact, functional effects provide another elegant solution to problems requiring structured concurrency.

There's nothing elegant about ZIO.

> But there are many engineers in the Scala community who were bitten by the exact issues of actor deadlocking / difficulty of debugging compared to functional effects

Because you can't truly retrofit a proper actor model onto a runtime that doesn't support it, and doesn't have proper tools for them.

So they reach for third-party libs that try to implement half of Erlang, often poorly, and get understandably bitten by issues.

> "A simple system that has been battle tested over decades of actual hardcore industrial use". The JVM certainly is not far from that.

The JVM isn't built around built-in support for concurrency and distributed computing.

Erlang's BEAM is. And its built-in primitives and standard library has been around for over three decades.

Re: Gleam OTP – Fault Tolerant Multicore Programs with Actors

#35
post #26

Earlier quoted context omitted.

For someone who hasn’t worked with either, is it better to learn gleam/lustre better or elixir/phoenix?

My path is a little different. I have used Haskell, and I'm looking to get into OTP. My original plan was either Elixir or vanilla Erlang depending on which one suits my sensibilities better. Reading about Gleam recently has me super, super excited. That's definitely going to be my path now. I don't know if Gleam is the best entry into the world of rich types that you find in a language like Haskell--I'm yet to actua…

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?

Re: Gleam OTP – Fault Tolerant Multicore Programs with Actors

#36
post #26
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.

For someone who hasn’t worked with either, is it better to learn gleam/lustre better or elixir/phoenix?

As someone who comes from Haskell/ML-like languages, I decided to opt for Elixir and Phoenix for my latest project, simply because of the maturity of the web framework and LiveView. If I weren't building a web app, I'd probably have gone with Gleam instead.

Edit: I do miss static typing, but it's worth it to not have to reinvent the web framework wheels myself.

Re: Gleam OTP – Fault Tolerant Multicore Programs with Actors

#37
post #31

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. 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. I see a lot of people that dislike Erlang that run into this or are afraid of running into it. Receive with timeout is certainly a primative to handle this, and there's thi…

I have no idea how you'd solve this even if you were not using have the actor model, if you had functions that triggered a 'functional ring of functions', you'd have the same problem.

Re: Gleam OTP – Fault Tolerant Multicore Programs with Actors

#38
post #24
post #12

Earlier quoted context omitted.

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.

you are not blocked on response right ?

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

Re: Gleam OTP – Fault Tolerant Multicore Programs with Actors

#39
post #26
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.

For someone who hasn’t worked with either, is it better to learn gleam/lustre better or elixir/phoenix?

In my opinion, Elixir and Phoenix will give you a better experience with BEAM and OTP, excellent tooling, a more mature ecosystem, and one of the best web frameworks ever to exist. I think Gleam is cool, but I can't see trading these benefits in for static typing.

To be fair, I can't think of anything I care less about than static typing, so please keep that in mind when entertaining my opinion.

Re: Gleam OTP – Fault Tolerant Multicore Programs with Actors

#40

Earlier quoted context omitted.

My path is a little different. I have used Haskell, and I'm looking to get into OTP. My original plan was either Elixir or vanilla Erlang depending on which one suits my sensibilities better. Reading about Gleam recently has me super, super excited. That's definitely going to be my path now. I don't know if Gleam is the best entry into the world of rich types that you find in a language like Haskell--I'm yet to actua…

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.
Post reply on HN