|
|
|
|
|
by neonsunset
754 days ago
|
|
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 :) |
|
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:
The default process limit is 262,000-ish for historical reasons but it is easy to override when running the script: 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.