简体   繁体   中英

Too many '/usr/sbin/apache2 -k start' processes

I'm facing a problem with apache processes (/usr/sbin/apache2 -k start) visible in HTOP. enter image description here After every refresh or connection from a client the number of processes increase without stopping to run. Even if the browser is closed, the proces continues. In every php page with a connection to the database I end with:

    $thread_id = $mysqli->thread_id;
    $mysqli->kill($thread_id);
    $mysqli->close(); 

After a while my raspberry PI 3 is running very slow and actually too hot. I have a default installation of apache with the default settings.

Server version: Apache/2.4.38 (Raspbian)
Server built:   2019-10-15T19:53:42
Server's Module Magic Number: 20120211:84
Server loaded:  APR 1.6.5, APR-UTIL 1.6.1
Compiled using: APR 1.6.5, APR-UTIL 1.6.1
Architecture:   32-bit
Server MPM:     prefork
  threaded:     no
    forked:     yes (variable process count)
Server compiled with....
 -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=256
 -D HTTPD_ROOT="/etc/apache2"
 -D SUEXEC_BIN="/usr/lib/apache2/suexec"
 -D DEFAULT_PIDLOG="/var/run/apache2.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="mime.types"
 -D SERVER_CONFIG_FILE="apache2.conf"

In the mpm_prefork.conf file I have:

<IfModule mpm_prefork_module>
    StartServers        4
    MinSpareServers     1
    MaxSpareServers     4
    MaxRequestWorkers   50
    MaxConnectionsPerChild  0
</IfModule>

What can I do or set to automatically kill these processes after a client leaves the pages or closes the browser? Or are there any settings in apache to prevent this behaviour?

Thanks in advance!

The default Apache multi-process mode is a cpu-intensive Fork-based model. That means as the number of requests grows, so will the number of processes Apache starts ( http2 ). Forking is CPU-intensive and can easily overwhelm the Pi. To use a more efficient multi-process model, try mpm_worker_module , as it uses threading to handle increased throughput and the number of parent processes can be limited via configuration.

For more information on the MPM options for Apache2, see the "Choosing an MPM" section of this document .

The default, prefork module:

The prefork MPM uses multiple child processes with one thread each. Each process handles one connection at a time. On many systems, prefork is comparable in speed to worker, but it uses more memory. Prefork's threadless design has advantages over worker in some situations: it can be used with non-thread-safe third-party modules, and it is easier to debug on platforms with poor thread debugging support.

Proposed worker module:

The worker MPM uses multiple child processes with many threads each. Each thread handles one connection at a time. Worker generally is a good choice for high-traffic servers because it has a smaller memory footprint than the prefork MPM.

Here is an example configuration that may work:

<IfModule mpm_worker_module>
    ServerLimit          2 # how many processes max?
    StartServers         1 # how many processes start initially?
    MaxRequestWorkers   40 # maximum total number of threads that may be launched
    MinSpareThreads     25
    MaxSpareThreads     75
    ThreadsPerChild     20 # number of threads deployed by each child process
</IfModule>

Note that your Apache2 installation must be compiled with the MPM you intend to use. The docs have more information on this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM