4 ms·
OS virtual memory ensures that overhead will not be that big. OS will allocate memory page by page as software touches corresponding virtual addresses. So threa
by vbezhenar 5y ago
OS virtual memory ensures that overhead will not be that big. OS will allocate memory page by page as software touches corresponding virtual addresses. So thread stack will use only as much memory as its maximum stack usage requires (rounded by page size). Async/await of course is more efficient, but in real world native stacks might be good enough, especially when RAM is not very expensive.
- addaon 5y ago"Rounded by page size" is a pretty huge caveat here, though, no? With a 4 kB minimum page size on most platforms, 5M threads is 20 GB of stack virtual mappings, minimum. And cycling through those threads even once will make every page of that 20 GB resident.
- astrange 5y agomacOS/iOS is a popular platform where the page size is 16KB and RAM is moderately-to-very expensive. It might be interesting to try something like Mesh (https://github.com/plasma-umass/Mesh https://github.com/plasma-umass/Mesh) to share pages.
- toast0 5y agomacOS/iOS aren't a realistic server platform for high loads. They don't even have syncookies, so anything TCP is out.
- lumost 5y agoThat still means I can effectively use 5 million threads on a small server. Which is effectively 3 orders of magnitude more threads than I can currently run with Java.
- Matthias247 5y agoMaybe. Realistically it won't matter, because any real world server would either need a lot more memory anyway to actually handle application-specific concerns or support a much lower number of clients. Keep in mind that even with a tiny and receive buffer of 16kB plus maybe some TLS state of > 30kB per connection the baseline memory usage of doing anything useful is already much higher than 4kB - unless the only thing you want to do is building a large-scale TCP ping service.