Welcome!

IBM Cloud Authors: Dalibor Siroky, William Schmarzo, John Worthington, Liz McMillan, APM Blog

Related Topics: IBM Cloud

IBM Cloud: Article

Building High-Availability Web Applications - Managing HTTP sessions within clustered WebSphere 5 environments

Building High-Availability Web Applications - Managing HTTP sessions within clustered WebSphere 5 environments

To provide the best performance and availability for WebSphere applications, administrators and developers count on scalability features found in the software, hardware, and networking components that host their WebSphere domain. More than ever, the availability of our Web applications can impact critical business processes.

Recognizing this, WebSphere technologists are implementing high-availability (HA) clusters using WebSphere Application Server Network Deployment Edition v5, hereafter referred to as ND. Along with HA functionality found in databases, Web servers, and operating systems, ND can be implemented to deliver the benefits of HA architecture: increased performance, failover, recovery, and workload management.

Let's now consider the Java applications hosted within WebSphere. Are they affected when the application servers that contain them are cloned? In the development life cycle, did you consider that your code might be deployed into a clustered WebSphere topology? For the servlet and JSP developer, this means that requests to servlets or JSPs might not be serviced by the same application server, even though the requests might all be for the same session.

In this article, I will examine HTTP session management strategies in clustered WebSphere environments from the perspectives of the administrator and the developer. I will make the case for implementing ND's framework for session management as an alternative to client-tier sessions, describing the tracking and persistence functionality that ND delivers.

Client-Tier Session Management
The HTTP session is implicitly stateless; this limitation must be considered when designing an HA solution. One way developers can overcome this limit is by storing the session at the client (browser) and delivering it as part of each server request.

There are several ways developers can store the session data at the client, including URL rewriting, cookies, and hidden HTML form elements. These are not to be confused with ND's session tracking mechanisms. The difference is that ND uses URL rewrites or cookies only to track the session ID. Storing the session in the client means sending all or most of the session data back and forth between the client and the server clone. Here are the major problems found with client-stored session data:

  • Network traffic: In each request to the server, a potentially large amount of session data will be along for the ride. Depending on the implementation, the server might also respond with the entire session. Another drawback is that usually most of the data is unchanged and is unnecessarily exchanged.
  • Varying browser support: When using URL rewriting or cookies to transport an entire session, you might run into size limitations at the client. There aren't standards that specify how long a URL can be or how much data can be stored in a cookie. Each browser enforces different rules.
  • Security: HTML forms can be saved anywhere the browser is rendered. Also, cookie files could be edited and URLs could be altered and pasted into another browser. While it's possible to add encryption, this will mean added complexity and performance overhead.
Since the entire session is part of each HTTP conversation, there is no need for stateful interaction with server clones. In this scenario, it doesn't matter which server clone services the request because the session data is contained in the request.

ND offers the alternative of server-managed sessions through affinity, tracking, and persistence mechanisms. This lets the developer take advantage of server-tier session management, with the added benefits of the HA infrastructure built into ND clusters. The rest of this article describes ND's support and functionality for server-tier session management.

ND Session Affinity
The conversation between a browser and a server clone can contain many exchanges. Since the browser initiates the conversation, the server clone that first services the request must be linked in some way to this new session so that subsequent requests can also be serviced by the same clone. Take, for example, the online shopping cart. As the user shops, items are added to the virtual shopping cart before checkout. This interaction could involve multiple HTTP exchanges. If items in the shopping cart are kept at the server clone, every one of those HTTP exchanges must be serviced by the same clone.

Uniquely identifying this browser-to-server relationship is what's known as session affinity. ND supports session affinity through the plug-in architecture, which defines the transport parameters between the Web server and the server clones. The plug-in parameters are built by the ND administrative server and stored in the plugin-cfg.xml file. When a server cluster is created, ND assigns each clone a unique identifier. Listing 1 shows what it looks like in the plugin-cfg.xml.

Since clone IDs are automatically assigned when the cluster is created, session affinity is enabled by default. The process of matching a session to a clone can impact performance, so if you don't need session affinity, disable it by removing the clone IDs from the plugin-cfg.xml. Also note that the plug-in will bypass session affinity if it doesn't detect session ID as part of the request. I'll discuss later how ND identifies the session and the options we have to track it.

The mechanics of session affinity are pretty straightforward, but it's worth noting that affinity guarantees only that requests for a single session are routed to the same clone. If the clone fails or is shut down, the plug-in will route the request to a different clone. If the alternate clone can't recover the session, then it is lost.

