4 ms·
I'm not talking about creating them, I'm talking about memory / context switch. There is a reason why none of the webservers on linux use one thread per connect
by Thaxll 8y ago
I'm not talking about creating them, I'm talking about memory / context switch. There is a reason why none of the webservers on linux use one thread per connection.
- Matthias247 8y agoI know what you mean (nginx & co), but I wouldn't bet whether the majority of websites and APIs use a thread per connection or event-driven IO. E.g. there is are a lot of PHP sites out there, which are thread-per-connection. Or which are powered by Java servlets, which had been synchronous until quite recently.
- paulddraper 8y agoThat was unclear. Yes, 1000 concurrent threads will take stack size * 1000.
- masklinn 8y agoThread stacks are reserved, but not allocated up-front (unless you're running on OSv apparently[0]). 1000 concurrent threads will not take stack size * 1000, they'll take used pages * 1000 (with used pages being at least 1) + the kernel overhead of the thread structures. That's trivial to check, even in a high-level language (with its own additional overhead) e.g. spawning 1000 threads in Python on OSX takes ~25MB. OSX uses 512k stacks for non-main threads. [0] https://github.com/cloudius-systems/osv/issues/143 https://github.com/cloudius-systems/osv/issues/143