How Much Memory Do You Need to Run 1 Million Concurrent Tasks?
published on 2023/05/22
Finally we see the increase in memory consumption of a C# program. But it is still very competitive. It even managed to slightly beat one of the Rust runtimes!
The distance between Go and others increased. Now Go loses over 12x to the winner. It also loses over 2x to Java, which contradicts the general perception of JVM being a memory hog and Go being lightweight.
Rust tokio remained unbeatable. This isn’t surprising after seeing how it did at 100k tasks.
The used code
List<Task> tasks = new List<Task>();
for (int i = 0; i < numTasks; i++)
{
Task task = Task.Run(async () =>
{
await Task.Delay(TimeSpan.FromSeconds(10));
});
tasks.Add(task);
}
await Task.WhenAll(tasks);
should be rewritten to
List<Task> tasks = new List<Task>();
for (int i = 0; i < numTasks; i++)
{
Task task = Task.Delay(TimeSpan.FromSeconds(10));
tasks.Add(task);
}
await Task.WhenAll(tasks);