Using our shopping cart example, such a failure will result in an empty cart. To avoid this, ND has session persistence options that make the session recoverable in failover scenarios. But first let's cover session tracking functionality in ND to complete the affinity picture.

ND Session Tracking Mechanisms
In addition to unique clone IDs, establishing affinity requires unique session IDs and an ability to track them in a multipart, browser-to-clone conversation. ND offers three options for tracking the session ID: SSL ID tracking, cookies, and URL rewriting. You can enable more than one tracking mechanism, and ND will resolve them in the following order: (1) SSL session IDs, (2) cookies, and (3) URL rewriting. A good reason to enable more than one mechanism is that each has deficiencies. If you decide to track sessions by SSL ID and the Web server fails, ND can fall back on an alternative tracking mechanism. The great part is that this functionality is built into ND, ready to go. Figure 1 shows ND's session tracking mechanisms.

 

An advantage of SSL tracking is that it doesn't require any code changes. The SSL ID is negotiated between the browser and the Web server, so even an application server failure won't change the session ID. Keep in mind that SSL IDs are affected by the Web server configuration (httpd.conf for Apache-style Web servers) and this may overlap with ND's session management controls. For example, session timeout is set by the SSLV3TIMEOUT parameter in the Web server, and is also set in ND's session management settings. Another possible conflict might occur if your code contains custom session invalidation routines. Be careful to verify each layer (Web server, app server, Web apps) to ensure one doesn't step on another.

As a tracking mechanism, cookies can be problematic. Many users block cookies out of concern for privacy. Some network administrators filter out cookies at the firewall. Still, beyond any privacy concerns, there are valid technical reasons for avoiding cookies. If cookies are permitted they can easily be manipulated at the client through browser controls or at the file system. Cookie files can be purged, expired, and changed manually. Any of these actions will cause loss of the session ID. If we don't trust cookies to hold session data, then we shouldn't trust cookies to hold the reference (session ID) to the session data either.

URL rewriting is fairly straightforward and involves appending the session ID to the end of a URL. There is a simple code requirement that the servlet or JSP must encode the URL for ND to properly recognize that a URL has a session attached to it.

The following code snippet shows the URL encoding in the servlet:

out.print(response.encodeURL("/storefront/chiisai"));

The following code snippet shows the URL encoding in the JSP:

<%= response.encodeURL(request.getRequestURI())%>

A big advantage for URL rewriting is that it works everywhere. It also supports concurrent sessions for single users, but this could be troublesome if the user pastes the URL of an active session into a new browser instance. The server wouldn't know which browser instance was active. From a code perspective, especially for JSPs, URL rewriting can be awkward. Any page links in the JSP that need stateful session information would need their URLs rewritten. Also off-limits are any static HTML pages, because there's no way to insert the session ID.

The IBMSession Interface
It is quite common for Web applications to store session data at the server in a session object without persistence. This nonpersisted, local session exists only in JVM memory; if it is not persisted through ND, it is not made available outside this JVM and doesn't play a role in the HA infrastructure. Be careful not to confuse in-memory local sessions with ND's memory-to-memory replication. In-memory local sessions are limited to a single server (per the Servlet 2.3 specification), and don't offer recovery options after failover.

Servlet developers using local sessions store information through the HttpSession interface. The HttpSession is obtained through the HttpServletRequest, and is handled in the servlet's doGet() and doPost() methods. The HTTPSession methods to access and update the session include:

HttpSession hsess = req.getSession();
Object o = hsess.getAttribute("sessAttributeName");
hsess.setAttribute("sessAttributeName", sessObject);

The IBMSession interface extends the HTTPSession to add the following functionality: session overflow control, user identity association, and the ability for the developer to force a session to be persisted externally. While the first two fall under the umbrella of ND's session management offerings, it is the session persistence method that is important in a clustered topology. The developer has complete control of when the session gets persisted by calling the sync() method. This level of control is new in ND; previously the persistent store update was deferred until the end of the time interval specified in the session manager's write frequency settings, as shown in Figure 2.

 

Developers who store session data at the server can easily implement the IBMSession interface, and won't have much work left to achieve a server-tier session management system that supports failover. An added bonus is that very little, if any, code needs to change to implement persistent sessions with ND.

The WebSphere implementation, through the IBMSession interface, includes methods to access the extended functionality:

