Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I would like to know what a threaded web server is?

I have performed many searches but am unable to find anything that gives a clear explanation or definition; perhaps somebody can enlighten me.

share|improve this question
add comment

migrated from stackoverflow.com Apr 29 '11 at 4:09

This question came from our site for professional and enthusiast programmers.

2 Answers

up vote 6 down vote accepted

A threaded web server is one that handles each request with a new thread, as opposed to handling each request with a new process.

Multi-threading is more complex than concurrency with processes, so there's an increased risk of the web server crashing if one of its modules isn't working correctly. Also, if it does crash, it's more likely to crash all of the threads (ie. all of the requests being handled at the time). However, multi-threaded servers consume less memory and are generally faster.

Here's a benchmark comparing the two (mutually exclusive) apache modules: prefork and worker.

http://www.camelrichard.org/apache-prefork-vs-worker

and their definitions...

http://httpd.apache.org/docs/2.0/mod/prefork.html

http://httpd.apache.org/docs/2.0/mod/worker.html

share|improve this answer
    
As a note: "as opposed to handling each request with individual processes" - there would be other options, too to implement a server. Like event-based where single thread in a single process uses event-based socket-operations –  johannes Apr 27 '11 at 10:22
    
Agreed... as in node.js ( stackoverflow.com/questions/5681853/… ) –  Homer6 Apr 27 '11 at 10:26
    
I don't think the definition of multithreaded server is necessarily 1 request 1 thread. I don't think that would scale real well. –  Justin Meiners Jul 16 '13 at 22:23
    
You're right. It doesn't. However, that model has been present for some time. I'm not sure that the definition is necessarily one thread per request either. Having a finite thread pool would also be considered a threaded web server. I believe the one thread per connection is more of a pedagogical model, as it's easier to build than a server that uses a thread pool instead. –  Homer6 Jul 17 '13 at 4:58
add comment

It's a web server that has a queue for incoming HTTP requests and a pool of threads for satisfying them. The server takes the first request off the queue and assigns a thread from the pool to do the work. Requests line up in the queue when they come in faster than the threads can process them or if the pool runs out of threads.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.