Dienstag, 11. September 2012

Axiom XMLHttpRequest

 

Axiom XMLHttpRequest - Enterprise XML Web Framework

by Thomas Merten

Figure 0. Architecture Axiom XMLHttpRequest - Enterprise XML Web Framework

"Solo ya pie...
Admirable peregrino,
todos siguen tu camino"
Manuel Machado

Axiom XMLHttpRequest Project on java.net

Axiom XMLHttpRequest is an Enterprise XML Web Framework enables XML Transformations in Java Server using Streaming API for XML (StAX) & Axis2 Databinding Framework(ADB). The Framework extends the client-side JavaScript DOM XMLHttpRequest with XMLHttpRequestSchema and high performance StAX XML Processing on server-side. Parsing XMLHttpRequest to org.apache.axis2.databinding.ADBBean and serialize org.apache.axis2.databinding.ADBBean to HttpServletResponse in ServletContainer while JavaScript Request processing is implemented. Based on supported SchemaCompiler Tool we generate ADBBean from XMLHttpRequestSchema. A Demo Web Application is included in the Framework - explains how to progress JavaScript-XMLHttpRequest in Java Server Page.

The Axiom XMLHttpRequest Enterprise XML Web Framework can be easily deployed over axiom-xmlhttprequest.jar registration in Web-Inf/lib directory of the Web Application. The Axiom XMLHttpRequest runs on all Java Web Containers without any modification and requires additional libraries from Apache ADB Project axiom_libs.

Enterprise XML Web Framework->Downloads

More Information about Axis2 Databinding Framework is on Apache Axis2 Website http://axis.apache.org/axis2/java/core/docs/adb/adb-howto.html .

Figure 1. Axiom XMLHTTPRequest Sequenz(UML)

Architecture Axiom XMLHttpRequest - Enterprise XML Web Framework

Axiom XMLHttpRequest - Demo Web Application

Demo Web Application is included in the Framework - show progress a JavaScript-XMLHttpRequest in Java Server Page. Assembled Demo Web Application for use in any Java Servlet WebContainer is located in Source Code Repository of Axiom XMLHttpRequest. Demo Web Application

Start URL for Demo: http://host:Port/WebContent/operation/addition.jsp



Figure 2. Axiom XMLHttpRequest - Demo Web Application

Architecture & Design - Demo Web Application

Browser=JavaScript Web Controls <=>XMLHttpRequest <=>XMLHttpRequestSchema<=>StAX-ADBBeans=Java Server

We divide in HTTP-GET and HTTP-POST Request:

  • HTTP-GET Request is used for Site Loading and Navigation.
  • HTTP-POST Request is used for Form Data Processing.

Here Axiom XMLHttpRequest Framework is active. Loosely coupled high interactivity client-side JavaScript Web Controls interact with high performance server-side StAX Objects based on XMLHttpRequestSchema communication.

XMLHttpRequest: XMLMessage & XMLSchema

<!-- XMLHTTPRequest-Communication-XMLMessage -->
<!-- based on client-side JavaScript:DOMRequest -->
<Addition>
 <Summand>27</Summand>
 <Summand>6</Summand>
 <Summe>33</Summe>
</Addition>
Code Snippet 1. XMLHTTPRequest-Communication-XMLMessage XMLHTTPRequest.xml

<!-- XMLHTTPRequest-Communication-XMLSchema -->
<!-- based on client-side JavaScript:DOMRequest -->
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema attributeFormDefault="unqualified"
 elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
 <xs:element name="Addition">
  <xs:complexType>
   <xs:sequence>
    <xs:element name="Summand" maxOccurs="unbounded"
     minOccurs="2">
     <xs:simpleType>
      <xs:restriction base="xs:string"/>
     </xs:simpleType>
    </xs:element>
    <xs:element type="xs:string" name="Summe" maxOccurs="1" minOccurs="0"/>
    <xs:element type="xs:string" name="Exception" maxOccurs="1" minOccurs="0"/>
    
   </xs:sequence>
  </xs:complexType>
 </xs:element>
</xs:schema>
Code Snippet 2. XMLHTTPRequest-Communication-XMLSchema XMLHTTPRequestSchema.xsd

JavaScript & Java ServerPages

<!-- Java Server Page JavaBean Definition -->
<jsp:useBean id="bean" scope="request" class="operation.Addition" />
<%
 bean.processRequest(request,response);
 //!!! getOutputStream() has already been called for this response
 if(request.getMethod()  == "POST") 
  return;
%>
<!-- Java Server Page HTML Formular -->
<!-- Request Definition Elements -->
<form name="addition" action="javascript:void">
Solve this math question and enter the solution with digits: 
<jsp:getProperty name="bean" property="summand_1"/>+<jsp:getProperty name="bean" property="summand_2"/> =
   <input type="hidden"  NAME="summand_1"  VALUE='<jsp:getProperty name="bean" property="summand_1"/>' />
   <input type="hidden"  NAME="summand_2"  VALUE='<jsp:getProperty name="bean" property="summand_2"/>' />
   <input  size="3"  NAME="summe" TYPE="text"  />
   <input  TYPE="button" VALUE="Validate Math Question[POST Request]" onclick="lookupAddition(document.addition)" />
