4 ms·
I thought forking webservers was too slow?
by iveqy 5y ago
I thought forking webservers was too slow?
- layoutIfNeeded 5y agoToo slow for what?
- dspillett 5y agoIt depends how complex a process you are forking and what OS you are running on. It has been some time since I wrote any real code for Linux or Windows that would be significantly affected by such things, but it used to be that forking could be almost as efficient under Linux as starting a new thread in an existing process. Under Windows this was very much not the case. Threads make communication between parts easier (no IPC needed) but that isn't usually an issue for the work a web server does. Comparing to purely event based web servers forking can still be better as no request should fully block another, or usually crash another (which is more likely with threads), and thread or fork based servers can make better use of concurrency which is significant for CPU heavy jobs. So swings & roundabouts. Each type (event, thread, process, some hybrid of the above) has strengths, and of course weaknesses.
- cesarb 5y ago> but it used to be that forking could be almost as efficient under Linux as starting a new thread in an existing process. That's because internally it's nearly the same thing. Both forking and starting a new thread on Linux is a variant of the clone() system call, the only difference being which things are shared between parent and child.