I've got a fairly standard setup in which a front-finish Apache server forwards demands to Tomcat through mod_proxy/AJP. How do i setup Apache/mod_proxy therefore it only forwards for the most part N (say, N=4) concurrent demands to Tomcat? Other concurrent demands entering Apache shouldn't be declined, and really should rather be queued to later be delivered to Tomcat.

PS 1: Observe that this really is something this can be done at Tomcat level using the maxThreads attribute, however i prefer additional in the Apache level.

PS 2: I observe that Apache includes a MaxClients configuration, which appears to do things i am searching for. But it's not obvious in my experience how to possess a MaxClient per server mod_proxy forwards to, instead of MaxClient per Apache. I.e. if Apache forward demands to some cluster of four Tomcat machine, I would like Apache to limit the amount of concurrent demands submitted to the given Tomcat to N (say, N=4).

The solutions is mod_proxy with the addition of parameters to ProxyPass directives. What you would like to create is most likely the max. Nevertheless this will throw a mistake instantly and never queue your demands whenever you hit the max.

If you want to queue make use of also mod_proxy_balancer. For instance allow maximum 4 connections:

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> 

Regrettably, within Apache, the need for max is per process. So, you are able to only effectively limit the amount of connections for your back-finish servers if Apache has one process and uses threads rather than ways to handle multiple connections, which is dependent on which MPM has been utilized by Apache:

  • On Home windows, you ought to be great and many likely don't need to bother about this, because the winnt MPM uses one process which produces threads to deal with demands.
  • On UNIX, if you are while using Apache that included your OS, regrettably there's a high probability you've prefork MPM Apache, which produces one process per request, with that the max parameter wouldn't work:

    1. To check on what MPM you've, run apachectl -l.
    2. Within the list, if you notice worker.c or event.c, then you're almost good: at this point you simply need to make certain that Apache produces just one process. With this, set ThreadsPerChild and MaxClients towards the same return, which is the entire quantity of concurrent connections your Apache will have the ability to process. Also set ServerLimit to at least one.
    3. Within the list, if you notice prefork.c, then you need to exchange your Apache using the worker or event MPM Apache. That can be done by either recompiling Apache yourself (the MPM isn't a run-time configuration parameter), or obtaining a existing package for the platform. Then, visit second step.