I’m having an application setup where there are multiple instances of application running (let’s say two instances/servers s1 and s2) balanced by HAProxy. We are using sticky session based on application session cookie. So if the first lands on s1 server, all the subsequent requests will land on s1 server.
The configuration I’m using for stickiness is below:
backend app_server
...
cookie appCookie prefix nocache
server s1 <ip> cookie s1
server s2 <ip> cookie s2
Now what I want to achieve is to remove the stickiness based on the load on the server. Let’s say there are two active sessions on s1 and if the cpu utilization reaches 90%, drop all the session redirection to s1 (including the active sessions) and redirect them on s2. And once the utilization settles down on s1, balance the requests in a normal fashion with stickiness enabled.
I looked around for using agent-check, to use agent utility to check for server cpu utilization and remove/delete cookie if the feedback from agent-check if more than 90%. But I faced 2 challenges:
- I found no way to remove/delete the cookie conditionally.
- I found no way to use last agent-check feedback to use in the condition.
Can anyone provide their views to achieve this?