</form>
Code Snippets 3.Java Server Page HTML Formular addition.jsp

<!-- 
JavaScript function: 
 1.)build DOM XML 
 2.)Serialize DOM -> XMLString
 3.)Send asynchron POST XMLHTTPRequest to JavaServer Page
 4.)Deserialize XMLHTTPResponseString -> DOM 
-->
function lookupAddition(element) {
 try {
  if (!element.working) {
   var http = element.http;
   var doc = getDomDocument("Addition");
   var item = doc.createElement("Summand");
   var text = doc.createTextNode(element.summand_1.value);
   item.appendChild(text);
   doc.childNodes.item(0).appendChild(item);
   var item2 = doc.createElement("Summand");
   var text2 = doc.createTextNode(element.summand_2.value);
          item2.appendChild(text2);
   doc.childNodes.item(0).appendChild(item2);
   var item3 = doc.createElement("Summe");
   var text3 = doc.createTextNode(element.summe.value);
   item3.appendChild(text3);
   doc.childNodes.item(0).appendChild(item3);
   var xmlString = serializeXML(doc);
            
   http.open("POST", encodeURI("addition.jsp"), true);
   http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   http.setRequestHeader("Content-length", xmlString.length);
   http.setRequestHeader("Connection", "close");
   http.onreadystatechange = function() {// Call a functionality when the state changes.
    if (http.readyState == 4 && http.status == 200) {
     try {
      doc = XML2DOM(http.responseText);
      if (doc.getElementsByTagName("Exception").length != 0) {
       alert("ERROR: "
         + doc.getElementsByTagName("Exception")[0].textContent);
       element.working = false;
      } else {
       var summe = doc.getElementsByTagName("Summe")[0];
       var summeServer = summe.textContent;

       if (element.summe.value != summe.textContent) {
        alert("ERROR: " + element.summand_1.value
          + " + " + element.summand_2.value
          + " is not " + element.summe.value
          + " !");
       } else {
        alert("OK: " + element.summand_1.value + " + "
          + element.summand_2.value + " is "
          + element.summe.value + " !");
        window.location.href = 'addition.jsp';
       }
      }
      element.working = false;
      return true;
     } catch (e) {
      alert(e.message);
      element.working = false;
     }
    }
   }
   http.send(xmlString);
   element.working = true;
   return false;
  } else {
   return false;
  }
 } catch (e) {
  alert(e.message);
  return false;
 }
}
Code Snippets 4. XMLHTTPRequest-JavaScript-JavaServer Page Communication xmlhttp.js


SchemaCompiler & Axiom Databinding Framework(ADB)


SchemaCompiler - How to

Axiom XMLHttpRequest Enterprise XML Web Framework enables ADBBean generation from XMLHttpRequestSchema. ADBBeans are used by StAX for Axiom Databinding Framework(ADB). So client-side JavaScript DOM XMLHttpRequest is progressed with high performance StAX XML Processing on Java Server server-side.
XML-Schema Compiler Source:  axiom.xml.httprequest.XSD2JavaADBBean.java
Based on supported SchemaCompiler command-lineTool we generate these ADBBeans with following console command:

java 
-Dorg.apache.adb.properties=/axiom/xml/httprequest/schema-compile.properties 
-cp /axiom-xmlhttprequest.jar;axiom_libs 
axiom.xml.httprequest.XSD2JavaADBBean 
XSD_FILE 
OUTPUT_FOLDER
CLASS_PACKAGE

Import required libraries and Objects:

3 Input Arguments:

  • XSD_FILE- Path to your XMLHttpRequestSchema File[derived from your XMLHttpRequest Message Pattern: Your Task]
  • OUTPUT_FOLDER- OUTPUT_FOLDER [Your source directory] -> ADBBean Package with your schema-compiled objects
  • CLASS_PACKAGE- Your ADBBean Package name

Example for Input Arguments:

  • "C:/XML/axiom-xmlhttprequest/DemoWebApplication/XMLHTTPRequest-XMLSchema/XMLHTTPRequestSchema.xsd"
  • "C:/XML/axiom-xmlhttprequest/DemoWebApplication/src"
  • "schema.adbbean"

java 
-Dorg.apache.adb.properties=/axiom/xml/httprequest/schema-compile.properties  
-cp ./axiom-api-1.2.12.jar;./axiom-dom-1.2.12.jar;./axiom-impl-1.2.12.jar;./axiom-xmlhttprequest.jar;./axis2-adb-1.5.6.jar;./axis2-adb-codegen-1.5.6.jar;./axis2-codegen-1.5.6.jar;./axis2-kernel-1.5.6.jar;./commons-logging-1.1.1.jar;./xmlbeans-2.3.0.jar;./XmlSchema-1.4.3.jar 
axiom.xml.httprequest.XSD2JavaADBBean 
"C:/XML/axiom-xmlhttprequest/DemoWebApplication/XMLHTTPRequest-XMLSchema/XMLHTTPRequestSchema.xsd" 
"C:/XML/axiom-xmlhttprequest/DemoWebApplication/src" 
"schema.adbbean"  


Figure 3. SchemaCompiler XSD2JavaADBBean generated ADDBeans based on XMLHttpRequestSchema

Axiom Databinding Framework(ADB) using in Java Server Pages Beans


