[英]Too many '/usr/sbin/apache2 -k start' processes
I'm facing a problem with apache processes (/usr/sbin/apache2 -k start) visible in HTOP.我遇到了在 HTOP 中可见的 apache 进程(/usr/sbin/apache2 -k start)的问题。 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:
在每个与数据库连接的 php 页面中,我以:
$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.过了一会儿,我的树莓派 3 运行非常缓慢,实际上太热了。 I have a default installation of apache with the default settings.
我使用默认设置默认安装了 apache。
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:在 mpm_prefork.conf 文件中,我有:
<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?
或者 apache 中是否有任何设置可以防止这种行为?
Thanks in advance!提前致谢!
The default Apache multi-process mode is a cpu-intensive Fork-based model.默认的 Apache 多进程模式是 CPU 密集型基于 Fork 的 model。 That means as the number of requests grows, so will the number of processes Apache starts (
http2
).这意味着随着请求数量的增加,Apache 启动的进程数量(
http2
)也会增加。 Forking is CPU-intensive and can easily overwhelm the Pi.分叉是 CPU 密集型的,很容易压倒 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.要使用更高效的多进程 model,请尝试
mpm_worker_module
,因为它使用线程来处理增加的吞吐量,并且可以通过配置限制父进程的数量。
For more information on the MPM options for Apache2, see the "Choosing an MPM" section of this document .有关 Apache2 的 MPM 选项的更多信息, 请参阅本文档的“选择 MPM”部分。
The default, prefork
module:默认的
prefork
模块:
The prefork MPM uses multiple child processes with one thread each.
prefork MPM 使用多个子进程,每个子进程都有一个线程。 Each process handles one connection at a time.
每个进程一次处理一个连接。 On many systems, prefork is comparable in speed to worker, but it uses more memory.
在许多系统上,prefork 的速度与 worker 相当,但它使用更多的 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.
Prefork 的无线程设计在某些情况下比 worker 有优势:它可以与非线程安全的第三方模块一起使用,并且在线程调试支持较差的平台上更容易调试。
Proposed worker
module:建议的
worker
模块:
The worker MPM uses multiple child processes with many threads each.
worker MPM 使用多个子进程,每个子进程有很多线程。 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.
Worker 通常是高流量服务器的不错选择,因为它的 memory 占用空间比 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.请注意,您的 Apache2 安装必须使用您打算使用的 MPM 进行编译。 The docs have more information on this.
文档对此有更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.