我目前正在运行一个networking应用程序,可以看到几个(〜15)用户每天login一次,然后让Web应用程序打开,每5分钟自动刷新一次新内容。 每个用户往往会打开约15-18个小时。
然而,在临界质量(〜30-40)的用户,一切都开始大幅放缓,HTTPD进程开始膨胀在内存使用。 我已经添加了一个cron作业,每小时重新启动apache一次,但这只会有所帮助。 所有的内容都是dynamic生成的,新的时间,所以caching页面不是一个选项。
我已经开始使用Timeout,MaxRequest和KeepAlive选项,但任何指导都将不胜感激,因为过去我一直将这些选项留在默认值上。
这是我的。 任何Apache天才有如何优化这个configuration上述情况的想法? 我认为很长的超时是很好的,因为加载时间有时会变得非常高。
# 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>
(为了澄清,我简化了数字,特别是内存部分太高了)
你的MaxRequestsPerChild目前是4000,因为你每天得到50个用户,每个人每5分钟刷新18小时,每小时600个请求,每天10800个请求。 作为参考,一个用户每天使用218个连接。
这意味着subprocess在一天内重新启动2.7次。 如果您的应用程序每次刷新使用50M的内存,并设法释放每次刷新1M的49M,50个用户的50M,以及4000次重新加载的4G。 这个孩子会被杀死
您应该检查您的应用程序使用了多less内存,并根据这些值设置这些值。
如果你的服务器有20G的内存,那么1M的泄漏会有效,但是如果将MaxRequestsPerChild改为1000,那么在重新启动subprocess之前,会使内存消耗减less四倍。
请注意,您可能希望将MaxClients减less到100,并确保实际上没有更多的用户在使用您的想法。 这种方式意外的问题不会由于太多的请求而导致服务器失败。 KeepAliveTimeout可能是15秒,因为用户每5分钟刷新一次。
我想你需要玩MaxRequestsPerChild指令。 每小时重新启动apache听起来不像是一个优雅的解决scheme。 MaxRequestsPerChild每个进程将自动重新启动,一旦它服务于设定数量的请求。 尝试将其设置为100?
另外使用更轻的networking服务器(例如nginx )来慢吞吞慢速客户端并服务静态媒体将会从Apache中带走大量的负载。