User Tools

Site Tools


apache:architecture

This is an old revision of the document!


Apache Architecture

MPM Prefork Architecture

  • StartServers: number of server processes to start
  • MinSpareServers: minimum number of server processes which are kept spare
  • MaxSpareServers: maximum number of server processes which are kept spare
  • MaxClients: maximum number of server processes allowed to start ⇒ Limist number of httpd created and processing the request

MPM worker Architecture

  • StartServers: initial number of server processes to start
  • MinSpareThreads: minimum number of worker threads which are kept spare
  • MaxSpareThreads: maximum number of worker threads which are kept spare
  • ThreadsPerChild: constant number of worker threads in each server process

Debug architecture of apache

Get current MPM is running: MPM Prefork or MPM worker

apachectl -V
Server version: Apache/2.2.15 (Unix)
Server built:   Apr  3 2014 23:56:16
Server's Module Magic Number: 20051115:25
Server loaded:  APR 1.3.9, APR-Util 1.3.9
Compiled using: APR 1.3.9, APR-Util 1.3.9
Architecture:   64-bit
Server MPM:     Prefork
  threaded:     no
    forked:     yes (variable process count)
Server compiled with....
 -D APACHE_MPM_DIR="server/mpm/prefork"
...........................

compiled modules in MPM Prefork(httpd) and MPM worker(httpd.worker)

  • httpd -V
    Server version: Apache/2.2.15 (Unix)
    Server built:   Apr  3 2014 23:56:16
    Server's Module Magic Number: 20051115:25
    Server loaded:  APR 1.3.9, APR-Util 1.3.9
    Compiled using: APR 1.3.9, APR-Util 1.3.9
    Architecture:   64-bit
    Server MPM:     Prefork
      threaded:     no
        forked:     yes (variable process count)
    Server compiled with....
     -D APACHE_MPM_DIR="server/mpm/prefork"
     -D APR_HAS_SENDFILE
     -D APR_HAS_MMAP
     -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
     -D APR_USE_SYSVSEM_SERIALIZE
     -D APR_USE_PTHREAD_SERIALIZE
     -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
     -D APR_HAS_OTHER_CHILD
     -D AP_HAVE_RELIABLE_PIPED_LOGS
     -D DYNAMIC_MODULE_LIMIT=128
     -D HTTPD_ROOT="/etc/httpd"
     -D SUEXEC_BIN="/usr/sbin/suexec"
     -D DEFAULT_PIDLOG="run/httpd.pid"
     -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
     -D DEFAULT_LOCKFILE="logs/accept.lock"
     -D DEFAULT_ERRORLOG="logs/error_log"
     -D AP_TYPES_CONFIG_FILE="conf/mime.types"
     -D SERVER_CONFIG_FILE="conf/httpd.conf"
  • httpd.worker -V
    Server version: Apache/2.2.15 (Unix)
    Server built:   Apr  3 2014 23:56:59
    Server's Module Magic Number: 20051115:25
    Server loaded:  APR 1.3.9, APR-Util 1.3.9
    Compiled using: APR 1.3.9, APR-Util 1.3.9
    Architecture:   64-bit
    Server MPM:     Worker
      threaded:     yes (fixed thread count)
        forked:     yes (variable process count)
    Server compiled with....
     -D APACHE_MPM_DIR="server/mpm/worker"
     -D APR_HAS_SENDFILE
     -D APR_HAS_MMAP
     -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
     -D APR_USE_SYSVSEM_SERIALIZE
     -D APR_USE_PTHREAD_SERIALIZE
     -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
     -D APR_HAS_OTHER_CHILD
     -D AP_HAVE_RELIABLE_PIPED_LOGS
     -D DYNAMIC_MODULE_LIMIT=128
     -D HTTPD_ROOT="/etc/httpd"
     -D SUEXEC_BIN="/usr/sbin/suexec"
     -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
     -D DEFAULT_ERRORLOG="logs/error_log"
     -D AP_TYPES_CONFIG_FILE="conf/mime.types"
     -D SERVER_CONFIG_FILE="conf/httpd.conf"
  • Difference between “httpd -V” and “httpd.worker -V”
    • httpd -V
      Server MPM:     Prefork
        threaded:     no
          forked:     yes (variable process count)
      Server compiled with....
       -D APACHE_MPM_DIR="server/mpm/prefork"
          
    • httpd.worker -V
      Server MPM:     Worker
        threaded:     yes (fixed thread count)
          forked:     yes (variable process count)
      Server compiled with....
       -D APACHE_MPM_DIR="server/mpm/worker"
          
  • httpd -l
    Compiled in modules:
      core.c
      prefork.c
      http_core.c
      mod_so.c
  • httpd.worker -l
    Compiled in modules:
      core.c
      worker.c
      http_core.c
      mod_so.c

