如何计算 apache 中的 MaxClient 值?

Sup*_*tik 5 apache-2.2

我想为我的生产服务器在 apache 中为 MaxClient 设置一个最佳值。计算此值时应考虑哪些参数?

小智 11

补充@Sameer 的回答,我阅读了很多这个主题,我所做的是:

  1. 获取Apache进程平均大小:

    server# ps -ylC apache2 --sort:rss
    
    S   UID   PID  PPID  C PRI  NI   RSS    SZ WCHAN  TTY          TIME CMD
    S    33  6233 25895  0  80   0  7432 72802 poll_s ?        00:00:00 apache2
    S    33  6250 25895  0  80   0  7432 72802 poll_s ?        00:00:00 apache2
    S    33  6278 25895  0  80   0  7432 72802 poll_s ?        00:00:00 apache2  
    S    33  6280 25895  0  80   0  7432 72802 poll_s ?        00:00:00 apache2 
    S    33  6577 25895  0  80   0  7432 72802 poll_s ?        00:00:00 apache2
    S    33  6299 25895  0  80   0  7772 72891 poll_s ?        00:00:00 apache2
    S    33  6295 25895  0  80   0  7776 72891 poll_s ?        00:00:00 apache2
    
    Run Code Online (Sandbox Code Playgroud)

    正如您在 SZ 列中看到的,我的 Apache 进程大小约为 73 MB

  2. 制作以下公式

    MaxClients: ((Total_Memory)(1024)(MB) - Other_processes_memory) / 73
    
    Run Code Online (Sandbox Code Playgroud)

    例如:我有 16 GB RAM,我可能会为任何其他进程留出 2 GB 可用空间

    MaxClients: ((16*1024) - 2048) / 73
    MaxClient: 196 
    
    Run Code Online (Sandbox Code Playgroud)

这就是我使用的,我的服务器运行良好。

您必须考虑到我的 Apache 进程有点繁重,因此您可以拥有大约 50 MB 或更少的进程。

问候,

对于所有 Apache 进程,您的 SZ 略有相同。就我而言,我的值在 23 到 212 Mb 之间

在此处输入图片说明

我应该在你的公式中使用什么值?

顺便说一下,在 Apache 2.4 中 MaxClients 已重命名为 MaxRequestWorkers。您的公式对这个新参数仍然有效吗?

问候


Buv*_*inJ 8

tachomi 的答案并不过分全面,但似乎是开始估算的合理方法。

除此之外,这将帮助您找出 Apache 当前消耗的一些资源:

ps aux | grep 'httpd' | awk '{count = NR;} END {print count " Apache processes";}'
ps aux | grep 'httpd' | awk '{print $6/1024;}' | awk '{sum += $1;} END {print sum " MB total mem usage";}'
ps aux | grep 'httpd' | awk '{print $6/1024;}' | awk '{avg += ($1 - avg) / NR;} END {print avg " MB avg mem usage";}'
Run Code Online (Sandbox Code Playgroud)


Sam*_*eer 3

请参阅Apache 性能调优指南。

引用

"You can, and should, control the MaxClients setting so that your server does not spawn   
so many children it starts swapping. This procedure for doing this is simple: determine 
the size of your average Apache process, by looking at your process list via a tool such 
as top, and divide this into your total available memory, leaving some room for other 
processes."
Run Code Online (Sandbox Code Playgroud)