leaqui
leaqui

Reputation: 543

Sticky session duration

is it possible to specify the sticky session duration in mod_cluster?

I mean that the stuck session is cleared when there isn't activity for a period of time.

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.

Another use of this functionality would be when you use cached information on a server. If you don't use sticky session you would load to cache several times the same information in different servers. But if you use sticky session you would be tied to the same server for all session life.

Thanks in advance

Leandro

Upvotes: 0

Views: 2204

Answers (2)

leaqui
leaqui

Reputation: 543

I´ve found a workaround for our needs.

I configure different stickysession attribute at balancer (BALANCER_SESSION_ID_HEADER_NAME) and manage balancer sticky session duration at client side.

First time, I set counter + JSESSIONID to BALANCER_SESSION_ID_HEADER_NAME. Every time the STICKY_SESSION_TIMEOUT is spent, I set ++counter + JSESSIONID to BALANCER_SESSION_ID_HEADER_NAME.

Client code:

if (USE_STICKY_SESSION_TIMEOUT && this.getjSessionId() != null) {
  if (this.getLastResponseTime() != 0
      && new Date().getTime() - this.getLastResponseTime() > STICKY_SESSION_TIMEOUT) {
    balancerSubsessionCounter++;
  }

  final String cookie = BALANCER_SESSION_ID_HEADER_NAME + "=" + balancerSubsessionCounter + "-"
      + this.getjSessionId();
  this.addCookie(httpPost, cookie);
}

//invoke service

if (USE_STICKY_SESSION_TIMEOUT) {
  this.setLastResponseTime(new Date().getTime());
}

Upvotes: 0

Michal Karm Babacek
Michal Karm Babacek

Reputation: 434

Answer

It is not possible to switch session stickiness in mod_cluster On and Off for a certain time duration. One either has it On or Off.

Further comments

IIUC, you are in fact after session expiration or session invalidation. You can programatically decide to invalidate your session at any moment, or you might let it expire by setting expiration timeout.

Could you perhaps elaborate more on how would you use the "session stickiness timeout"? We could create a JIRA and and implement a new feature if it makes sense...

Upvotes: 2

Related Questions