From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1QPEiy-0000Oq-5z for garchives@archives.gentoo.org; Wed, 25 May 2011 14:06:12 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id B0F2A1C1D6 for ; Wed, 25 May 2011 14:06:11 +0000 (UTC) Received: from mail-pv0-f181.google.com (mail-pv0-f181.google.com [74.125.83.181]) by pigeon.gentoo.org (Postfix) with ESMTP id 526A21C1CA for ; Wed, 25 May 2011 14:04:05 +0000 (UTC) Received: by pvg13 with SMTP id 13so4967289pvg.40 for ; Wed, 25 May 2011 07:04:04 -0700 (PDT) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-server@lists.gentoo.org Reply-to: gentoo-server@lists.gentoo.org MIME-Version: 1.0 Received: by 10.68.60.9 with SMTP id d9mr3601607pbr.488.1306332243763; Wed, 25 May 2011 07:04:03 -0700 (PDT) Sender: vladimir@greenmice.info Received: by 10.68.55.105 with HTTP; Wed, 25 May 2011 07:04:03 -0700 (PDT) In-Reply-To: <201105251418.59200.stephane@22decembre.eu> References: <201105251038.56032.stephane@22decembre.eu> <201105251334.22655.stephane@22decembre.eu> <201105251418.59200.stephane@22decembre.eu> Date: Wed, 25 May 2011 18:04:03 +0400 X-Google-Sender-Auth: MHXNrS_p3SRUEVsLdgYn5qNeQxg Message-ID: Subject: Re: [gentoo-server] apache2 threads From: Vladimir Rusinov To: gentoo-server@lists.gentoo.org Content-Type: multipart/alternative; boundary=bcaec52e57c759217f04a41a2d37 X-Archives-Salt: X-Archives-Hash: 3f62421472ec81fea29f581b32d8b696 --bcaec52e57c759217f04a41a2d37 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Wed, May 25, 2011 at 4:18 PM, St=C3=A9phane Guedon wrote: > On Wednesday 25 May 2011 14:04:17 Vladimir Rusinov wrote: > > On Wed, May 25, 2011 at 3:34 PM, St=C3=A9phane Guedon > wrote: > > > I read the apache2 doc, and I don't really know the principes of mpm. > > > Worker, > > > prefork... Don't understand really ! :( > > > > Ok, than in order to explain (or suggest books/articles) we need to kno= w: > > Do you understand basic architecture concepts of multi-process network > > server? > > Do you understand what fork() is? > > The only thing in this subject I have understood (I think, not sure... :)= ) > is > that apache start few child processes and it's this processes that respon= d > to > requests. > Yep, this is correct. Classic architecture of network server is a follows: main process listens on network address, and when there is new client connection, it creates new child process (using fork() system call, which just duplicates process) or thread. Child process works with this new connection, while main continues to wait for next connection. So it is possible to process number of requests at the same time. Apache (and many other web server) behaves and the same way, but it somewha= t smarter: it maintains pool of processes, so there is no need to do fork() for each connection - fork might be quite expensive. This behavior called prefork, and it is being implemeted by prefork mpm, where mpm stands for 'multiprocessing module'. There are other mpms exists as well: 'worker', which is basically the same as perfork, but it operates with threads, not with processes. Thread is lighter (it is 'lightweight process'), it shares memory with othe= r threads, it's faster to create and it have less overhead. But since all threads of the process have access to whole process memory, error in one thread could break other threads and cause whole process to die. This is usually not happens in stable environments, but it could happen for example with apache+mod_php+some exotic untested extension. HTH Yes, I am not skilled, but said it earlier, and I think of myself quite > courageous to get into Linux and Apache adventure without this > knowledges... > :) Good luck! I could also suggest to read some articles/books about network programming. Good book is 'UNIX Network Programming' by Richard Stevens, but it could be overkill. --=20 Vladimir Rusinov http://greenmice.info/ --bcaec52e57c759217f04a41a2d37 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable

On Wed, May 25, 2011 at 4:18 PM, St=C3= =A9phane Guedon <stephane@22decembre.eu> wrote:
On Wednesday 25 May 2011 14:04:17 Vladimi= r Rusinov wrote:
> On Wed, May 25, 2011 at 3:34 PM, St=C3=A9phane Guedon
<stephane@22dec= embre.eu>wrote:
> > I read the apache2 doc, and I don't really know the principes= of mpm.
> > Worker,
> > prefork... Don't understand really ! :(
>
> Ok, than in order to explain (or suggest books/articles) we need to kn= ow:
> Do you understand basic architecture concepts of multi-process network=
> server?
> Do you understand what fork() is?

The only thing in this subject I have understood (I think, not = sure... :) ) is
that apache start few child processes and it's this processes that resp= ond to
requests.
=C2=A0
Yep, this is correct.
=

Classic architecture of network server is a follows:
main process listens on network address, and when there is new clie= nt connection, it creates new child process (using fork() system call, whic= h just duplicates process) or thread. Child process works with this new con= nection, while main continues to wait for next connection. So it is possibl= e to process number of requests at the same time.
Apache (and many other web server) behaves and the same way, but it so= mewhat smarter: it maintains pool of processes, so there is no need to do f= ork() for each connection - fork might be quite expensive. This=C2=A0behavi= or=C2=A0called prefork, and it is being implemeted by prefork mpm, where mp= m stands for 'multiprocessing module'.

There are other mpms exists as well: 'worker', = which is basically the same as perfork, but it operates with threads, not w= ith processes.
Thread is lighter (it is 'lightweight process&= #39;), it shares memory with other threads, it's faster to create and i= t have less overhead. But since all threads of the process have access to w= hole process memory, error in one thread could break other threads and caus= e whole process to die. This is usually not happens in stable environments,= but it could happen for example with apache+mod_php+some exotic untested e= xtension.

HTH

Yes, I am not skilled, but said it earlier, and I think of myself quite courageous to get into Linux and Apache adventure without this knowledges..= .
:)

Good luck!
I could also suggest to = read some articles/books about network programming. Good book is 'UNIX = Network Programming' by Richard Stevens, but it could be overkill.

--
Vladimir Rusinov
http://gr= eenmice.info/
--bcaec52e57c759217f04a41a2d37--