Getting Started with Coherence*Web in WebLogic Server 12.1.2

Introduction

Coherence*Web is a great feature which allows you to store your HTTP sessions in a Coherence Cluster.  Doing this allows your to de-couple the HTTP sessions from your JVM’s that are running your web apps, (which can free up JVM memory) and take advantage of the RASP (Reliability, Availability, Scalability and Performance) capabilities of Coherence for storage.

With this separation you can also more easily scale and manage and your HTTP session tier as well as utilise the wide array of session management options that Coherence*Web provides.

What I’d like to show you here is how to configure Coherence*Web in WebLogic Server 12.1.2 and deploy a basic web application that utilises this.

For more detailed information on Coherence*Web and the options available, see http://docs.oracle.com/middleware/1212/coherence/COHCW/start.htm#sthref11.

Setup

For this example, I’m assuming you already have installed WebLogic Server 12.1.2 and created a domain with node manager running.

If you are not familiar with how to do this, then you can use one of my posts here as a starting point or see the product documentation here.

We are going to create two WebLogic Server Clusters and a Coherence cluster into which we shall place both WLS clusters. This will ensure that the manages servers in both WLS clusters are associated with a common set of Coherence caching services

  • StorageTier – 2 Coherence managed servers storage1 and storage2. This tier will hold the HTTP session data.
  • ClientTier – 2 regular application managed servers client1 and client2 – We will deploy our application to this tier.

Typically you would have multiple servers in each tier and have a load balancer in front, but for this example, we will just 2 which is the minimus to demonstrate session fail-over.

Once you have your AdminServer and node manager up and running, login to the console to carry out the following steps.

1. Create a Coherence Cluster

  • Navigate to Domain Structure then Environment and click on Coherence Clusters.
  • Give it a name and leave the defaults.  Do not target it the AdminServer as we will target it in a moment.

Coherence Cluster

2. Create the WebLogic Clusters, place both your WLS clusters in the Coherence cluster and configure Coherence storage for each WLS cluster

  • Navigate to the Clusters link and create 2 clusters. StorageTier and ClientTier.
  • Leave the defaults as is.
  • Select the StorageTier cluster and click on the Coherence tab.
  • Select your newly created Coherence cluster and click Save.
  • Select Coherence Web Local Storage Enabled to ensure any managed servers in this cluster store Coherence*Web session data.
  • Click Save to continue.

Storage Tier

  • Select the ClientTier cluster and click on the Coherence tab.
  • Select your newly created Coherence cluster and click Save.
  • De-select Local Storage Enabled and click Save. We don’t want to actually store HTTP sessions in the client tier, but we want to be able to access them.

Client Tier

3. Create Managed Servers to populate each WLS cluster.

Note the managed servers added to each cluster will inherit their Coherence config form the cluster wide values which you set above. This means the Coherence managed servers added to the Storage Tier WLS cluster will be providing session storage while the Regular managed servers in the Client Tier WLS cluster will be coherence clients.

  • Navigate to the Servers link
  • Create a new managed server called client1 and assign it to the ClientTier as well as the machine you created. Set the listener port to 7005.
  • Create a new managed server called storage1 and assign it to the StorageTier as well as the machine you created. Set the listener port to 7007.
  • Clone storage1 and name it storage2 and change the listener port to 7009.
  • Start up you managed servers.

Managed Servers

Deployment

Now we need to Deploy applications which will demonstrate session fail-over and management features we have configured

  1. ClusterJSP – (optional) shows session failover.
  2. Sample-applications (optional) shows session management features

Deployment 1 ClusterJSP
Deploy ClusterJSP as a directory deployment rather than a archive deployment. This will make modifications of the deployment descriptors easier.  You can download the file required from here.

Deploy the Application

  • Unzip clusterjsp-ear.zip into your WLS domain applications directory (…/user_projects/applications)
    <wls install…>/applications/clusterjsp-ear/clusterjsp-war/WEB-INF/weblogic.xml
  • In the Admin. Console navigate to the Deployments page.
  • Click the Install button and navigate to the applications directory where you should find the clusterjsp-ear directory.
  • Click the select button to the left of the folder and click the Next button at the bottom of the page.
  • Leave Install as application selected and click Next.
  • Select ClientTier cluster and click Next.
  • Leave the defaults and click Finish.

Test the application

  • In a browser access the clusterjsp with the following url: http://yourhostname:7003/clusterjsp
  • Follow the instructions at the bottom of the displayed page.
  • To access the page from the other server in the client tier cluster change the the port number in the browser and hit enter. Notice the session attribute and value which you had added are not present because we have not yet enabled Coherence*Web.

Application Screenshot

Enable Coherence*Web Session Storage

  • Create a WLS deployment descriptor to enable Coherence*Web sessions by saving the text below into a new file called:
    <wls install…>/applications/clusterjsp-ear/clusterjsp-war/WEB-INF/weblogic.xml
<?xml version="1.0"?>

<weblogic-web-app xmlns="http://www.bea.com/ns/weblogic/weblogic-web-app"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.bea.com/ns/weblogic/weblogic-web-app http://www.bea.com/ns/weblogic/weblogic-web-app/1.0/weblogic-web-app.xsd">

  <session-descriptor>
    <persistent-store-type>coherence-web</persistent-store-type>
  </session-descriptor>

