[ale] threads and apache

Michael D. Hirsch mhirsch at nubridges.com
Fri Oct 11 10:52:42 EDT 2002


On Friday 11 October 2002 10:01 am, stephen wrote:
> On Fri, Oct 11, 2002 at 04:13:28AM -0700, Stephen Turner wrote:
> > hey, i was reading about how threads use less resources than actual
> > applications, well that makes sense and all but why hasnt apache
> > adopted this before? and how much resources do you think it saves?
>
> This depends on the OS, but linuxthreads in glibc is implemented
> in userspace so threads in linux are not lightweight processes
> scheduled by the kernel.

Huh?  The linux pthreads implementation for the last 4-5 years has been 
exactly the opposite.  It is all done in the kernel via a very clever 
hack so that the kernel cannot tell the difference between a thread and 
a process.  Threads are scheduled in the kernel exactly like processes.  
Thread creation takes about the same amount of time as process 
creation, too.  It is only a little faster.

> However, I believe the forking API
> in linux was designed to be as lightweight as possible so
> the time for process creation is minimal. 

That is correct--linux process creation is quite efficient.  On other 
OSes they need efficient thread creation because porcess creation is 
slow.  On Linux they are about the same, so relatively speaking the 
processes are quick to create and the threads a little slow.

> Also, there are some patches going into 2.5 wrt scaling for
> kernelspace threads along with the Native Posix Threads
> Library (nptl) which will eventually be integrated into glibc.
> This should give linux the ablility to schedule threads in
> kernelspace and will most certainly be cheaper than process
> creation with forking.  You may have heard already about
> some of the initial benchmarks of starting and stopping
> 100,000 threads in under 2 seconds.

Also true.  In the 2.6 (or 3.0) threading should be lightening fast.

My understanding (and I am not an apache developer, or even much of a 
user) is that apache is designed to work extremely well and reliably, 
but not designed to be extremely efficient or fast.  Threading can be 
very tricky and hard to debug.  If a thread crashes it tends to bring 
down the whole process.  By using a forking model apache was able to 
develop rapidly to the point that it dominates the market.

That said, there are some advantages to threading.  Now that apache has 
proven itself to be very stable and reliable, the developers have 
started to move on to the second level of features.  So now, with 
apache 2.0 you get to pick the extent of threading.  I believe that you 
get to say how many thread should run in each process, so depending on 
your settings you can have one process with multiple threads, or 
multiple processes each with one thread.

--Michael

---
This message has been sent through the ALE general discussion list.
See http://www.ale.org/mailing-lists.shtml for more info. Problems should be
sent to listmaster at ale dot org.






More information about the Ale mailing list