[Type text] Hands-on Lab Session 19120 Develop, Deploy, and Monitor a Java EE 6 Application with Clustered GlassFish 3.1 Arun Gupta Java EE & GlassFish Guy blogs.oracle.com/arungupta, @arungupta Byron Nevins GlassFish Monitoring Lead blogs.oracle.com/foo
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
[Type text]
Hands-on Lab Session 19120 Develop, Deploy, and Monitor a Java EE 6 Application with Clustered GlassFish 3.1 Arun Gupta Java EE & GlassFish Guy blogs.oracle.com/arungupta, @arungupta
Byron Nevins GlassFish Monitoring Lead blogs.oracle.com/foo
3.0 Download, Walk-through, and Build the Java EE 6 Application ........................................................................... 5
3.1 Get the Application ............................................................................................................................................. 5
3.2 Read the Application........................................................................................................................................... 6
3.3 Build the Application .......................................................................................................................................... 7
4.0 Create a 2-instance Cluster and Deploy the Application ........................................................................................ 8
4.1 Start the GlassFish Domain Administration Server ............................................................................................ 8
4.2 Start the Database Server .................................................................................................................................. 10
4.3 Create the Cluster using Admin Console .......................................................................................................... 10
4.4 Start the Cluster................................................................................................................................................. 11
4.5 Enable the JDBC Resource for the Cluster ....................................................................................................... 12
4.6 Deploy the Application to the Cluster .............................................................................................................. 12
4.7 Verify the Application Deployment .................................................................................................................. 13
5.0 Install and Configure the Load Balancer .............................................................................................................. 14
5.1 Install the Oracle iPlanet Web Server ............................................................................................................... 14
5.2 Install the GlassFish Load Balancer Configurator ............................................................................................ 16
5.3 Create, Export, Upload a Load Balancer Configuration ................................................................................... 19
5.4 Access the Application and Show Session Failover ......................................................................................... 21
6.0 Monitor the Application ........................................................................................................................................ 22
6.1.1 Use the JavaScript Listener ........................................................................................................................ 25
6.2 Automatic Monitoring Data .............................................................................................................................. 27
7.1 How to restart Oracle Web Server Administration Server ?............................................................................. 28
7.2 How to change Oracle Web Server password ? ................................................................................................ 28
7.3 How to restart GlassFish ? ................................................................................................................................ 28
7.4 Getting an error “failed to join group c1” ? ...................................................................................................... 28
7.5 Deployment gives “Command succeeded with Warning”................................................................................ 30
7.6 Session data not preserved ................................................................................................................................ 30
7.7 No monitoring data from the script ................................................................................................................... 30
1.0 Introduction GlassFish Server Open Source Edition 3.1.1 is a fully open sourced, community-supported, Java EE 6 compliant application server. It offers a modular runtime based on OSGi and full-featured clustering with centralized administration of multiple clusters and high availability of stateful components. GlassFish also offers advanced features such as application versioning, application-scoped resources, non-intrusive RESTful management and monitoring. It also provides integration with NetBeans, Eclipse, and other popular IDEs. Oracle GlassFish Server is the commercially supported version of the open source edition and is ideally suited for applications requiring lightweight infrastructure with most up-to-date implementations of enterprise Java. This hands-on lab will:
Walk you through and deploy a typical Java EE 6 application using NetBeans and GlassFish.
Create a two-instance GlassFish cluster and front end with a Web server and a load balancer.
Demonstrate session replication when one of the instances fails.
Use the extensible monitoring infrastructure to generate application-specific monitoring data.
This lab will get you ready to put a Java EE 6 application into production. The latest version of this document is available at http://blogs.oracle.com/arungupta/resource/javaone2011/19120-lab-instructions.pdf. Please talk to us using GlassFish Forums (link in the References section).
2.0 Software Requirements This lab requires the following software:
1. JDK 1.7+ can be downloaded from http://www.oracle.com/technetwork/java/javase/downloads/java-se-jdk-7-download-432154.html.
2. NetBeans 7.0.1+ (“All” or “JavaEE” bundle) can be downloaded from http://netbeans.org/downloads/index.html.
3. Oracle GlassFish Server 3.1.1 (zip bundle) can be downloaded from http://www.oracle.com/technetwork/java/javaee/downloads/ogs-3-1-1-downloads-439803.html.
4. Oracle Web Server 7.0.9+ can be downloaded from https://updates.oracle.com/download/12676928.html.
5. GlassFish Load Balancer Configurator 3.1.1 can be downloaded from http://www.oracle.com/technetwork/middleware/glassfish/downloads/glassfish-lbconfig-3-1-1-downloads-439811.html.
If you are doing this lab as part of the JavaOne 2011 Hands-on Lab session then:
All the software is already downloaded in the C:\Users\Lab\Downloads
directory.
The software 1 and 2 are pre-installed at their default locations, 3 is installed in the
C:\javaone2011 directory, and 4 – 5 will be installed as part of the lab exercise.
Oracle GlassFish Server is pre-configured in the NetBeans IDE.
3.0 Download, Walk-through, and Build the Java EE 6 Application This section will explain how to download the Java EE 6 Application, explain the different parts, and then build it. This section should take about 20 mins.
If you are interested in building a complete Java EE 6 application using NetBeans and GlassFish, then consider attending the hands-on lab #23421 at JavaOne 2011 with the title “Beginning Java EE 6”.
3.1 Get the Application Download the application from http://blogs.oracle.com/arungupta/resource/javaone2011/19120-app.zip and unzip.
3.2 Read the Application In the NetBeans IDE, choose “File”, “Open Project…” (short cut key
= Ctrl+Shift+O), select the unzipped directory, and click on
“Open Project”. NetBeans may show red lines under some of the annotation in different classes. This can happen if Maven does not have all
the dependencies in the local repository. This will however get resolved once the project is built. The expanded project structure looks like as shown. This is a typical 3-tier application that shows the list of movies stored in a database and allows the user to select a preferred list. The three tiers use JSF for the UI, EJBs for the middle tier, and JPA/JavaDB for the database tier. The basic architecture of the application is shown below: The movie database is created using a singleton EJB
(DatabaseSingletonBean.java) and a JPA entity (Movie.java). A stateless EJB
(MovieSessionBean.java) is used to query the database and return the results that
are displayed in a JSF page (index.xhtml). This page also allows the user to specify
movie preferences and save the state using a stateful EJB
(MoviePreferencesBean.java).
The application also consists of the following supporting files:
index.xhtml Database
@Stateless
@Stateful
@Singleton
@Entity
7
ClusterInstanceBean.java: Provides information about the instance on which
the application is deployed.
TestProbeLister.java: Shows all Monitoring Probes that are specific to this
application.
Web Pages/WEB-INF/beans.xml: Enable CDI injection for the beans in the WAR
file
WEB-INF/template.xhtml: Template file for the JSF pages and used in the
index.xhtml.
WEB-INF/web.xml: Contains <distributable/> element to ensure that the app
can run in a distributed environment and the sessions can be replicated in a clustered environment.
Other Sources/…/persistence.xml: JPA Persistence Unit that points to the
default JDBC resource in GlassFish, named jdbc/__default, and uses it for all
database communication.
Web Pages/resources/css/*: Stylesheets used by the template page.
19120-app.js (not shown in the diagram): JavaScript to capture monitoring
events.
The default JDBC resource is defined as a global resource and shared across all different applications. In addition, GlassFish allows to create an application-scoped
resource by bundling the resource definition in WEB-INF/glassfish-
resources.xml. These resources are then created / deleted with application
deployment and are not available for other applications. This hands-on lab does not
use glassfish-resources.xml though.
3.3 Build the Application In the NetBeans IDE, right-click on the project and select “Build” to see an output as: Packaging webapp
Assembling webapp [19120-app] in [D:\code\workspaces\arun\19120-app\target\19120-app]
A similar output ensures that your Web application is successfully built. This generates a
19120-app.war file in the target directory of the application.
The first build of this application may take a few minutes as the Maven will download all the dependencies.
4.0 Create a 2-instance Cluster and Deploy the Application
This section will create a 2-instance GlassFish cluster on the local machine and deploy the previously built application to it. This section should take about 30 mins.
GlassFish has the concept of an administrative domain managed by a Domain Administrative Server (DAS). Multiple Server Instances are managed by a DAS to form a homogeneous cluster.
4.1 Start the GlassFish Domain Administration Server In a Command Prompt, give the following command (highlighted in bold): C:\javaone2011\glassfish3>.\bin\asadmin start-domain
Command start-domain executed successfully. This starts the DAS and shows the following output in the log file at C:\javaone2011\glassfish3\glassfish\domains\domain1\logs\server.lo
You may optionally start the command with the –v switch to display the log on the
console. This can be done by giving the asadmin stop-domain command to stop
the DAS and restarting by giving the command as above with the additional –v switch.
Accessing http://localhost:8080 in a browser window shows the output as shown. This ensures that the Oracle GlassFish Server DAS has started successfully.
The GlassFish provides a web-based Administration Console, aka admin console, and is available at http://localhost:4848 after a successful start of the DAS. The admin console provides a graphical UI for all the administration tasks and is used for creating a cluster, adding instances to it, and deploying applications for our hands-on lab.
4.2 Start the Database Server In a Command Prompt, give the following command (highlighted in bold) to start the database server: C:\javaone2011\glassfish3>.\bin\asadmin start-database
Starting database in Network Server mode on host 0.0.0.0 and port 1527.
--------- Derby Network Server Information --------
Log redirected to C:\javaone2011\glassfish3\glassfish\databases\derby.log.
Command start-database executed successfully.
4.3 Create the Cluster using Admin Console 4.3.1 Go to the admin console, click on “Clusters” in the right navigation tree, and then click the “New…” button. 4.3.2 Enter the cluster name as “c1”, click the “New…” button, specify the instance name as “i1”, click the “New…” button, and specify the instance name as “i2”.
The values entered in the console look like as shown and click the “OK” button. This will create a cluster “c1” with two instances “i1” and “i2” on the local machine and will show the output as:
This indicates that the cluster is created and both the instances in the cluster are not running.
4.4 Start the Cluster Start the cluster by selecting the check box next to “c1” and clicking the “Start Cluster” button. The admin console prompts and click on the “OK” button to confirm. The Command Prompt shows the following output towards the end: [#|2011-09-12T12:31:41.533-0700|INFO|oracle-
Adding Joined And Ready member: i2 group: c1 StartupState: GROUP_STARTUP |#]
A similar output ensures that the cluster is successfully started.
Please see troubleshooting section if the instances are not able to join the cluster.
4.5 Enable the JDBC Resource for the Cluster The application uses “jdbc/__default” as the JDBC resource. This resource is not available to clusters by default and need to be configured by giving the following command using CLI (highlighted in bold): C:\javaone2011\glassfish3>.\bin\asadmin create-resource-ref --enabled=true --target c1
The value specified after the --target is the cluster name previously chosen.
4.6 Deploy the Application to the Cluster 4.6.1 In admin console, click on the “Applications” node, click on “Deploy…”, click on “Browse…”, and point to the generated “19120-app.war” file in
the unzipped application directory’s target
directory. 4.6.2 Make sure to select “Enabled” checkbox next to Availability. This check box ensures that the session replication is enabled for HTTP and Stateful Session Beans. The updated page looks
13
like as shown. Select “c1” as the target for deployment in “Available Targets” as shown below and click on "Add>". Click on “OK” (at the top or bottom of the page).
4.7 Verify the Application Deployment
Click on “Clusters”, “c1” in the navigation tree, “Instances” tab, “i1” and it displays three HTTP ports. The first port is for the administration of this particular instance, the second is the HTTP port for accessing the application, and the third is the HTTPS port.
The deployed application can be accessed using http://<HOST>:<PORT>/19120-app/faces/index.xhtml where <HOST> is “localhost” and <PORT> is 28081 for the instance “i1” in our case. So our application on “i1” will be accessible at http://localhost:28081/19120-app/faces/index.xhtml. Similar our application on “i2” will be accessible at http://localhost:28080/19120-app/faces/index.xhtml.
Accessing this application on “i1” shows the output as: Notice the instance serving the application is displayed in the title bar and the footer. A similar output is shown when this application is accessed on the instance “i2” using the following URL http://localhost:28080/19120-app/faces/index.xhtml. The only difference is that the title bar and the footer shows the correct instance name as shown.
This section will install Oracle Web Server as the Load Balancer and install/configure the GlassFish Load Balancer Plugin for it. This section should take about 40 mins.
5.1 Install the Oracle iPlanet Web Server
5.1.1 Unzip the file Oracle-iPlanet-Web-Server-
7.0.12-windows.zip from the
downloads directory in the
C:\javaone2011 directory.
Note that a top-level directory name needs to be explicitly specified for unzipping. Double-click on the “setup.exe” in the unzipped Oracle Web Server installation directory and click on “Yes” in “User Account Control” dialog box to begin the installation. The dialog box as shown is displayed. Click the “Next>” button. 5.1.2 Take the default installation directory and click on “Next >”. Click on “Yes” on “Create New Directory” dialog box.
5.1.3 Choose the “Express” install and click on “Next>”.
The Web server administrator password must contain at least 8 characters as this is
15
a requirement for the Load Balancer Configurator which will be installed later. 5.1.4 Take the default user name, enter the password as “glassFish” and click the “Next>” button.
5.1.5 Confirm all the values and click on “Install Now>”. This will install the Oracle iPlanet Web Server and also start the Web Server Administration Server. On the next screen, select “Skip Registration” (only to save time otherwise preferred), click on “Next>”, and then click the “Finish” button.
The Oracle Web Server, like any other, uses a self-signed certificate for the administration server. Trying to access the administration server at http://localhost:8989 shows a warning message in the Firefox browser as shown.
The warning message may look different in other browsers. In this case, click on “I Understand the Risks”, click on “Add Exception…”, take the defaults, and click on “Confirm Security Exception”. This shows the login page for the Oracle iPlanet Web Server Admin Console. Enter the “User Name” as “admin” and “Password” as “glassFish” as shown, and click on “Login”.
The following page in the browser ensures that the Web Server is successfully installed:
5.2 Install the GlassFish Load Balancer Configurator
The Load Balancer plugin must be installed using the GUI installer for the first time. Subsequent installations can utilized a generated installer script for headless (remote) installations.
The GUI installer need to run with the Administrator privileges as it creates a directory in the Oracle Web Server instance directory. Start a Command Prompt with the Administrator privileges. This can be easily done by going to the Windows “All Programs”, “Accessories”, right-clicking on “Command Prompt” and selecting “Run as administrator”.
17
5.2.1 Run the GUI installer by giving the following command in a Command Prompt with Administrator privileges: java -jar c:\Users\Lab\Downloads\glassfish-lbconfigurator-
3_1_1.jar
The actual directory name may be different in your environment. 5.2.2 In the Load Balancer Configurator screen, click the “Next” button. 5.2.3 Select the Oracle iPlanet Web Server and click the “Next” button. 5.2.4 In the “LB Plugin Configuration” screen, specify the following values:
<MACHINE-NAME> and is called https-ARUNGUP-LAP.st-users.us.oracle.com
on my local machine and as https-LAB-OAA9LDAV45C.us.oracle.com on a lab test
machine. 5.2.5 Click on “Next” and “Next” to proceed with unzip of the package and see the output as shown. 5.2.6 Click on “Next” to proceed with the installation and see the output as shown.
18
The detailed warning message can be seen by scrolling the window to the right.
The first WARNING message indicate that the C:\Program
Files\Oracle\WebServer7\glassfish-lbplugin\lib directory is added to the
PATH and the machine needs to be re-booted for the settings to take effect. If the Windows PATH environment variable has parameterized values then this directory is not added by the installer. This can be easily fixed by manually adding
C:\Program Files\Oracle\WebServer7\glassfish-lbplugin\lib to the
system environment variable in the Control Panel. The second WARNING message can be ignored as it tries to start the Administration Server which is already running in our case. 5.2.7 Click the “Next” button, review the post-installation procedures (we’ll perform these steps later so can skip as well), click the “Next” button. Click the “Done” button to complete the installation.
You can click the “Generate an automatic installation script” button to generate a script for future installations. This lab does not use or cover it though.
Please make sure to restart GlassFish DAS and Cluster and the Database server after restarting the machine. This can be easily done from the Command Prompt (in
the c:\javaone2011\glassfish3\glassfish3\bin directory) by giving the
following commands: asadmin start-domain
asadmin start-cluster c1
asadmin start-database
The Windows environment may prompt for a firewall warning to run these commands. Accept the warning to proceed with the command execution. And then you'll have to start the Oracle iPlanet Web Server Administration Server from an Administrator-privileged Command Prompt as: C:\Program Files\Oracle\WebServer7\admin-server\bin>startserv
The Oracle iPlanet Web Server 7.0 Administration Server service is starting..
The Oracle iPlanet Web Server 7.0 Administration Server service was started successfully.
19
5.3 Create, Export, Upload a Load Balancer Configuration
5.3.1 Create a load balancer configuration named c1_lb within the DAS (Domain
Administration Server) for the cluster c1 by giving the command (highlighted in bold):
5.3.2 Export the DAS configuration to the file system by giving the command (highlighted in bold): c:\ javaone2011\glassfish3 >.\bin\asadmin export-http-lb-config --lbname c1_lb
This command needs to be executed from an Administrator privileged Command
Prompt. The actual directory starting with https- may be different.
The GlassFish Load Balancer Configurator provides an ease-of-use feature which
allows loadbalancer.xml to be pushed over the wire to the Web server. This
requires to set up a SSL listener on Web server. This is not covered in the lab however more details can be found at http://download.oracle.com/docs/cd/E18930_01/html/821-2426/geobp.html.
5.3.4 Start the Oracle iPlanet Web Server local instance from an Administrator-privileged Command Prompt using the following command (highlighted in bold): C:\Program Files\Oracle\WebServer7\https-ARUNGUP-LAP.st-sers.us.oracle.com\bin>startserv.bat
The Oracle iPlanet Web Server 7.0 (https-ARUNGUP-LAP.st-users.us.oracle.com) service is
starting...
The Oracle iPlanet Web Server 7.0 (https-ARUNGUP-LAP.st-users.us.oracle.com) service was
started successfully.
Check the logs in the file C:\Program Files\Oracle\WebServer7\https-
ARUNGUP-LAP.st-users.us.oracle.com\logs\errors (with the directory name
starting with https- appropriately changed) and look for the output highlighted in bold:
https://ARUNGUP-LAP.st-users.us.oracle.com:28182 has been intialized.
[24/Aug/2011:14:50:30] info ( 8304): HTTP3072: http-listener-1: http://ARUNGUP-LAP.st-
users.us.oracle.com:80 ready to accept requests
[24/Aug/2011:14:50:30] info ( 8304): CORE3274: successful server startup
This output ensures that the LB Plugin is loaded correctly. Accessing http://localhost:80 in a web page displays the output shown and confirms that the local instance has correctly started.
5.4 Access the Application and Show Session Failover 5.4.1 Access the application at http://localhost/19120-app/ to see the output as: As described earlier this page shows the instance serving the application in the title bar
GlassFish comes with a fully-featured Monitoring Framework. Monitoring consists of event emitters, named Probes, and Listeners that receive these events from the Probes. A good way to look at it is that a Probe is simply a public non-static method that has a special annotation. A Probe Provider is a class that contains one or more Probes and which also has a special annotation at class-scope. The infrastructure does the magic of connecting Probes and Listeners at runtime. There are many things you can monitor in your application using the built-in probes that GlassFish provides – without doing anything to your app. For instance you can see when threads are getting created by the Web container to service clients.
6.1 Customized Application Monitoring In this application we are interested in using the Monitoring Framework to provide our own customized monitoring. There are 2 main reasons for using the Monitoring Framework rather than more obvious solutions like writing information to log files:
1. The Monitoring Framework ensures that the Probes have practically no overhead if there is no active listener registered. So the listeners can be attached and detached at will. There is no performance penalty when the listener is detached.
2. We can write interesting (and therefore probably complicated) code in the listener itself that is gathering the data. The listener may not even be part of the application itself. In fact we will run a JavaScript program as our listener.
Let’s take a look at the Monitoring code that is inside the App. The first thing we need to do at run-time is to get a reference to the globally available
object that registers Probe Providers. We use DatabaseSingletonBean.java for this
purpose. The bean is not a Probe Provider itself. But it is a nice handy place where we can inject the Probe Provider Registrar Object. Then we call one line of code to register
our Probe Provider, MovieSessionBean, with the Monitoring Framework.
Here is all of the code needed to do this from DatabaseSingletonBean: import org.glassfish.flashlight.provider.ProbeProviderFactory;
Here the getProbeProvider method takes the class-bytes for
MovieSessionBean.class, finds all the Probes, and injects one line of code into the
end of each such probe method. That one line of code calls into the Monitoring Framework at runtime each time you call the method. The payload are the parameters passed into the probe method that are sent to the framework. The framework then calls all the registered listeners for that particular probe. The probe and their corresponding listeners need to have the exact same method signature to ensure the values are passed correctly.
The byte-code transformer will not do anything until a listener registers for the probe. The transformation is performed just-in-time.
We turned the MovieSessionBean into a Probe Provider by adding this one-line
The long variable names are really just identifying strings. We want all Probe Provider classes in the same application to share exactly the same first three identifying strings so we turned them into constants. This is modeled, exactly, along the lines of DTrace. Every Probe Provider has 3 names and every probe adds one name for a total of 4 names per probe.
This class has 2 Probes: @Probe(name = "getMovieStarted")
public void getMovieStarted(@ProbeParam("nano") long nano) {
}
@Probe(name = "getMovieFinished")
public void getMovieFinished(@ProbeParam("nano") long nano) {
}
The getMovies method is a likely place to check on timing. So the getMovies method
calls the getMovieStarted probe before the database access, and calls the
25
getMovieFinished probe after the database access. It sends the current time, in
nanoseconds, as a parameter, to the probes. If there is no Listener attached then the only overhead is the 2 extra calls to get the current time. The application has a simple Servlet that shows every probe in the system that happens to have “19120” in its name. You can use this Servlet to verify that the Probes have been registered correctly. It also shows you all the Probes that have been created on behalf of the app by the containers. To see the output, access this URL in a browser: http://localhost/19120-app/Probes
And here is the output (truncated). Note the 4-string IDs for all Probes JavaOne:19120-app:MovieSessionBean:getMovieFinished (long nano)
The application’s directory has a java script named 19120-app.js. This script will
register itself as a listener for the 2 probes. In a real world scenario you could add all sorts of interesting complicated code in here. For example it could gather data, and save it in a local repository, generate dynamic charts and reports. In this case the script is listening to the start and finish probes. The script takes the start and finish times, calculate how long the database access took, and then maintain an average of the access time. And then it prints out the current call’s time and the average time.
Before invoking the JavaScript listener you may like to start the instance shutdown earlier by giving the following command (highlighted in bold):
And then the following output is shown after selecting a few movies, clicking on Submit, and going through that a few times. [i1] Time to get all of the movies from the database for this one call = 10.693949 milliseconds
[i1] Time to get all of the movies from the database for this one call = 18.037415 milliseconds
[i1] Current Average Time to get all of the movies from the database = 14.365682 milliseconds
[i1] Current Average Time to get all of the movies from the database = 10.693949 milliseconds
[i1] Time to get all of the movies from the database for this one call = 84.91996 milliseconds
[i1] Time to get all of the movies from the database for this one call = 15.515721 milliseconds
[i1] Current Average Time to get all of the movies from the database = 32.29176125 milliseconds
[i1] Time to get all of the movies from the database for this one call = 26.142038 milliseconds
[i1] Current Average Time to get all of the movies from the database = 31.061816599999997 milliseconds
[i1] Time to get all of the movies from the database for this one call = 28.490124 milliseconds
[i1] Current Average Time to get all of the movies from the database = 30.633201166666666 milliseconds
[i1] Time to get all of the movies from the database for this one call = 9.940943 milliseconds
[i1] Current Average Time to get all of the movies from the database = 27.677164285714287 milliseconds
[i1] Current Average Time to get all of the movies from the database = 37.88377466666667 milliseconds
[i2] Time to get all of the movies from the database for this one call = 326.420717 milliseconds
[i2] Current Average Time to get all of the movies from the database = 326.420717 milliseconds
[i2] Time to get all of the movies from the database for this one call = 7.147516 milliseconds
[i2] Current Average Time to get all of the movies from the database = 166.7841165 milliseconds
[i2] Time to get all of the movies from the database for this one call = 5.458838 milliseconds
[i2] Current Average Time to get all of the movies from the database = 113.00902366666668 milliseconds
[i2] Time to get all of the movies from the database for this one call = 5.768917 milliseconds
[i2] Current Average Time to get all of the movies from the database = 86.198997 milliseconds
[i2] Time to get all of the movies from the database for this one call = 7.379094 milliseconds
[i2] Current Average Time to get all of the movies from the database = 70.43501640000001 milliseconds
Notice a few things about the power of this technique:
1. You can run the script from any computer. 2. The overhead of processing the data can be done on a different machine from the
server where the app is deployed. 3. You can do anything at all with the data – which is flowing directly from the app. 4. It will simultaneously listen to every instance in a cluster and can easily identify
which instance the data is coming from. This can be very handy when trouble-shooting problems with load balancing the same app running on multiple instances.
5. You can easily run the script against any one specific instance or DAS itself.
27
6. When you exit the run-script command, the overhead goes away.
6.2 Automatic Monitoring Data
The Web Container has many Probes installed. These are automatically fired as you use your application. To get a taste of the power of Automatic Monitoring Data, run these commands: 1. The Monitoring data collection is turned off by default. We need to enable it for the
web-container by running this command (highlighted in bold): C:\javaone2011\glassfish3>.\bin\asadmin enable-monitoring --target c1 --
modules web-container=HIGH
Command enable-monitoring executed successfully.
2. Access the application URL in a browser. 3. Take a look at the number of times the application has run in each instance by running
this command (use the quotes because of the embedded space): C:\javaone2011\glassfish3>.\bin\asadmin get -m "c1.applications.19120-
app.server.Faces Servlet.requestcount-count"
4. Repeat from step 2 Here is a typical output. Notice that you can easily see how the load is being balanced.
at com.sun.enterprise.mgmt.ClusterManager.<init>(ClusterManager.java:140)
... 27 more
This error occurs if the IP address of the current machine cannot be determined correctly. This typically occurs if the machine is configured to use a wireless network. In such a case you may have to specify a system property for each instance named “GMS-BIND-INTERFACE-ADDRESS-<clustername>” to the IP address of the machine where the instance is running. In our case, <clustername> is “c1” and all the instances are running on the localhost. So we’ll need to set the property “GMS-BIND-INTERFACE-ADDRESS-c1” to the IP address of the local machine. This can be done in web-based Admin Console as:
1. Click on the clustername “c1” 2. Click on “Instances” tab 3. Click on the instance name “i1” 4. Click on “Properties” tab 5. Click on “Add Property” button 6. Specify the new “Instance
Variable Name” as “GMS-BIND-INTERFACE-ADDRESS-c1” and the “Override Value” to IP address of the current machine.
7. Click on “Save”. The updated output will look like as shown.
8. Repeat steps 3-8 for each instance in the cluster.
30
7.5 Deployment gives “Command succeeded with Warning” The application deployment gives the following warning message:
This error may occur if you try to re-deploy the application. This error can be ignored as the application deployment tries to create a SEQUENCE table for automatic generation of the primary keys even though it may exist.
7.6 Session data not preserved
This error occurs if you try to access the application on different instances (i1 and i2 in
our case) without a front-end load balancer and using different host names. Make sure to use the same host name to access the application on different instances. This issue does not occur when the multiple instances are front-ended with a load balancer as the same host name is passed to the underlying instances.
7.7 No monitoring data from the script Make sure you are accessing the app in a browser. You should see a few lines of output every time you do something with the app in a browser. If not, restart all the servers and try again. For example: asadmin stop-cluster c1
asadmin stop-domain
asadmin start-domain
asadmin start-cluster c1
31
8.0 Acknowledgements
This hands-on lab was gracious reviewed by the following GlassFish community member:
Markus Eisele Thank you very much for taking time to provide the valuable feedback.
9.0 References 9.1 GlassFish 9.1.1 Community Website: http://glassfish.org 9.1.2 Oracle GlassFish Server: http://oracle.com/goto/glassfish 9.1.4 GlassFish Forum: http://www.java.net/forums/glassfish/glassfish 9.2 NetBeans: http://netbeans.org 9.3 Clustering in GlassFish 3.1: http://glassfish.java.net/public/clustering31.html 9.4 GlassFish Load Balancer Setup and Configuration video: http://www.youtube.com/playlist?list=PLFC8CB788718C4EAE 9.5 Configuring Web Servers for HTTP Load Balancing in GlassFish: http://download.oracle.com/docs/cd/E18930_01/html/821-2426/gchvt.html