Debug processes and used memory, cpu

  • netstat -anp | grep 80 | grep LISTEN
    tcp        0      0 :::80                       :::*                        LISTEN      5141/httpd
    => http listen on port 80 with PID(ProcessID) 5141
  • ps -eaf | grep 5141
    ps -eaf | grep 5141
    UID        PID  PPID  C STIME TTY      TIME      CMD
    root      5141     1  0 15:38 ?        00:00:00 /usr/sbin/httpd
    apache    5176  5141  0 15:40 ?        00:00:01 /usr/sbin/httpd
    apache    5196  5141  0 15:42 ?        00:00:02 /usr/sbin/httpd
    apache    5353  5141  0 15:58 ?        00:00:00 /usr/sbin/httpd
    apache    5358  5141  0 15:58 ?        00:00:00 /usr/sbin/httpd
    apache    5360  5141  0 15:59 ?        00:00:00 /usr/sbin/httpd

    ⇒ PPID(Parent PID). the master process is 5141, and sub processes are 5176, 5196, 5353, 5358, 5360 with CMD is /usr/sbin/httpd

  • ps -aux | grep /usr/sbin/httpd
    ps -aux | grep /usr/sbin/httpd
    USER      PID  %CPU  %MEM  VSZ   RSS TTY  STAT START   TIME COMMAND
    root      5141  0.0  1.9 254904  9920 ?   Ss   15:38   0:00 /usr/sbin/httpd
    apache    5176  0.1  9.0 290320 45340 ?   S    15:40   0:01 /usr/sbin/httpd
    apache    5196  0.1  9.3 291896 46956 ?   S    15:42   0:02 /usr/sbin/httpd
    apache    5353  0.1  6.8 279708 34160 ?   S    15:58   0:00 /usr/sbin/httpd
    apache    5358  0.0  3.3 263124 16592 ?   S    15:58   0:00 /usr/sbin/httpd
    apache    5360  0.1  7.6 283964 38312 ?   S    15:59   0:00 /usr/sbin/httpd

    With VSZ is Virtual Memory Size(address space allocated) , and RSS is Resident Set Size (physically resident memory)

  • pmap -x 6726 | sort -ak +2
    pmap -x 6812 | sort -nk +2
    00007fcacac95000    2048       0       0 -----  mod_mime_magic.so
    00007fcacb4a8000    2048       0       0 -----  mod_log_config.so
    00007fcacc0c1000    2048       0       0 -----  mod_authz_user.so
    00007fcacccd7000    2048       0       0 -----  mod_auth_digest.so
    00007fcacd559000    2048       0       0 -----  libdl-2.12.so
    00007fcacdb06000    2048       0       0 -----  libpthread-2.12.so
    00007fcace4db000    2048       0       0 -----  libcrypt-2.12.so
    00007fcad1562000    2384    2356    2356 rw---    [ anon ]
    00007fcac723b000    3268    1672       0 r-x--  libphp5.so
    00007fcad17b6000   47848   47488   47488 rw---    [ anon ]

Optimize apache and PHP config

optimize load module apache

Config load modules below:

LoadModule authz_host_module modules/mod_authz_host.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule expires_module modules/mod_expires.so
LoadModule deflate_module modules/mod_deflate.so
LoadModule headers_module modules/mod_headers.so
LoadModule env_module modules/mod_env.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule mime_module modules/mod_mime.so
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule negotiation_module modules/mod_negotiation.so
LoadModule dir_module modules/mod_dir.so
LoadModule alias_module modules/mod_alias.so
LoadModule rewrite_module modules/mod_rewrite.so

Explain directives with these modules:

LoadModule authz_host_module modules/mod_authz_host.so#Order
LoadModule log_config_module modules/mod_log_config.so#LogFormat,TransferLog
LoadModule expires_module modules/mod_expires.so
LoadModule deflate_module modules/mod_deflate.so
LoadModule headers_module modules/mod_headers.so
LoadModule env_module modules/mod_env.so
LoadModule setenvif_module modules/mod_setenvif.so#BrowserMatch
LoadModule mime_module modules/mod_mime.so#AddHandler
LoadModule autoindex_module modules/mod_autoindex.so#IndexOptions
LoadModule negotiation_module modules/mod_negotiation.so#LanguagePriority
LoadModule dir_module modules/mod_dir.so#DirectoryIndex
LoadModule alias_module modules/mod_alias.so#Alias
LoadModule rewrite_module modules/mod_rewrite.so

optimize load module php

apache/architecture.1411223207.txt.gz · Last modified: 2022/10/29 16:15 (external edit)