Search This Blog

Monday, November 23, 2009

Websphere -- maximum # of sessions

Have you ever wondered what happens if, for whatever reason, there is a runaway amount of logins into your application.

The answer probably is -- not good things. Especially if you have any amount of data in your session, your server is going to struggle with managing the memory, i/o for session persistence etc.

So, on the assumption you agree with the premise: 'Do three things well -- instead of ten things badly'. You'll want to do something about this.

For Websphere at least there is a setting in the administrative console to set the maximum number of sessions on the server.

First of all you'll have to decide what this number should be. Only you really know the answer. Set this (or have this set) via the administrative console. 'Application Servers > serverName > Web Container > Session Management'. The 'Allow overflow' checkbox needs to be unchecked of course.

Your job is not done. You should be asking, what happens when this maximum is reached. Perhaps 'request.getSession(true);' will return null, or throw an exception? The answer is neither of those. Websphere will return you a session, but it will be an invalid one.

So, you will have to add this code to wherever you do a getSession(true) or a getSession(). Hopefully (presumably?) this isn't in more than a few places in your code.

HttpSession session = request.getSession(true);
IBMSession ibmSession = (IBMSession)session;
if (ibmSession.isOverflow()) {
... appropriate action ..

} else {

.. continue normally ..

}

Most likely you are going to want to simply redirect them to a simple html page with a message to the effect 'Server Busy, please retry later'.

1 comment:

  1. Thanks for sharing... I'm using now the following code snippet which allows me to run on multiple app containers


    private boolean isOverflow(HttpSession pSession) {
    Class types[] = {};
    Object params[] = {};

    try {
    Class ibmSession = Class.forName("com.ibm.websphere.objectgrid.IBMSession");
    Method method = ibmSession.getMethod("isOverflow", types);
    return (Boolean) method.invoke(pSession, params);
    } catch (Exception e) {
    LOG.error("Problem with IBMSession.isOverflow : " + pSession.getClass(), e);
    return false;
    }
    }

    ReplyDelete