I have two docker containers each with a running application on port 8080. This application has a REST endpoint "/status" that can signal if the application still has the resources to accept another request by a user. A user request will be forwarded and balanced to the two containers by an load balancing Apache proxy.
What I want to achieve:
- If the application in a container signals it doesn't want to receive more requests the balancer will not forward requests to this container
- If every running application server signals to not receive any requests one of those servers should receive the requests anyway.
What I've configured:
<VirtualHost *:80>
ProxyRequests off
ProxyPreserveHost On
ProxyHCExpr status_ok {hc('body') ~ /Status: ok/}
<Proxy balancer://application-cluster>
BalancerMember http://application1:8080 route=worker1 hcexpr=status_ok hcmethod=get hcuri=/status
BalancerMember http://application2:8080 route=worker2 hcexpr=status_ok hcmethod=get hcuri=/status
BalancerMember http://application1:8080 route=standby status=+H
ProxySet lbmethod=byrequests
</Proxy>
<Location /balancer-manager>
SetHandler balancer-manager
</Location>
ProxyPass /balancer-manager !
ProxyPass / balancer://application-cluster/
ProxyPassReverse / balancer://application-cluster/
</VirtualHost>
As you can see here, application1 is definded as a hot standby and should be the "victim" to handle requests if all other BalanceMembers are "offline" for new requests
What works:
- The requests are load balanced to both BalancerMembers.
- application1 and application2 can signal to not receive any requests. In this case both BalancerMembers show the expected status "Init HcFl" on the the Balancer Manager page.
What doesn't work:
- application1 doesn't show up as hot standby on the Balance Manager page
- Therefore requests will not be forwarded to application1
What's possible but I don't want to do:
- If I configure the hot standby to forward to another port on application1 it will show up and forward requests to this port.
It seems like Apache just removes a BalancerMember if host and port are equal to another BalancerMember. Do I miss something or is there another way to achieve what I want?