News for hackers. Stuff that matters.
Re:Tokio 1.0 – async runtime for Rust by varajelle on Wednesday December 23, 2020 @05:02PM (#25522783)
> Considering a normal-sized Linux server can handle a million threads without much trouble, it really seems like misplaced effort

Seems like that would use a lot of memory for all the stacks

Re:Tokio 1.0 – async runtime for Rust by oblio on Wednesday December 23, 2020 @05:13PM (#25522877)
Based on this, the default value is 2MB: https://unix.stackexchange.com/questions/127602/default-stac...

So that would mean a lot of memory for 1 million threads, 2TB of RAM. But you can change the default. With a 64k stack you'd use up ~68GB of RAM, which doesn't seem like a lot for 1 million threads and 1 million requests happening at the same time.

Re:Tokio 1.0 – async runtime for Rust by platinumrad on Wednesday December 23, 2020 @06:09PM (#25523351)
Also worth noting that the entire stack isn't allocated at once so 1 million threads would be using 2TB/68GB of virtual address space, not 2TB/68GB of physical memory.
Re:Tokio 1.0 – async runtime for Rust by spacechild1 on Thursday December 24, 2020 @06:27AM (#25526634)
That is indeed a very important fact to keep in mind! Thread stack sizes have been a problem with 32 bit systems where you quickly run out of virtual memory because the adress space is not large enough. With 64 bit that is not a problem anymore.
Re:Tokio 1.0 – async runtime for Rust by akvadrako on Wednesday December 23, 2020 @05:29PM (#25523022)
That is also the maximum stack size which shouldn't normally be reached. You'll have to be careful how you use memory when you're handling a million clients, either as async or threaded.
Re:Tokio 1.0 – async runtime for Rust by varajelle on Wednesday December 23, 2020 @05:44PM (#25523155)
The point is that each stack need to be big enough for the worst case. That means it does not really scales to start many thousands of threads. While the futures themselves used in async code can be kept relatively small, as they only need to contain the state needed while awaiting.
Re:Tokio 1.0 – async runtime for Rust by gpderetta on Thursday December 24, 2020 @07:28AM (#25526939)
In theory a smart enough OS (or runtime) should be able to reclaim any memory beyond the stack pointer (plus redzone) at any time without preserving its content and shrink back the stack. Because of signal handlers that memory is to be considered volatile anyway.

It might not be worth doing it in practice, but it is something to keep on mind.

Re:Tokio 1.0 – async runtime for Rust by ibraheemdev on Wednesday December 23, 2020 @05:21PM (#25522948)
What "normal-sized Linux server" has 70GB of RAM?
Re:Tokio 1.0 – async runtime for Rust by oblio on Wednesday December 23, 2020 @05:31PM (#25523036)
One that wants to handle a million requests per second?

Or would you want to do that with a Raspberry Pi? :-)

> What "normal-sized Linux server" has 70GB of RAM?

Also, why are you "quoting" what I did not say?

Re:Tokio 1.0 – async runtime for Rust by ibraheemdev on Wednesday December 23, 2020 @06:09PM (#25523348)
I was quoting the parent comment by @akvadrako :)
Re:Tokio 1.0 – async runtime for Rust by ComputerGuru on Wednesday December 23, 2020 @05:48PM (#25523188)
Air quotes.
Re:Tokio 1.0 – async runtime for Rust by akvadrako on Wednesday December 23, 2020 @05:36PM (#25523084)
Most servers support at least 128GB; it isn't even very expensive. And if you want to handle a million concurrent users you also need to consider CPU and latency, so for most real-world workloads the memory probably won't even be your bottleneck.
Re:Tokio 1.0 – async runtime for Rust by secondcoming on Wednesday December 23, 2020 @06:51PM (#25523666)
How much does a 68GB cost on the cloud per day? Also, you don't have 1 million cores so quite a bit of your daily server costs will be eaten up by the OS running context switching code.
Re:Tokio 1.0 – async runtime for Rust by novocaine on Wednesday December 23, 2020 @05:49PM (#25523195)
Pending async waits have stacks to preserve too
Re:Tokio 1.0 – async runtime for Rust by steveklabnik on Wednesday December 23, 2020 @05:54PM (#25523245)
The difference, at least in the way this is built in Rust, is that when you create a task, you get a single allocation that's exactly sized. There's no resizing, which means that you aren't getting stacks that are too big or too small, with all of the other runtime shenanigans that that entails.
Re:Tokio 1.0 – async runtime for Rust by varajelle on Thursday December 24, 2020 @02:56AM (#25525807)
That said, the future has the size of the biggest state that need to be kept across await. The future might be slightly oversized, but still order of magnitude smaller than a perfectly sized stack.
Re:Tokio 1.0 – async runtime for Rust by Yoric on Wednesday December 23, 2020 @05:54PM (#25523239)
In some languges, that's true. In Rust, however, that pseudo-stack is typically tiny.