-
1. Re: Configuring sticky session attribute name
jfclere Jul 4, 2017 11:41 AM (in response to leaqui)How are the balancer members defined?
-
2. Re: Configuring sticky session attribute name
leaqui Jul 4, 2017 3:38 PM (in response to jfclere)Thanks for replying Jean.
We use system properties:
modcluster.balancer.name = xxxxx
modcluster.proxy.list = balancer.ip:port
-
3. Re: Configuring sticky session attribute name
jfclere Jul 6, 2017 7:49 AM (in response to leaqui)try:
modcluster.balancer.StickySessionCookie = xxxx
-
4. Re: Configuring sticky session attribute name
leaqui Jul 7, 2017 10:04 AM (in response to jfclere)It didn't work Jean.
Is it possible to configure, at balancer, a cookie name for session id different than what is used in the back-end server?
What I want to do is to manage the sticky session duration. So when a client doesn't make requests for a period of time, next request could go to a different server than the original, without losing its session.
We have a distributable application that keeps a reference to logged user in the web session. But at login time, the web session replication isn't enough fast as requests that follow the login request. So, if, for those requests, the balancer choose a node that doesn't have been replicated yet, the user wouldn't be in session and an error occur.
The solution I found is using a cookie A at backend Server, a cookie B at balancer and manage both cookies at client. A the beginning I set B=A, but when there isn't activity for a period of time, I clear B so that balancer could choose another server.
Few months ago I´ve made a question load balancing - Sticky session duration - Stack Overflow and posted this solution but I couldn't make it work.
Is [MODCLUSTER-477] Broken design: session cookie name should be specified on the Context level instead of the Engine level… related to this?
Thanks in advance
-
5. Re: Configuring sticky session attribute name
jfclere Jul 7, 2017 11:52 AM (in response to leaqui)Is it possible to configure, at balancer, a cookie name for session id different than what is used in the back-end server?
I don't understand what you want to achieve with that...
balancers aren't storing sessions nor session information so they can't know when a session is expired.
MODCLUSTER-477 isn't related to your problem.
-
6. Re: Configuring sticky session attribute name
leaqui Jul 7, 2017 2:02 PM (in response to jfclere)I want to achieve a better load balance between back-end servers.
Imagine 2 servers (X, Y) and 6 clients (A, B, C ,D ,E, F) configured with sticky session.
At the beginning, A, C and E start sessions with X and B, D and F start sessions with Y.
Later A, C and E end their sessions.
The result is a system that is not well balanced, because Y has 3 active sessions and X doesn't have any.
Some of our sessions are heavy weight and last for 8 hours, so this problem gets bigger.
-
7. Re: Configuring sticky session attribute name
leaqui Jul 10, 2017 1:27 PM (in response to leaqui)jfclere, am I wrong if I conclude that it's impossible to configure, at balancer, a cookie name for session id different than what is used in the back-end server?
-
8. Re: Configuring sticky session attribute name
pferraro Jul 11, 2017 7:52 AM (in response to leaqui)leaqui What you are looking for is a mechanism for the servers to rebalance the sessions such that work is redistributed following a change to your server topology, and yet session stickiness is preserved. I am not sure what you hope to achieve by changing the cookie name, but, in general, load balancers do not have any knowledge of where a given session is located. This is, however, typically supported by your application server itself. WildFly's distributed session manager supports this, for one.
-
9. Re: Configuring sticky session attribute name
leaqui Jul 11, 2017 10:54 AM (in response to pferraro)Thanks pferraro for answering.
Paul Ferraro escribió:
leaqui What you are looking for is a mechanism for the servers to rebalance the sessions such that work is redistributed following a change to your server topology, and yet session stickiness is preserved.
Server topology is not changed. What has changed is number of clients connected to Server X, making the cluster to be unbalanced in a "standard" sticky session scenario.
I am not sure what you hope to achieve by changing the cookie name, but, in general, load balancers do not have any knowledge of where a given session is located. This is, however, typically supported by your application server itself.
What I am looking for is a better load balance after the scenario of 2 servers and 6 clients I mentioned before.
A way to achieve this is implementing a duration for the sticky session. So after a period of time the cluster could be balanced again.
The way I found to implement sticky session duration, is that the balancer looks to another cookie (MYSESSIONID, different from JSESSIONID) so when the period of time spent, the client can clear MYSESSIONID cookie, so the balancer must assign a server following metrics configured, re-balancing the cluster.
WildFly's distributed session manager supports this, for one.
I am using JBoss AS 7, does Wildfly implement some mechanism for re-balance the cluster?
Again, thanks for your time, Paul
-
10. Re: Configuring sticky session attribute name
leaqui Jul 19, 2017 3:23 PM (in response to leaqui)Finally I´ve found a way to configure the session cookie name, but I´ve needed to make some minor changes in mod_cluster-container-jbossweb.
I've created a JBossWebEngine subclass:
package org.jboss.modcluster.container.jbossweb;
import org.apache.catalina.Engine;
import org.jboss.modcluster.container.Server;
import org.jboss.modcluster.container.catalina.CatalinaFactoryRegistry;
public class CustomJBossWebEngine extends JBossWebEngine {
private static final String CUSTOM_SESSION_COOKIE_NAME_ATT = "org.jboss.modcluster.container.jbossweb.customSessionCookieName";
private static final String CUSTOM_SESSION_PARAMETER_NAME_ATT = "org.jboss.modcluster.container.jbossweb.customSessionParameterName";
private String sessionCookieName;
private String sessionParameterName;
public CustomJBossWebEngine(CatalinaFactoryRegistry registry, Engine engine, Server server) {
super(registry, engine, server);
}
@Override
public String getSessionCookieName() {
if (this.sessionCookieName == null) {
this.sessionCookieName = System.getProperty(CUSTOM_SESSION_COOKIE_NAME_ATT,
super.getSessionCookieName());
}
return this.sessionCookieName;
}
@Override
public String getSessionParameterName() {
if (this.sessionParameterName == null) {
this.sessionParameterName = System.getProperty(CUSTOM_SESSION_PARAMETER_NAME_ATT,
super.getSessionParameterName());
}
return this.sessionParameterName;
}
}
And an EngineFactory implementation:
package org.jboss.modcluster.container.jbossweb;
import org.jboss.modcluster.container.Engine;
import org.jboss.modcluster.container.Server;
import org.jboss.modcluster.container.catalina.CatalinaFactoryRegistry;
import org.jboss.modcluster.container.catalina.EngineFactory;
public class CustomJBossWebEngineFactory implements EngineFactory {
@Override
public Engine createEngine(CatalinaFactoryRegistry registry, org.apache.catalina.Engine engine,
Server server) {
return new CustomJBossWebEngine(registry, engine, server);
}
}
And modified the /META-INF/services/org.jboss.modcluster.container.catalina.EngineFactory file:
org.jboss.modcluster.container.jbossweb.CustomJBossWebEngineFactory
And specified the system properties:
org.jboss.modcluster.container.jbossweb.customSessionCookieName=TESTID
org.jboss.modcluster.container.jbossweb.customSessionParameterName=testid
It would be nice if you could add this to mod_cluster.