适用于高页面查看、长时间会话用户的 Apache 配置 - KeepAlive 和 MaxRequest 变量

发布于 2024-09-13 02:20:45 字数 1637 浏览 6 评论 0原文

我目前正在运行一个 Web 应用程序,每天有几个(~15)个用户登录一次,然后让该 Web 应用程序保持打开状态,每 5 分钟自动刷新一次新内容。每个用户通常会打开它大约 15-18 小时。

然而,在达到临界质量(~30-40)用户时,一切都开始急剧减慢,并且 HTTPD 进程的内存使用量开始激增。我添加了一个 cron 作业,每小时重新启动 apache 一次,但这只是有一定帮助。所有内容都是动态生成的,并且有新的监视时间,因此缓存页面不是一个选项。

我已经开始尝试使用 Timeout、MaxRequest 和 KeepAlive 选项,但是任何指导都将不胜感激,因为我过去总是将这些选项保留为默认值。

这就是我所拥有的。任何 apache 天才有关于如何针对上述场景优化此配置的想法吗?我认为较长的超时是好的,因为加载时间有时会变得非常长。

# Timeout: The number of seconds before receives and sends time out.

Timeout 200

# KeepAlive: Whether or not to allow persistent connections (more than
# one request per connection). Set to "Off" to deactivate.

KeepAlive On

# MaxKeepAliveRequests: The maximum number of requests to allow
# during a persistent connection. Set to 0 to allow an unlimited amount.
# We recommend you leave this number high, for maximum performance.

MaxKeepAliveRequests 100

# KeepAliveTimeout: Number of seconds to wait for the next request from the
# same client on the same connection.

KeepAliveTimeout 60

# prefork MPM
# 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
# ServerLimit: maximum value for MaxClients for the lifetime of the server
# MaxClients: maximum number of server processes allowed to start
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule prefork.c>
StartServers       16
MinSpareServers    10
MaxSpareServers   20
ServerLimit      256
MaxClients       256
MaxRequestsPerChild  4000
</IfModule>

I am currently running a web app that sees several (~15) users logging in once each day, and then leaving the web app open where it automatically refreshes with new content every 5 minutes. Each user tends to have it open for about 15-18 hours.

However at critical mass (~30-40) users everything starts to slow down dramatically and the HTTPD process start to balloon in memory usage. I have added a cron job that restarts apache once an hour, but that only helps somewhat. All the content is dynamically generated and new wach time, so caching pages isn't an option.

I have started to play around with the Timeout,MaxRequest and KeepAlive options, but any guidance would be greatly appreciated, as I have always left these on defaults in the past.

Here's what i have. Any apache geniuses have ideas on how to optimize this config for above scenario? I figured a long timeout is good because the load times can sometimes get VERY high.

# Timeout: The number of seconds before receives and sends time out.

Timeout 200

# KeepAlive: Whether or not to allow persistent connections (more than
# one request per connection). Set to "Off" to deactivate.

KeepAlive On

# MaxKeepAliveRequests: The maximum number of requests to allow
# during a persistent connection. Set to 0 to allow an unlimited amount.
# We recommend you leave this number high, for maximum performance.

MaxKeepAliveRequests 100

# KeepAliveTimeout: Number of seconds to wait for the next request from the
# same client on the same connection.

KeepAliveTimeout 60

# prefork MPM
# 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
# ServerLimit: maximum value for MaxClients for the lifetime of the server
# MaxClients: maximum number of server processes allowed to start
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule prefork.c>
StartServers       16
MinSpareServers    10
MaxSpareServers   20
ServerLimit      256
MaxClients       256
MaxRequestsPerChild  4000
</IfModule>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

假情假意假温柔 2024-09-20 02:20:45

这可能是一个值得深入研究 ServerFault 的好问题。

您的服务器可能正在交换(缺少 RAM)。

您的 MaxClients 指令应该类似于:

MaxClients ≈ (RAM - size_all_other_processes)/(size_apache_process)

您可以查看几个解释如何微调 apache 的文章

cron 重启不是!一个好主意。也许每天一次。但不要试图以这种方式解决这个问题。

希望有帮助!

This is probably a good question to go into ServerFault.

Your server is probably swapping (lack of RAM).

Your MaxClients directive should be something like:

MaxClients ≈ (RAM - size_all_other_processes)/(size_apache_process)

You can look into several articles that explain how to fine-tune apache.

Cron-restarting is not! a good ideia. Maybe once a day. But don't try to solve this problem that way.

Hope it helps!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文