IBMSession isess = (IBMSession)req.getSession();
if (isess.isOverFlow()) throw new ServletException ...
String userName = isess.getUserName();
isess.setAttribute("sessAttributeName", sessObject);
isess.sync(); // persist externally

Now we can turn our attention toward what ND offers us for session persistence. We've already seen how the IBMSession interface allows the developer to choose exactly when the persistent store is updated, so let's look at the other way that persistent stores get updated, along with the details about ND's persistence mechanisms.

ND Session Persistence Mechanisms
To briefly review, we've identified the session and the server (IDs), associated the two (affinity), and routed the request (plug-in). As we move on and discuss ND's session persistence functionality, keep in mind that ultimately it is the two persistence options that make failover recovery possible for the session.

Figure 3 shows the distributed environment settings in ND's administrative console. Here you can specify either database or memory-to-memory replication. Memory-to-memory replication is new in ND and uses WebSphere internal messaging.

 

Before the release of ND, database persistence was the only option available. The concept of persisting session objects to a database is fairly straightforward. Usually, when discussing this option, the first question asked is about performance. The general concern is that writing the objects out to a database is slow to begin with, and will collapse under any volume. While it's possible to overload even a very highly tuned system with enough volume, the real problem is the size of the session. When selecting database persistence, you must carefully consider page sizes (if using DB2) and whether to use a multirow schema. A single-row schema means one session object per row. A multirow schema means one session attribute per row. The trade-off is between performance and space in the database. The consensus best practice is to keep the session objects as small as possible and carefully analyze the average session size to determine database structure.

Memory-to-memory replication is a new alternative for persistence released in ND. One of the best reasons to consider this option is that it doesn't require a database. At first look, it might not be a big deal to create and manage a simple database for session persistence; however, the database needs to be part of a clustered solution to avoid a single point of failure.

There are three possible topologies: single replica, dedicated replication server, and peer-to-peer (default). The basic idea is that the session objects are "replicated" in memory between server clones, and the different topologies offer varying degrees of recovery. If a clone fails, the next request is routed through the plug-in, which then, depending on topology, can access a replicated copy of the session. The session size is even more important in memory-to-memory replication than in database persistence. A large session object combined with a high number of users can exhaust JVM heap memory quickly. The performance trade-off comes in the number of servers that participate in replication (based on the three available topologies).

Immediately after a session is persisted, it starts growing stale. Any session updates that happen after the last write won't be recovered in a failover scenario. We must decide between the performance trade-off of low update intervals and an acceptable level of session "freshness." Frequent updates (session synchronization) can hurt server performance. The best strategy is to find the right balance that still keeps your data fresh. In addition to the manual control through the IBMSession interface, you can choose a prepackaged tuning level that doesn't require any code change. The tuning choices are shown in Figure 4.

 