The Framework extends the client-side JavaScript DOM XMLHttpRequest with high performance StAX XML Processing on server-side. Parsing XMLHttpRequest to org.apache.axis2.databinding.ADBBean and serialize org.apache.axis2.databinding.ADBBean to HttpServletResponse in JavaServer Page Bean while JavaScript Request processing is implemented.

axiom.xml.httprequest.ADBBean4XMLHttpRequest.java   is the most central Object.
Extend your Java Server Page Beans with this Class and use the following Methods for HTTP Post Processing:

  • org.apache.axis2.databinding.ADBBean xmlHttpRequest2ADBBean(HttpServletRequest request,String Factory) -> Parse XMLHttpRequest to your ADBBean using ADBBean.Factory
  • void ADBBean2xmlHttpResponse(org.apache.axis2.databinding.ADBBean bean,HttpServletResponse response) -> Serialize your ADBBean to HttpServletResponse

Import required libraries and Objects:

  • axiom-xmlhttprequest.jar - Axiom XMLHttpRequest - Enterprise XML Web Framework Package[axiom.xml.httprequest]
  • schema.adbbean - your ADBBean Package with your schema-compiled Objects
  • axiom_libs - additional axiom libraries from Apache Axis2 Project

Using Axiom XMLHttpRequest your JavaServer Bean should implement Axiom Databinding Framework(ADB) like this example:

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import axiom.xml.httprequest.ADBBean4XMLHttpRequest;
import schema.adbbean.Summand_type1;

public class Addition extends ADBBean4XMLHttpRequest {

