0

I am aware that threading is the preferred way to go, but what are some benefits of using Forking or Threading in something like a Web server?

Update: My question is about either forking off a process or to start a separate thread to deal with each connections.

Is there any other (perhaps better) way to manage the connections?

John Saunders
  • 160,644
  • 26
  • 247
  • 397
  • 1
    Without some context, the question is meaningless. Besides, `fork()` was originally used with operating systems which had no concept of threading. – John Saunders Dec 13 '14 at 21:40
  • Who still does use fork() nowadays, I wonder... – kuroi neko Dec 13 '14 at 21:43
  • You don't even need a separate thread per connection. That's a very old idea. – John Saunders Dec 14 '14 at 05:03
  • Another way without forks and without threads is the asynchronous callback (nightmare?) used by [Node.js](http://stackoverflow.com/questions/2353818/how-do-i-get-started-with-node-js) – xmojmr Dec 14 '14 at 07:46

1 Answers1

2

In many modern web applications, you are often spending a lot of time on an external resource: a database, a cache server, a filesystem, etc. In this case, a threading model helps by not reserving memory resources for multiple processes that are going to spend most of the time idle.

The benefit of the forking model is primarily when you have existing frameworks that aren't aware of threads (most PHP, Ruby, Python, etc. applications). Making existing apps thread-aware can take a huge amount of time and effort. In some cases, such as where the app uses a lot of CPU, RAM bandwidth, or I/O with resource contention (i.e. a single-channel disk controller), processes aren't that much of a disadvantage.

Allen Luce
  • 7,859
  • 3
  • 40
  • 53