Live data from Hacker News

Erlang/OTP 27 Highlights

erlang.org

41–50 of 53 posts

Re: Erlang/OTP 27 Highlights

#41
post #30

Earlier quoted context omitted.

Tasks are not processes, and that would be a wrong thing to do, and so would be "isolated heaps" given performance requirements faced by .NET - you do want to share memory through concurrent data structures (which e.g. channels are despite what go apologists say), and easily await them when you want to. CSP, while is nice on paper, has the same issues as e.g. partitioning in Kafka, just at a much lower level where it…

> and that would be a wrong thing to do, and so would be "isolated heaps" - you do want to share memory through concurrent data structures (which e.g. channels are despite what go apologists say), and easily await them when you want to. It depends on the context. In some contexts absolutely not. If we share memory, and these tasks start modifying global data or taking locks and then crash, can those tasks be safely r…

RE: locks and concurrently modified data-structures

It comes down to the kind of lock being used. Scenarios which require strict data sharing handle them as they see fit - for recoverable states the lock can simply be released in a `finally` block. Synchronous/blocking `lock` statement does this automatically. All concurrent containers offered by standard library either do not throw or their exceptions indicate a wrong operation/failed precondition/etc. and can be recovered from (most exceptions in C# are, in general).

This does not preclude the use of channel/mailbox and other actor patterns (after all, .NET has Channel and ConcurrentQueue or if you would like to go from 0 to 100 - Akka and Orleans, and the language offers all the tools to write your own fast implementation should you want that).

Overall, I can see value of switching to Erlang if you are using a platform/language with much worse concurrency primitives, but with F# and C#, personally, Erlang and Elixir appear to be a sidegrade as .NET applications tend to scale really well with cores even when implemented sloppily.

Re: Erlang/OTP 27 Highlights

#42
post #40

Earlier quoted context omitted.

What value does isolated heap offer for memory-safe languages? Task exceptions can simply be handled via try-catch at the desired level. Millions of concurrently handled tasks is not that high of a number for .NET's threadpool. It's one thing among many that is "nothingburger" in .NET ecosystem which somehow ends up being sold as major advantage in other languages (you can see it with other features too - Nest.js as…

Briefly, the tradeoff that Erlang and its independent process heaps model make is that garbage collection (and execution in general) occurs per-process. In practical terms, this means you have lots of little garbage collections and much fewer "large" (think "full OS process heap") collections. This provides value in a few ways: - conceptually: it is very simple. i.e., the garbage collection of one process is not logi…

Thanks!

Re: Erlang/OTP 27 Highlights

#43
post #30

Earlier quoted context omitted.

> and that would be a wrong thing to do, and so would be "isolated heaps" - you do want to share memory through concurrent data structures (which e.g. channels are despite what go apologists say), and easily await them when you want to. It depends on the context. In some contexts absolutely not. If we share memory, and these tasks start modifying global data or taking locks and then crash, can those tasks be safely r…

RE: locks and concurrently modified data-structures It comes down to the kind of lock being used. Scenarios which require strict data sharing handle them as they see fit - for recoverable states the lock can simply be released in a `finally` block. Synchronous/blocking `lock` statement does this automatically. All concurrent containers offered by standard library either do not throw or their exceptions indicate a wro…

If you use an 96 core machine, or 96 individual machines with single core each, the Erlang code is going to look pretty much the same.

Re: Erlang/OTP 27 Highlights

#44
post #27

The `maybe_expr' meta pattern matching fallback mechanic is nice, and can surely help avoid a lot of boilerplate code while simultaneously encapsulating the logic in a structure which is easy to read and reason about. It's also not a thing in any other programming language I've learned- C, Java/Scala/C#/C++, Go, Javascript, Tcl, Bash(lol), PHP, Forth, ML, and so on. I had to look up it's usage though, because I'm new…

You do realize that Rust, C#/F#, Kotlin/Scala, now Java to an extent, pretty much all FP and many other languages have extensive pattern matching support?

It goes beyond your typical pattern matching, check out the link in my first post if you're curious to learn!

Re: Erlang/OTP 27 Highlights

#45

Earlier quoted context omitted.

this. Erlang's concurrency support is one of those things you can't unsee. Going back to sequential-by-design languages (which is pretty much every other industrial quality language bar go[1]) just feels cumbersome: C/C++/C#/Python/...: "You want concurrency? Sure. We have OS processes, and threads, and this cool new async doohickey. Pick whatever you fancy! Oh, but by the way: you can't use very many processes cos t…

C# tasks are lightweight, and I'd expect for per-task overhead to be significantly lower than that of Erlang's. e.g.: var delay = Task.Delay(3_000); var tasks = Enumerable .Repeat(async () => await delay, 1_000_000) .Select(f => f()); Console.WriteLine("Waiting for 1M tasks..."); await Task.WhenAll(tasks); Console.WriteLine("Finished!"); edit: consider suggesting a comparable example in Erlang before downvoting :)

I'm not really sure what this proves, since there aren't really good reasons for spawning 1 million processes that do nothing except sleeping. A more convincing demonstration would be spawning 1 million state machines that each maintain their own state and process messages or otherwise do useful work. But examples of that on the BEAM have been around for years.

So, in interest of matching this code I wrote an example of spawning 1_000_000 processes that each wait for 3 seconds and then exit.

This is Elixir, but this is trivial to do on the BEAM and could easily be done in Erlang as well:

    #!/usr/bin/env elixir
    
    [process_count | _] = System.argv()
    
    count = String.to_integer(process_count)
    
    IO.puts "spawning #{count} processes"
    
    1..count
    |> Enum.map(fn _c ->
      Task.async(fn -> 
        Process.sleep(3_000) 
      end)
    end)
    |> Task.await_many()

The default process limit is 262,000-ish for historical reasons but it is easy to override when running the script:

    » time elixir --erl "+P 1000001" process_demo.exs 1000000
    spawning 1000000 processes
    
    ________________________________________________________
    Executed in    6.85 secs    fish           external
       usr time   11.79 secs   60.00 micros   11.79 secs
       sys time   15.81 secs  714.00 micros   15.81 secs

I tried to get dotnet set up on my mac to run the code in your example to provide a timing comparison, but it has been a few years since I wrote C# professionally and I wasn't able to quickly finish the required boilerplate set up to run it.

Ultimately, although imo the BEAM performs quite well here, I think these kind of showy-but-simple tests miss the advantages of what OTP provides: unparalleled introspection abilities in production on a running system. Unfortunately, it is more difficult to demonstrate the runtime tools in a small code example.

Re: Erlang/OTP 27 Highlights

#46

Earlier quoted context omitted.

C++: zero-cost leaky abstraction with unlimited cognitive and development cost Functional programming languages: Unlimited good abstractions of unknown cost I don't feel like there's a great third option. Go is pretty good.

I hate to be that guy, but if you want "C++ but also functional programming" then... Well, then Rust is in fact the language which you're looking for.

If anything the cognitive load of rust is worse than C++

Re: Erlang/OTP 27 Highlights

#47
post #36

Earlier quoted context omitted.

GC determinism is one of the things you get. Another one is non cooperative asynchronous termination.

Pretty much all efficient GC implementations are inherently non-deterministic, even if predictable. How can this improve predictability of GC impact?

No global GC. Each erlang process does its own GC, and the GC only happens when the process runs out of space (ie. the heap and stack meet).

You can for example configure a process to have enough initial memory so as not to ever run into GC, this is especially useful if you have a process that does a specific task before terminating. Once terminated the entire process memory is reclaimed.

Re: Erlang/OTP 27 Highlights

#48
post #47

Earlier quoted context omitted.

Pretty much all efficient GC implementations are inherently non-deterministic, even if predictable. How can this improve predictability of GC impact?

No global GC. Each erlang process does its own GC, and the GC only happens when the process runs out of space (ie. the heap and stack meet). You can for example configure a process to have enough initial memory so as not to ever run into GC, this is especially useful if you have a process that does a specific task before terminating. Once terminated the entire process memory is reclaimed.

There is no free lunch in software - the tradeoff is binary serialization and/or data copying over simple function calls. The same goes for GC - for efficient GC, it has to come with quite involved state which has additional cost of spawning. At this point, might use bump allocator, or an arena. Either way, Gen0 (it's a generational GC) in .NET acts like one, STW pauses can be sub-millisecond and are pretty much non-issue, given that you don't even need to allocate that often compared to many other high-level languages.

Re: Erlang/OTP 27 Highlights

#49

Earlier quoted context omitted.

C# tasks are lightweight, and I'd expect for per-task overhead to be significantly lower than that of Erlang's. e.g.: var delay = Task.Delay(3_000); var tasks = Enumerable .Repeat(async () => await delay, 1_000_000) .Select(f => f()); Console.WriteLine("Waiting for 1M tasks..."); await Task.WhenAll(tasks); Console.WriteLine("Finished!"); edit: consider suggesting a comparable example in Erlang before downvoting :)

I'm not really sure what this proves, since there aren't really good reasons for spawning 1 million processes that do nothing except sleeping. A more convincing demonstration would be spawning 1 million state machines that each maintain their own state and process messages or otherwise do useful work. But examples of that on the BEAM have been around for years. So, in interest of matching this code I wrote an example…

The argument regarding representativeness is fair. But I think it is just as important for the basics to be fast, as they represent a constant overhead most other code makes use of. There are edge cases where unconsumed results get optimized away and other issues that make the results impossible to interpret, and these must be accounted for, but there is also a risk of just reducing the discussion to "No true Scotsman" which is not helpful in pursuit of "how do we write fast concurrent code without unnecessary complexity".

I have adjusted the example to match yours and be more expensive on .NET - previous one was spawning 1 million tasks waiting for the same asynchronous timer captured by a closure, each with own state machine, but nonetheless as cheap as it gets - spawning an asynchronously yielding C# task still costs 96B[0] even if we count state machine box allocation (closer to 112B in this case iirc).

To match your snippet, this now spawns 1M tasks that wait the respective 1M asynchronous timers, approximately tripling the allocation traffic.

    var count = int.Parse(args[0]);

    Console.WriteLine($"spawning {count} tasks");

    var tasks = Enumerable
        .Range(0, count)
        .Select(async _ => await Task.Delay(3_000));

    await Task.WhenAll(tasks);
In order to run this, you only need an SDK from https://dot.net/download. You can also get it from homebrew with `brew install dotnet-sdk` but I do not recommend daily driving this type of installation as Homebrew using separate path sometimes conflicts with other tooling and breaks SDK packs discovery of .NET's build system should you install another SDK in a different location.

After that, the setup process is just

    mkdir CSTasks && cd CSTasks
    dotnet new console --aot
    echo '{snippet above}' > Program.cs
    dotnet publish -o .
    time ./CSTasks
Note: The use of AOT here is to avoid it spamming files as the default publish mode is "separate file per assembly + host-provided runtime" which is not as nice to use (historical default). Otherwise, the impact on the code execution time is minimal. Keep in mind that upon doing the first AOT compilation, it will have to pull IL AOT compiler from nuget feed.

Once done, you can just nuke the `/usr/local/share/dotnet` folder if you don't wish to keep the SDK.

Either way, thank you for putting together your comment - Elixir does seem like a REPL-friendly language[1] in many ways similar to F#. It would be impolite for me to not give it a try as you are willing to do the same for .NET.

[0]: https://devblogs.microsoft.com/dotnet/performance-improvemen...

[1]: there exist dotnet fsi as well as dotnet-script which allow using F# and C# for shell files in a similar way, but I found the startup latency of the latter underwhelming even with the cached compilation it does. It's okay, but not sub-100ms an sub-20ms you get with properly compiled JIT and AOT executables.

Re: Erlang/OTP 27 Highlights

#50
I really appreciate that this software has been under continuous development, maintenance and improvement for so long. Its nice to see such long term support, no better way to preserve engineering insights, than continuing to use them in production.
Post reply on HN