 public void processRequest(HttpServletRequest request,  HttpServletResponse response) {
  // Progress Question
  if (request.getMethod() == "POST") {
   try {
    schema.adbbean.Addition addition = 
    (schema.adbbean.Addition) xmlHttpRequest2ADBBean(request,schema.adbbean.Addition.Factory.class.getName());
    try {
     Summand_type1[] summand = addition.getSummand();
     int summe = Integer.valueOf(addition.getSumme());
     summand_1 = Integer.valueOf(summand[0].getSummand_type0());
     summand_2 = Integer.valueOf(summand[1].getSummand_type0());
     if (summe != summand_1 + summand_2) {
      addition.setSumme(String.valueOf(summand_1 + summand_2));
              }
     
    } catch (NumberFormatException e) {
     if (addition != null) {
      addition.setException(e.getMessage());
     }
    }
    ADBBean2xmlHttpResponse(addition, response);
   } catch (Exception e) {
    e.printStackTrace();
   }
 }
Code Snippets 5. Axiom XMLHTTPRequest-JavaServer Page Implementation Addition.java

Pluggable StAX implementations & Jar Service Provider Interfaces

The Axiom XMLHTTPRequest Framework allows you to decide how to configure StAX. However, if you have multiple StAX implementations in your classpath (->jar service provider technologie), you may have to specifically set/override system properties in web.xml to point to the implementation you want. axiom.xml.httprequest.ADBBean4XMLHttpRequest Listener will initialize Axiom XMLHTTPRequest Framework with your local StAX-Factory Settings independent of your global StAX configuration.

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_3.xsd"
 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_3.xsd"
 version="2.3">
 ...
 <listener>
   <listener-class>
    axiom.xml.httprequest.ADBBean4XMLHttpRequest
   </listener-class>
 </listener>

 <!--Setup StAX implementations from your classpath libraries , in this case 
  we use JDK 1.6 Standard Implementation -->
 <context-param>
   <param-name>javax.xml.stream.XMLInputFactory</param-name>
   <param-value>com.sun.xml.internal.stream.XMLInputFactoryImpl</param-value>
 </context-param>
</web-app>
Code Snippets 6. Axiom XMLHTTPRequest-Web Application Context StAX-Parameter web.xml

Prerequisites

Axiom XMLHttpRequest requires:

About the Author


Figure 4. The Author

My professional activities currently concentrate on J2EE Profiling and Monitoring. I am also interested in EAI/EIM Software Systems Integration. Previously, I worked in the ICT industry as a Siebel Core Consultant. Presently I am working as a freelance consultant and software developer in Europe. I contribute to the open source community(java.net) with the Java EE LoadBalancer & Axiom XMLHttpRequest Projects.

Lizenz


Limited warranty: Axiom XMLHttpRequest Software and Documentation are "as is" without any warranty as to their performance, merchantability or fitness for any particular purpose. The licensee assumes the entire risk as to the quality and performance of the software. In no event shall Axiom XMLHttpRequest or anyone else who has been involved in the creation, development, production, or delivery of this software be liable for any direct, incidental or consequential damages, such as, but not limited to, loss of anticipated profits, benefits, use, or data resulting from the use of this software, or arising out of any breach of warranty. This includes, but is not limited to, interruption of service, loss of classroom time or loss of consulting profits from the use of these programs.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

License

Resources & References


  • Tomcat Copyright ©  1999-2011, The Apache Software Foundation
  • java.net Copyright ©  2011, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
  • Axiom XMLHttpRequest Project Copyright ©  2012 Thomas Merten. All rights reserved.(http://solutions.website.org)
  • Axis2 Databinding Framework Copyright ©  2004-2012 The Apache Software Foundation. All Rights Reserved.
  • Ignatian Exercises, EB Nr.22 ©  Ignacio de Loyola
  • Lukas 14,12
  • Genesis 32,26-27

Bottom Axiom XMLHttpRequest Project ©  2012 Thomas Merten.

Java EE LoadBalancing

 

Profiling & Calibration Java Enterprise - Performance Management

by Thomas Merten

"Ad majorem Dei gloriam."
Saint Ignatius of Loyola

Java EE LoadBalancer Project on java.net

The Java EE LoadBalancer Filter is a pure J2EE Web Component for high traffic environments. Java Server Performance depends on CPU & Memory allocation of Traffic. Tuning Performance is also a borderline Process in reference to stability. Java EE LoadBalancer addresses this with Monitoring and Run-time Customizing of key parameters (response time & throughput). Traffic is directed among a Semaphore mechanism[from E.W.Dijkstra] to protect memory critical resources. Fail-over strategies are implemented and customizable while calibration process. Via jconsole essential Visibility into Java Web Transactions is supported across your Web Application infrastructure. You can identify performance problems and balance your Java Web Server.

The LoadBalancer can be easily deployed over loadbalancer.jar registration in Web-Inf/lib directory of the Web Application and administrated in every Web Application using web.xml registration and configuration. The LoadBalancer runs on all Java Web Containers without any modification and requires a Servlet Specification 2.3 or later. The LoadBalancer supports HTTP and JMX Monitoring and JMX Run-time Customizing of LoadBalancer Parameters. Historical Profiling is supported via file logging using the java.util.logging facility. Using this loadbalancing practice is no hardware or software architecture changes required.


Figure 0. LoadBalancer Sequenz(UML)

Java EE LoadBalancer->Downloads
Java EE LoadBalancer->JavaDoc

Preparations for Profiling Java Enterprise using Java EE LoadBalancer Project


We use Apache Tomcat Servlet/JSP container running with SUN JDK 1.5. EAI Performance depends on CPU, Memory & Heap consumption of Traffic(volume of requests). Performance Measuring is based on response time and throughput. Tuning Performance is also a borderline Process in reference to stability. Java EE LoadBalancer addresses this with Monitoring and Run-time Customizing of Key Numbers(CurrentEndpointAllocatedBytes, EndpointTotalAllocatedBytes, EndPointTotalCpuTime, EndPointTotalUserTime, EndPointTotalSystemTime, EndPointCountRelative, MAX_THREAD_COUNT, Current_Thread_Pool_Count, Waiting_Thread_Count, THREAD_BLOCKING_TIME and CurrentEndpointCpuTime).

Based on a Bad Fit Start Setup we show the steps to get the Best Fit settings. The resulting settings are independent of the HTTP Scope(stateful Session, stateless Request).

Setup the Java Virtual Machine on Tomcat Web Container

Apache Tomcat is an open source software implementation of the Java Servlet and JavaServer Pages technologies. An Introduction to Apache Tomcat is on Apache Tomcat Website: http://tomcat.apache.org

Set the following parameters for JVM Garbage Collection to minimize count of GC's in your Tomcat start-up script:

  • New Generation: -XX:NewSize=512m -XX:MaxNewSize=512m
  • Old Generation (tenured): -Xms1024m

The Apache Tomcat and Sun website include the list of options and how to configure JMX Remote on Java:

The following is a quick configuration guide for Java 5:

Enable JMX Profiling and Monitoring on Tomcat. Add the following parameters to your Tomcat start-up script:

Set JVM_OPTS=

"-Dcom.sun.management.jmxremote

-Dcom.sun.management.jmxremote.port=9004

-Dcom.sun.management.jmxremote.ssl=false

-Dcom.sun.management.jmxremote.authenticate=false"

Be careful: This is only for Test Environment. In Real-life Application use authentication (with/without ssl).

Setup Apache Axis2

Axis2 Documentation http://axis.apache.org/axis2/java/core/docs/installationguide.html#servlet_container provides information on Axis2 distribution packages, system prerequisites and setting up environment variables and tools followed by detailed instructions on installation methods. Install Apache Axis2 Web Service Framework [WAR (Web Archive) Distribution] from http://axis.apache.org/axis2/java/core/download.cgi in a Tomcat Servlet Container. We use Axis2 as Reference Web Application to show how the Profiling Process works.

Setup Java EE LoadBalancer JMX Plug-in

Install Java EE LoadBalancer (loadbalancer.jar) from http://j2ee-loadbalancer.java.net/downloads in Web-Inf/lib directory of the Axis2 Web Application[- we use Axis2 as Reference Web Application-]. Register Java EE LoadBalancer in Axis2 Web Application using Web-Inf/web.xml registration. A Sample configuration File(web.xml) for activation Java EE Loadbalancer with Axis 2 Web Application is here http://j2ee-loadbalancer.java.net/downloads .

Later we will use Java EE LoadBalancer for Axis2 Web Application Run-time Customizing & Calibration while Load Test.

Setup SoapUI

Install SoapUI Web Service Testing Tool from http://www.soapui.org. We need this Software for Functional Testing of the Axis2 pre-deployed Version Web Service. Setup a SoapUI Benchmark Project for the predeployed Version Service on Tomcat (http://localhost:8080/axis2/services/Version?wsdl).

Profiling & Calibration Java Enterprise using Java EE LoadBalancer Project


When running Tomcat on unixes, the console output is usually redirected to the file named catalina.out. The name is configurable using an environment variable. (See the Tomcat startup scripts). Whatever on startup is written from the Java EE LoadBlanacer to System.err/out will be caught into that file. ->Restart Apache Tomcat. Please check if the following Logging Mechanisms are active:

  • WebServer log: On Server start up the current LoadBalancer Configuration is logged to Standard Output -> /export/home/tomcat7/logs/catalina.out with the following entries:

    +++ LoadBalancer:version_balancer ist aktiv+++

    +++ LoadBalancer:version_balancer, Configuration:/export/home/tomcat7/webapps/axis2/WEB-INF/web.xml

    +++ LoadBalancer:version_balancer, Context:/axis2

    +++ LoadBalancer:version_balancer, URL_MAPPING:/services/Version.VersionHttpSoap12Endpoint/

    +++ LoadBalancer:version_balancer, LOG_DIRECTORY:/export/home/tomcat7/logs/version_balancer_profile1337085046890.log

    +++ LoadBalancer:version_balancer, LOG_MONITORING:true

    +++ LoadBalancer:version_balancer, MAX_THREAD_COUNT:10

    +++ LoadBalancer:version_balancer, THREAD_BLOCKING_TIME:100

    +++ LoadBalancer:version_balancer, HTTP_MONITORING:true

    +++ LoadBalancer:version_balancer, JMX_MONITORING:true

    +++ LoadBalancer:version_balancer, Endpoint CpuTime Measuring is supported.

    +++ LoadBalancer:version_balancer, Endpoint Heap Memory Allocation Measuring is supported.

    +++ LoadBalancer:version_balancer, JMX_INTERVAL:100

    +++ LoadBalancer:version_balancer, JMX-Registry:merten.thomas:type=version_balancer

  • If LOG_MONITORING is enabled -> LoadBalancer Log File must exists in LOG_DIRECTORY: /export/home/tomcat7/logs/version_balancer_profileXXXXXXXXXXXXX.log

Monitoring & Run-time Customizing using JConsole

JMX Profiling, Monitoring & Run-time Customizing is implemented. So essential Visibility into Java Web Transactions is supported across your Web Application infrastructure via jconsole. You can identify performance problems and balance your Java Web Server. Activate JMX_MONITORING in LoadBalancer Filter Section of Web Application configuration file(web.xml):

 <!-- LoadBalancer Filter Section Definition & Configuration-->
 <filter>
  <filter-name>version_balancer</filter-name>
  ...
  <init-param>
            <param-name>JMX_MONITORING</param-name>
            <param-value>true</param-value>
  <init-param>
  <init-param>
            <param-name>JMX_INTERVAL</param-name>
            <!-- Time in ms-->
            <param-value>100</param-value>
  <init-param>
  ...
 </filter>
Code-Snippet 1. Filter Section of Web Application configuration file(web.xml)

Parameter JMX_INTERVAL in milliseconds - in reference to your JConsole update interval(=seconds) .

After you have set up the Apache Tomcat with the jmx configuration, you can connect with JConsole to the WebServer. JConsole is a JMX-compliant GUI tool that connects to the running Tomcat ServletContainer JVM . An Introduction on JConsole is on Oracle Website: http://java.sun.com/developer/technicalArticles/J2SE/jconsole.html To start JConsole, run from command line with the following arguments:

JDK_HOME/bin/jconsole localhost:9004

Maybe you have to change the reload interval for JConsole(-interval=1).

Select MBeans JConsole Tab: You will see the loaded LoadBalancer.

There is a Mapping between the LoadBalancers filter-name and the MBean ObjectName:

filter-name <=> merten.thomas:type=filter-name

In this Case: version_balancer <=> merten.thomas:type= version_balancer

LoadBalancer configuration in Axis2 Web Application (web.xml):

 <!-- LoadBalancer Filter Section Definition & Configuration-->
 <filter>
  <filter-name>version_balancer</filter-name>
  ...
 </filter>
Code-Snippet 2. LoadBalancer Web Application configuration file(web.xml)

Figure 1. Mapping between the LoadBalancers filter-name and the MBean ObjectName

While Benchmark Load Tests you can see the current LoadBalancer state via MBean Property (in Chart mode): Current_Thread_Pool_Count

Figure 2. LoadBalancer state via MBean Property: Current_Thread_Pool_Count

Figure 3. LoadBalancer state via MBean Property: CurrentThreadCpuTime_ns

Figure 4. LoadBalancer state via MBean Property: Total CPU, System and User Time for balanced EndPoint

Figure 5. LoadBalancer state via MBean Property: Heap Memory Allocation & Total Heap Memory Allocation for balanced EndPoint

Where the Values come from?

In Axis2 Web Application Configuration (web.xml) the LoadBalancer is configured as a filter. LoadBalancer Filter url-pattern is mapped to Axis Version Service url-pattern. Therefore the LoadBalancer gets his Traffic Request Information and send the result to the associated JMX Beans.

<!-- LoadBalancer Filter Section Definition & Configuration-->
<filter>
 <filter-name>version_balancer</filter-name>
  ...
</filter>

<filter-mapping>
 <filter-name>version_balancer</filter-name>
 <url-pattern>/services/Version.VersionHttpSoap12Endpoint/</url-pattern>
</filter-mapping>
Code-Snippet 3. LoadBalancer Web Application configuration file(web.xml)

Note: For every memory critical Resource a LoadBalancer must be registered in the Web Application deployment descriptor (web.xml file) as a filter, mapped to the same requests (based on url-pattern /*) like the protected Resource. The LoadBalancer reads his policies from his filter configuration.

Soap Endpoint for Axis2 Version Service Interface[VersionSoap12Binding] is

http://localhost:8080/axis2/services/Version.VersionHttpSoap12Endpoint/

-> /services/Version.VersionHttpSoap12Endpoint/

Run-time Customizing of LoadBalancer Parameters - EAI Calibration Process

JMX Run-time Customizing of Semaphores Parameter to get the Best Fit profiling for your environment is supported. Set the parameter values for MAX_THREAD_COUNT and THREAD_BLOCKING_TIME to change configuration and Run-time Behavior in real-time to find Best Fit Settings for EAI Endpoint and System.

Monitor system changes to your new Attribute settings (in Attribute Chart mode):

  • CurrentEndpointAllocatedBytes:[Information Readonly]

    CurrentEndpointAllocatedBytes returns an approximation of the total amount of memory, in bytes, allocated in heap memory for the last current Endpoint thread(while current jconsole jmx interval). Requires Java SE 1.7 .

  • EndpointTotalAllocatedBytes:[Information Readonly]

    EndpointTotalAllocatedBytes returns an approximation of the total amount of memory, in bytes, allocated in heap memory for all Endpoint Threads(while current jconsole jmx interval). Requires Java SE 1.7 .

  • EndPointTotalCpuTime:[Information Readonly]

    EndPointTotalCpuTime is the total CPU time over all Endpoint threads(while current jconsole jmx interval) have executed in user mode plus system mode in nanoseconds. CPU time(all Endpoint threads) = user time(all Endpoint threads) + system time(all Endpoint threads)

  • EndPointTotalUserTime:[Information Readonly]

    EndPointTotalUserTime is the total CPU time over all Endpoint threads(while current jconsole jmx interval) have executed in user mode(running your application's own code) in nanoseconds.

  • EndPointTotalSystemTime:[Information Readonly]

    EndPointTotalSystemTime is the total CPU time over all Endpoint threads(while current jconsole jmx interval) have executed in system mode(running OS code on behalf of your application (such as for I/O)) in nanoseconds. user time(all Endpoint threads) = CPU time(all Endpoint threads) - user time(all Endpoint threads)

  • EndPointCountRelative:[Information Readonly]

    Amount of all Endpoint threads in relation to all JVM threads.

  • CurrentEndPointCpuTime_ns: [Information Readonly]

    CurrentEndPointCpuTime is the amount of time that the last current Endpoint thread(while current jconsole jmx interval) has executed in user mode plus system mode in nanoseconds.Total time spent using a CPU for your application. CPU time = user time + system time

  • Waiting_Thread_Count:[Information Readonly]

    Amount of all Endpoint threads waiting(THREAD_BLOCKING_TIME) until the Request-pool has new free thread resources

  • Current_Thread_Pool_Count:[Information Readonly]

    Amount free resources. Running Endpoint Threads = MAX_THREAD_COUNT-Current_Thread_Pool_Count

Figure 3. JMX Run-time Customizing of via MBean Attributes: MAX_THREAD_COUNT & THREAD_BLOCKING_TIME

Hint: Analyze and compare CPU, Heap and Thread activity with & without(!!!) Server activity.

JConsole interval, Time Measuring and (lack of) nanosecond accuracy

Profiled Data in JConsole Viewer are interval Data, so they are approximated over the JConsole interval(min: -interval=1)

The CPU and user time methods on ThreadMXBean report times measured in nanoseconds. That sounds really accurate, but the Java documentation notes:

"The returned value is of nanoseconds precision but not necessarily nanoseconds accuracy."

Nanosecond timing won't be exact due to hardware limitations and overhead in the OS and JVM. The accuracy available may not be documented and may vary between OS and JVM releases. (see David R. Nadeau, Ph.D. )

Java EE Loadbalancer Fail-over Strategies

Fail-over strategies are implemented. Activate LoadBalancers fail-over strategies via configuration in LoadBalancer Filter section of Web Application configuration file(web.xml):

<!-- LoadBalancer Filter Section Definition & Configuration-->
<filter>
            <filter-name>version_balancer</filter-name>
             ...
             <init-param>
                     <param-name>MAX_THREAD_COUNT</param-name>
                     <param-value>10</param-value>
             </init-param>                       
             <init-param>
                     <param-name>THREAD_BLOCKING_TIME</param-name>
                     <!-- Time in ms-->
                     <param-value>100</param-value>
             </init-param>
             ...
</filter>
Code-Snippet 4. LoadBalancer Web Application configuration file(web.xml)

Request processing Strategies are customizable by the THREAD_BLOCKING_TIME and MAX_THREAD_COUNT parameter.

If Request-pool size (customized by MAX_THREAD_COUNT) is empty there are 2 ways to Handling a new incoming request based on THREAD_BLOCKING_TIME parameter.

  • THREAD_BLOCKING_TIME == 0 => The request breaks up, without processing! The HTTP Return and log Message(->Standard out)is: "[FilterName] InFlow: Too many active sessions,NonBlocking,NotDelivered +++"
  • THREAD_BLOCKING_TIME != 0 => The request is waiting until the Request-pool has new free resources. The log Message(->Standard out) while waiting is: "+++[FilterName] InFlow: Too many active sessions, [Thread.currentThread().getName()] Waiting: [Waiting_Thread_Count]+++"

Use the log Information to balance your Server. Normalize the process-, system- and IO-Data. Change JVM GC Heap Settings and Java EE LoadBalancer parameter MAX_THREAD_COUNT and THREAD_BLOCKING_TIME to get better response time and throughput or stability.

Analyze Logging Information

Historical Profiling is implemented. Activate Log connector in LoadBalancer Filter Section of Web Application configuration file(web.xml):

<!-- LoadBalancer Filter Section Definition & Configuration-->
<filter>
         <filter-name>version_balancer</filter-name>
         ...
         <init-param>
                 <param-name>LOG_MONITORING</param-name>
                 <param-value>true</param-value>
         </init-param>
         <init-param>
                 <param-name>LOG_DIRECTORY</param-name>
                 <param-value>/export/home/tomcat7/logs/</param-value>
         </init-param>
         ...
</filter>
Code-Snippet 5. LoadBalancer Web Application configuration file(web.xml)

  • LOG_DIRECTORY: java.util.logging.Facility File Handler Directory
  • LOG_MONITORING: true/false ->enable/disable File Logging/Monitoring

=>File: /export/home/tomcat7/logs/version_balancer_profileXXXXXXXXXXXX.log

Figure 6. Live Graph Logfile Analytics

[For each Request 1 Entry]

10.09.2012 10:17:03,1347265023827,10,-14,100,118585439,2726000,603684920,57176314,16314304,546508606

The following Properties are profiled for each Request:

  • Timestamp
  • MAX_THREAD_COUNT,
  • currentThreadPoolCount
  • THREAD_BLOCKING_TIME
  • CurrentThreadCpuTime
  • CurrentThreadAllocatedBytes
  • TotalCpuTime
  • TotalSystemTime
  • TotalThreadAllocatedBytes
  • TotalUserTime

Hints:

If you use more than one Loadbalancer in the Web Application - you have to normalize the different log files based on Timestamp Parameter. So you can compare different profiled Key numbers in a nominated context. Please be careful and analyze the results on different focuses [process based, system environment based].

The JMX-MONITORING profiled Data in JConsole Viewer are interval Data, so they are approximated over the JConsole interval. Use this for Run-time calibration of your Server.

The FILE-LOGGING profiled Data are logged for each request, so they are more correct and should be used for extended analysis. Use Plotter Software(Live Graph) for graphical Monitoring.

Real-time Profiling via HTTP Monitoring - HTTPMonitoringServlet

HTTP Monitoring is implemented. Activate LoadBalancers HTTP Connector via configuration of LoadBalancerServlet in Web Application configuration file(web.xml):

<!-- LoadBalancer Servlet Section: HTTP-Monitoring -->
<servlet>
      <servlet-name>version_balancer_servlet</servlet-name>
       <servlet-class>merten.thomas.monitoring.http.HTTPMonitoringServlet</servlet-class>
      <init-param>
            <param-name>filter-name</param-name>
            <param-value>version_balancer</param-value>
         </init-param>
</servlet>
<servlet-mapping>
        <servlet-name>version_balancer_servlet</servlet-name>
        <url-pattern>/HTTPMonitoringServlet</url-pattern>
</servlet-mapping>
Code-Snippet 6. LoadBalancer Web Application configuration file(web.xml)

Note: Be careful about the right matching param-value for param-name:filter-name.

filter/filter-name = servlet/init-param/param-name[filter-name]/param-value

In this Case: <=>

servlet/init-param/param-name[filter-name]/param-value = version_balancer

That means: For each LoadBalancer one HTTPMonitoringServlet can be activated via web.xml configuration.

Activate HTTP_MONITORING in LoadBalancer Filter section of Web Application configuration file(web.xml):

 <!-- LoadBalancer Filter Section Definition &Configuration-->
 <filter>
  <filter-name>version_balancer</filter-name>
  ...
  <init-param>
           <param-name>HTTP_MONITORING</param-name>
          <param-value>true</param-value>
  <init-param>
  ...
 </filter>
Code-Snippet 7. LoadBalancer Web Application configuration file(web.xml)

Now you can test the HTTP-Monitoring Functionality via the URL in Web Browser.

Invoke http://localhost:8080/axis2/HTTPMonitoringServlet?input=test with the following result:

  • LoadBalancer für Web Application: /export/home/tomcat7/webapps/axis2/
  • ContextPath: /axis2
  • Filter URL_MAPPING(EAI Endpoint): /services/Version.VersionHttpSoap12Endpoint/
  • Filter EndPointURL: http://Host:Port/axis2/services/Version.VersionHttpSoap12Endpoint/
  • LOG_MONITORING: true
  • HTTP_MONITORING: true
  • JMX_MONITORING: true
  • FilterName: version_balancer
  • Current_Thread_Pool_Count: 10
  • MAX_THREAD_COUNT: 10
  • THREAD_BLOCKING_TIME(ms): 100
  • Waiting_Thread_Count: 0
  • CurrentThreadCpuTime(ns): 0
  • Test for Parameter("input"): test

Hint: Use HTTP Monitoring for real-time Monitoring in real world production environments - when JMX connect is impossible.

UNIX Monitoring Tools Support(ProcessLogger)


Profiling System Resources is important for comparability and relationship building. Logging UNIX Monitoring Tools like vmstat, iostat,... is supported via ProcessLogger WrapperServlet. Profiled Data are interval Data, so they are approximated over the time interval(min: 1 second).

Activate Unix System Tools Process Monitoring in Web Application configuration file(web.xml):

<!-- ProcessLogger Section  Start -->
<servlet>
               <servlet-name>VMSTAT_ProcessLogger</servlet-name>
               <display-name>VMSTAT_ProcessLogger</display-name>
               <servlet-class>merten.thomas.monitoring.log.ProcessLogger</servlet-class>
               <init-param>
                       <param-name>PROCESS_NAME</param-name>
                       <param-value>/usr/bin/vmstat 1</param-value>
               </init-param>
               <init-param>
                        <param-name>LOG_DIRECTORY</param-name>
                        <param-value>/export/home/tomcat7/logs/</param-value>
               </init-param>
               <load-on-startup>1</load-on-startup>
</servlet>
<!-- ProcessLogger Section  End -->
Code-Snippet 8. LoadBalancer Web Application configuration file(web.xml)


Round-trip Profiling

Figure 4. EAI Profiling the complete Round-trip

The following Relationships are comparable:

  • Endpoint(i) to Endpoint(k) based on Loadbalancer-log Data[Loadbalancer(i)-Loadbalancer(k)-log Normalization]
  • Endpoint(n) to Tomcat based on Loadbalancer-log and Tomcat Status Servlet-log Data[Loadbalancer(n)-GC-log Normalization]
  • Tomcat to OS based on Tomcat Status Servlet-log Data and VMSTAT-IOSTAT-log Data[GC-VMSTAT-IOSTAT-log Normalization]
  • Endpoint(n) to Tomcat to OS based on Normalized Data[Loadbalancer(n)-GC-Tomcat Status Servlet-VMSTAT-IOSTAT-log Normalization]

Monitoring Log Data using LiveGraph gives a complete picture about absolute and relative resource consumption.

With these strategies you can create a Best Fit configuration for your EAI Web Application. Set JVM GC Heap parameter in Tomcat start-up script and LoadBalancer parameter in Web Application configuration(web.xml)

Prerequisites

Java EE LoadBalancer requires:

  • Java Servlet Engine(Tomcat,...) with Servlet Specification 2.3 or later
  • Java SE 1.5
  • For Profiling & Runtime Customizing[Best Fit Calibration]: enabled JMX connection
  • Some Features like Endpoint Heap Memory Allocation Measuring requires Java SE 1.7

About the Author


Figure 5. The Author

My professional activities currently concentrate on J2EE Profiling and Monitoring. I am also interested in EAI/EIM Software Systems Integration. Previously, I worked in the ICT industry as a Siebel Core Consultant. Presently I am working as a freelance consultant and software developer in Europe. I contribute to the open source community(java.net) with the Java EE LoadBalancer & Axiom XMLHttpRequest Projects.

Lizenz

Java EE LoadBalancer is open source but not free.

  • Use in Test and Development Environment is for free - with the requirement that any copy acknowledges the original product and its developers.
  • For use in Production Environment get in touch with me(Thomas Merten)
  • License

Limited warranty: Java EE LoadBalancer Software and Documentation are "as is" without any warranty as to their performance, merchantability or fitness for any particular purpose. The licensee assumes the entire risk as to the quality and performance of the software. In no event shall Java EE LoadBalancer or anyone else who has been involved in the creation, development, production, or delivery of this software be liable for any direct, incidental or consequential damages, such as, but not limited to, loss of anticipated profits, benefits, use, or data resulting from the use of this software, or arising out of any breach of warranty. This includes, but is not limited to, interruption of service, loss of classroom time or loss of consulting profits from the use of these programs.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Resources & References


  • Tomcat Copyright ©  1999-2011, The Apache Software Foundation
  • java.net Copyright ©  2011, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
  • Java EE LoadBalancer Project Copyright ©  2011 Thomas Merten. All rights reserved.(http://solutions.website.org)
  • Axis2 Copyright ©  2004-2011 The Apache Software Foundation. All Rights Reserved.
  • JConsole, JDK, Java ©  2010, Oracle Corporation and/or its affiliates
  • LiveGraph This product includes software developed by the LiveGraph project and its contributors. (http://www.live-graph.org) Copyright © 2007 G. Paperin. All rights reserved.
  • SoapUI ©  2011 SmartBear Software. All rights reserved.
  • Article: How to get CPU, system, and user time for benchmarking (David R. Nadeau, Ph.D. )

Java EE LoadBalancer Project ©  2011 Thomas Merten.