Since performance is an overriding factor in deciding on a persistence method, load testing is important and can help identify any weakness in an HA design before it is implemented. For many developers and administrators it is difficult to stage the entire HA implementation for testing and proof-of-concept purposes. There are some relatively inexpensive options, however, that can help you build a replica of your HA design. The ND environment described in this article was built using VMware's virtual machine software (www.vmware.com), allowing a single workstation to host software components (Web server, database, WebSphere) in separate virtual machines. To test performance and functionality, Apache's JMeter (http://jakarta.apache.org/jmeter/index.html) was used to simulate HTTP requests.

Developers can build use cases and test them against a planned HA configuration. For example, if you plan on implementing memory-to-memory replication using the default peer-to-peer topology, you might be concerned about the replicated sessions exhausting JVM memory. Such virtualized testing can help validate your choice of persistence methods. Developers can also simulate failover by shutting down server clones or even an entire virtual machine to observe recovery behavior.

Conclusion
WebSphere Application Server ND supplies rich session management support in the areas of session tracking and persistence. Since the hardware, network, and software components on the server side of the topology are usually very reliable, it makes good sense to trust application-critical data, like session data, to the server tier. While this article focuses on the HA aspects of ND session management, it should be noted that there are other session-related controls in WebSphere 5 that we did not cover (check the referenced documents for more information). Developers and administrators are encouraged to take advantage of this functionality to build Web applications that meet the demand for application availability.

References

  • Wang, H. and Bransford, M. Server Clusters for High Availability in WebSphere Application Server Network Deployment Edition 5.0: http://ibm.com/support/docview.wss?uid=swg27002473
  • IBM WebSphere Application Server v5.0 System Management and Configuration (IBM Redbook): http://publib-b.boulder.ibm.com/Redbooks.nsf/ RedbookAbstracts/sg246195.html?Open

    Performance Tips

    • By default, JSP pages create a session for every page. To avoid creating unnecessary sessions on JSP pages that don't need a session, set the scope to "false" with: <%@page session="false" %>.
    • If session affinity is not required, disable it by removing the clone IDs from the plugin-cfg.xml file to improve performance.
    • If using database persistence, use a dedicated session database. Storing session data in a shared database can adversely affect performance.
    • Build a small-scale replica of the HA topology and conduct functionality and performance validation testing.
    • Keep session objects small. Large session objects can limit options for session persistence topologies and are resource intensive. Limit data stored in the session to a minimum.
  • More Stories By Christopher Delgado

    Chris Delgado is a consultant based in Atlanta, Georgia, working with clients in the areas of WebSphere, Java, and relational databases. Chris is an IBM-certified specialist in WebSphere and DB2 and has worked as a developer and architect for nearly 10 years.

    Comments (1) View Comments

    Share your thoughts on this story.

    Add your comment
    You must be signed in to add a comment. Sign-in | Register

    In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


    Most Recent Comments
    Olivier Gourment 02/28/08 10:24:58 AM EST

    About session replication in a web/portal application: if you choose the transparent (from the coding perspective) approach and replicate the session every x seconds, don't you risk replicating a corrupted session? (WebLogic would have the same problem). It sounds like calling the sync() method is the right way, although it's non standard...

    @ThingsExpo Stories
    WebRTC is great technology to build your own communication tools. It will be even more exciting experience it with advanced devices, such as a 360 Camera, 360 microphone, and a depth sensor camera. In his session at @ThingsExpo, Masashi Ganeko, a manager at INFOCOM Corporation, introduced two experimental projects from his team and what they learned from them. "Shotoku Tamago" uses the robot audition software HARK to track speakers in 360 video of a remote party. "Virtual Teleport" uses a multip...
    Gemini is Yahoo’s native and search advertising platform. To ensure the quality of a complex distributed system that spans multiple products and components and across various desktop websites and mobile app and web experiences – both Yahoo owned and operated and third-party syndication (supply), with complex interaction with more than a billion users and numerous advertisers globally (demand) – it becomes imperative to automate a set of end-to-end tests 24x7 to detect bugs and regression. In th...
    "Space Monkey by Vivent Smart Home is a product that is a distributed cloud-based edge storage network. Vivent Smart Home, our parent company, is a smart home provider that places a lot of hard drives across homes in North America," explained JT Olds, Director of Engineering, and Brandon Crowfeather, Product Manager, at Vivint Smart Home, in this SYS-CON.tv interview at @ThingsExpo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
    "IBM is really all in on blockchain. We take a look at sort of the history of blockchain ledger technologies. It started out with bitcoin, Ethereum, and IBM evaluated these particular blockchain technologies and found they were anonymous and permissionless and that many companies were looking for permissioned blockchain," stated René Bostic, Technical VP of the IBM Cloud Unit in North America, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Conventi...
    "Cloud Academy is an enterprise training platform for the cloud, specifically public clouds. We offer guided learning experiences on AWS, Azure, Google Cloud and all the surrounding methodologies and technologies that you need to know and your teams need to know in order to leverage the full benefits of the cloud," explained Alex Brower, VP of Marketing at Cloud Academy, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clar...
    It is of utmost importance for the future success of WebRTC to ensure that interoperability is operational between web browsers and any WebRTC-compliant client. To be guaranteed as operational and effective, interoperability must be tested extensively by establishing WebRTC data and media connections between different web browsers running on different devices and operating systems. In his session at WebRTC Summit at @ThingsExpo, Dr. Alex Gouaillard, CEO and Founder of CoSMo Software, presented ...
    A strange thing is happening along the way to the Internet of Things, namely far too many devices to work with and manage. It has become clear that we'll need much higher efficiency user experiences that can allow us to more easily and scalably work with the thousands of devices that will soon be in each of our lives. Enter the conversational interface revolution, combining bots we can literally talk with, gesture to, and even direct with our thoughts, with embedded artificial intelligence, whic...
    Coca-Cola’s Google powered digital signage system lays the groundwork for a more valuable connection between Coke and its customers. Digital signs pair software with high-resolution displays so that a message can be changed instantly based on what the operator wants to communicate or sell. In their Day 3 Keynote at 21st Cloud Expo, Greg Chambers, Global Group Director, Digital Innovation, Coca-Cola, and Vidya Nagarajan, a Senior Product Manager at Google, discussed how from store operations and ...
    In his session at 21st Cloud Expo, Carl J. Levine, Senior Technical Evangelist for NS1, will objectively discuss how DNS is used to solve Digital Transformation challenges in large SaaS applications, CDNs, AdTech platforms, and other demanding use cases. Carl J. Levine is the Senior Technical Evangelist for NS1. A veteran of the Internet Infrastructure space, he has over a decade of experience with startups, networking protocols and Internet infrastructure, combined with the unique ability to it...
    "MobiDev is a software development company and we do complex, custom software development for everybody from entrepreneurs to large enterprises," explained Alan Winters, U.S. Head of Business Development at MobiDev, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
    SYS-CON Events announced today that CrowdReviews.com has been named “Media Sponsor” of SYS-CON's 22nd International Cloud Expo, which will take place on June 5–7, 2018, at the Javits Center in New York City, NY. CrowdReviews.com is a transparent online platform for determining which products and services are the best based on the opinion of the crowd. The crowd consists of Internet users that have experienced products and services first-hand and have an interest in letting other potential buye...
    "There's plenty of bandwidth out there but it's never in the right place. So what Cedexis does is uses data to work out the best pathways to get data from the origin to the person who wants to get it," explained Simon Jones, Evangelist and Head of Marketing at Cedexis, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
    SYS-CON Events announced today that Telecom Reseller has been named “Media Sponsor” of SYS-CON's 22nd International Cloud Expo, which will take place on June 5-7, 2018, at the Javits Center in New York, NY. Telecom Reseller reports on Unified Communications, UCaaS, BPaaS for enterprise and SMBs. They report extensively on both customer premises based solutions such as IP-PBX as well as cloud based and hosted platforms.
    SYS-CON Events announced today that Evatronix will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Evatronix SA offers comprehensive solutions in the design and implementation of electronic systems, in CAD / CAM deployment, and also is a designer and manufacturer of advanced 3D scanners for professional applications.
    Leading companies, from the Global Fortune 500 to the smallest companies, are adopting hybrid cloud as the path to business advantage. Hybrid cloud depends on cloud services and on-premises infrastructure working in unison. Successful implementations require new levels of data mobility, enabled by an automated and seamless flow across on-premises and cloud resources. In his general session at 21st Cloud Expo, Greg Tevis, an IBM Storage Software Technical Strategist and Customer Solution Architec...
    To get the most out of their data, successful companies are not focusing on queries and data lakes, they are actively integrating analytics into their operations with a data-first application development approach. Real-time adjustments to improve revenues, reduce costs, or mitigate risk rely on applications that minimize latency on a variety of data sources. In his session at @BigDataExpo, Jack Norris, Senior Vice President, Data and Applications at MapR Technologies, reviewed best practices to ...
    An increasing number of companies are creating products that combine data with analytical capabilities. Running interactive queries on Big Data requires complex architectures to store and query data effectively, typically involving data streams, an choosing efficient file format/database and multiple independent systems that are tied together through custom-engineered pipelines. In his session at @BigDataExpo at @ThingsExpo, Tomer Levi, a senior software engineer at Intel’s Advanced Analytics gr...
    When talking IoT we often focus on the devices, the sensors, the hardware itself. The new smart appliances, the new smart or self-driving cars (which are amalgamations of many ‘things’). When we are looking at the world of IoT, we should take a step back, look at the big picture. What value are these devices providing? IoT is not about the devices, it’s about the data consumed and generated. The devices are tools, mechanisms, conduits. In his session at Internet of Things at Cloud Expo | DXWor...
    Everything run by electricity will eventually be connected to the Internet. Get ahead of the Internet of Things revolution. In his session at @ThingsExpo, Akvelon expert and IoT industry leader Sergey Grebnov provided an educational dive into the world of managing your home, workplace and all the devices they contain with the power of machine-based AI and intelligent Bot services for a completely streamlined experience.
    SYS-CON Events announced today that Synametrics Technologies will exhibit at SYS-CON's 22nd International Cloud Expo®, which will take place on June 5-7, 2018, at the Javits Center in New York, NY. Synametrics Technologies is a privately held company based in Plainsboro, New Jersey that has been providing solutions for the developer community since 1997. Based on the success of its initial product offerings such as WinSQL, Xeams, SynaMan and Syncrify, Synametrics continues to create and hone inn...