</weblogic-web-app>
  • In the Admin. Console navigate to the Deployments page.
  • Update the deployment by click the Select button next to the clusterjsp-ear application and click the Update button.
  • Repeat your previous test. This time you should see your Session attributes are present regardless of which client tier server you access.
  • Stop the servers one at a time in each tier and notice when the session data is no longer available.

Deployment 2 Large session sample-application

Next, deploy the sample-application.war (available from here) to just the ClientTier WebLogic Cluster.

The only step required to configure a web application to use Coherence*Web, select coherence-web as the persistence-store-type in WEB-INF/weblogic.xml as shown above. It’s that simple!

Next, run the application using the URL: http://your-ip-address:7005/sample-application and choose ‘Create Session’, then ‘Display Session’.  This is only a simple application with no real bells and whistles, to show you how to enable Coherence*Web for a web application.

You can see the output displays something similar to the following, which shows that Coherence is being used as the HTTP session store provider.

class: class weblogic.servlet.internal.session.CoherenceWebSessionData
sessionid: Vqi9nQtgCjpfO2F6FBHieVZV2vEmXfqF8Tyx6QDaQddqRhyKrFQM!502625314!1400916309965

The create.jsp file contains the following. Here we are just using the HTTP session and no Coherence specific code is used. You can experiment with the other links in the sample application.

<%@ page import="java.util.*"%>

<%
session = request.getSession(true);

out.println("class: " + session.getClass() + "<br/>");
out.println("sessionid: " + session.getId());
HashMap m = new HashMap();
m.put("a", 1);
m.put("b", 1);
session.setAttribute("test", m);
%>

Your web application is now using Coherence to store your HTTP sessions!

It’s very easy to scale out your HTTP session tier, just add another managed server to your StorageTier.

You can skip to the Conclusion below, or continue with the next section where I’ll show you how to install the Coherence JVisualVM Plug-in to view what’s going on under the covers.

Use the JVisualVM Plug-in from the Coherence Incubator Project to monitor the Coherence*Web session data

I’m using the Coherence JVisualVM Plug-in from the Coherence Incubator for viewing MBean information for the rest of this demo. You could just as well browse the MBean tree, but the Plug-in shows this in a nicer format.

For detailed information on how to install and connect jvisualVM to a WebLogic Server environment please see the Coherence Incubator site.

Install the Coherence VisualVM plugin brief steps

  • Download the latest pre-built plug-in module (NBM) from search.maven.org and save it to a local directory.
  • Start JVisualVM by running jvisualvm or jvisualvm.exe (for Windows) from the bin directory under your Java home.
  • Choose Tools -> Plugins.
  • Click on the ‘Downloads’ tab.
  • Click ‘Add Plugin’ and choose the file coherence-jvisualvm-12.2.0.nbm (from the location where you saved above).
  • Click ‘Install’ and follow the prompts to install.

Once installed, connect to either a remote or local JMX enabled Coherence cache server process using JMX

  • Restart jvisualvm with the following command (I have used UNIX style backslash for line continuation. If you are on Windows then please ensure the command is on one line.)
    $JAVA_HOME/bin/jvisualvm --cp:a \
    $WL_HOME/server/lib/wljmxclient.jar:$WL_HOME/server/lib/weblogic.jar \
    -J-Djmx.remote.protocol.provider.pkgs=weblogic.management.remote \
    -J-Dcom.oracle.coherence.jvisualvm.disable.mbean.check=true
    
  • To create a connection right-click on either ‘Local’ or ‘Remote’ under the ‘Applications’ tree. Use the following for the connection URI and enter the credentials for the WebLogic Server Admin: (the following should contain no spaces)
    service:jmx:iiop://hostname:port/jndi/weblogic.management.mbeanservers.domainruntime
  • Once you have opened the newly created connection you will see the ‘Coherence Tab’.
  • For troubleshooting, see the Coherence Incubator site.

After connecting to the domain runtime mbean server, you should see the ‘Coherence’ tab displayed, select this tab and then the ‘Coherence*Web’ tab and you will see that there is a session that has been created.

Coherence*Web

If you then choose ‘Heavy Session’ in the sample web application, you will see the session overflow count go up as Coherence will store large attributes in a separate cache for optimised performance.

If you look at the ‘Caches’ tab, you will see the size of the session-storage and session-overflow caches are updated.

Coherence*Web Caches

Lastly, I used JMeter to create a load script that called the create.jsp and heavy.jsp to create sessions. You can see from the screenshot below, that you are able to view the number of sessions created and any session-reaping, which is cleaning up of old sessions.

More Sessions

Conclusion

It may have seemed that we went though a few steps above, but I wanted to show the evidence of the HTTP sessions begin stored Coherence*Web. The high-level steps to setup Coherence*Web are pretty straight forward:

  1. In your WebLogic domain, create a Coherence Cluster.
  2. Create a Client WebLogic Server Cluster and managed servers for your web apps and associate with the Coherence cluster as storage-disabled.
  3. Create a Storage WebLogic Server Cluster and managed servers for your data tier. Make this storage-enabled and also check ‘Coherence Web Local Storage Enabled‘.
  4. Update your WEB-INF/weblogic.xml to use coherence-web as persistence-store-type.
  5. Deploy your application and you are away.

Enjoy

 

 

About these ads
This entry was posted in Examples and tagged , , . Bookmark the permalink.

One Response to Getting Started with Coherence*Web in WebLogic Server 12.1.2

  1. Pingback: WebLogic Partner Community Newsletter June 2014 | WebLogic Community

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s