我有一个相当标准的设置,其中前端Apache服务器通过mod_proxy/AJP将请求转发到Tomcat。如何设置Apache/mod_proxy,使其只向Tomcat转发最多N个(比如N=4)并发请求?进入Apache的其他并发请求不应该被拒绝,而应该排队等待稍后发送到Tomcat。
PS 1:请注意,您可以在Tomcat级别使用maxThreads属性完成此操作,但我更喜欢在Apache级别处理此问题。
PS 2:我看到Apache有一个MaxClients配置,它似乎正在做我正在寻找的事情。但我不清楚如何让mod_proxy转发到每个服务器的MaxClient,而不是每个Apache的MaxClient。也就是说,如果Apache将请求转发到由4台Tomcat机器组成的集群,我希望Apache将转发到任何给定Tomcat的并发请求的数量限制为N(例如,N=4)。
发布于 2011-02-07 03:49:18
通过向ProxyPass指令添加参数,解决方案是mod_proxy。您想要设置的可能是最大值。然而,这将立即抛出一个错误,并且在您达到最大值时不会对您的请求进行排队。
如果你真的想排队,你还必须使用mod_proxy_balancer。例如,允许最多4个连接:
ProxyPass / balancer://appservers/ stickysession=JSESSIONID|jsessionid nofailover=On
<Proxy balancer://appservers>
BalancerMember ajp://192.168.0.100:8009 max=4
BalancerMember ajp://192.168.0.101:8009 max=4
BalancerMember ajp://192.168.0.102:8009 max=4
BalancerMember ajp://192.168.0.103:8009 max=4
</Proxy> 不幸的是,在Apache中,max的值是每个进程的。因此,如果Apache只有一个进程,并且使用线程而不是进程来处理多个连接,那么您只能有效地限制到后端服务器的连接数量,这取决于Apache使用的MPM:
Windows,您应该都很好,而且很可能不必担心这一点,因为
1. To check what MPM you have, run `apachectl -l`.
2. In the list, if you see `worker.c` or `event.c`, then you are almost good: you now just need to make sure that Apache creates only one process. For this, set `ThreadsPerChild` and `MaxClients` to the same value, which will be the total number of concurrent connections your Apache will be able to process. Also set `ServerLimit` to 1.
3. In the list, if you see `prefork.c`, then you first need to replace your Apache with the worker or event MPM Apache. You can do so by either recompiling Apache yourself (the MPM is not a run-time configuration parameter), or getting a existing package for your platform. Then, go to step two.
https://stackoverflow.com/questions/3167907
复制相似问题