Using Filter as JEE LoadBalancer for Enterprise Application Integration(EAI) Traffic Web Protect Plus Overview The JEE LoadBalancer Filter is an pure JEE Web Component for high traffic environments. The LoadBalancer can easily deployed over loadbalancer.jar registration in Web-Inf/lib directory of the webapp und administrated in every webapp using web.xml registration and configuration. The Traffic is directed among an Semaphores mechanismen[from E.W.Dijkstra] to protect memory critical ressources and works without synchronisation. The LoadBalancer runs on all Java Web Containers without any modification. The LoadBalancer requires a Servlet Specification 2.3 or later. The LoadBalancer supports HTTP and JMX Monitoring and JMX Runtime Customizing of LoadBalancer Parameters. Historical Profiling is supported via file logging using the java.util.logging facility. 1
TOC: 1 Configuration 2 2 Monitoring 5 2.1 HTTP 5 2.2 JMX 6 2.3 File Logging 8 3 Impressum 9 1 Configuration Request processing Strategies are implemented and can be customized by the Thread- Blocking-Time parameter. If Requestpool (Max-Thread-Count) is empty there are 2 ways for Handling the request: a) Thread-Blocking-Time == 0 => the request breaks up, without processing! The Return Message is +++ InFlow: Too many active sessions,nonblocking,notdelivered +++ b) Thread-Blocking-Time!= 0 => the RequestThread is waiting (Thread_Blocking_Time) until the Requestpool has one free ressource again. The log Message while waiting is: +++ InFlow: Too many active sessions,waiting Thread_Blocking_Time +++" For every memory critical Ressource a LoadBalancer must be registered in the webapp deployment descriptor (web.xml file) as a filter, mapped to the same requests (based on url- 2
pattern /) like the protected Ressource. The LoadBalancer reads its rules from his filter configuration. The following example explains how to protect the Axis2 Version WebService: <!-- LoadBalancer Filter Section Definition & Configuration--> <filter> <filter-name>version_balancer</filter-name> <filter-class>merten.thomas.loadbalancer</filter-class> <init-param> <param-name>http_monitoring</param-name> <param-value>true</param-value> </init-param> <init-param> <param-name>jmx_monitoring</param-name> <param-value>true</param-value> </init-param> <init-param> <param-name>log_monitoring</param-name> <param-value>true</param-value> </init-param> <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> <param-value>100</param-value> 3
</init-param> <init-param> <param-name>log-directory</param-name> <param-value>/export/home/tomcat7/logs/</param-value> </init-param> </filter> <filter-mapping> <filter-name>version_balancer</filter-name> <url-pattern>/services/version/</url-pattern> </filter-mapping> Max-Thread-Count: RequestPoolSize, Max Count of paralle (Web-)Service Request Thread-Blocking-Time: -Time in ms the current Request-Thread has to wait - until Reqest retries to access the protected Ressource again(if Request PoolSize is 0). -if Thread-Blocking-Time =0 ms and Request PoolSize is 0 =>the Requests are not delivered, the following Response is sended +++ LoadBalancer InFlow: Too many active sessions;nonblockingmode +++ Log-Directory: java.util.logging Facility FileHandler Directory, Syntax Example for FileHandler: Log-Directory + version_balancer + currenttimemillis +.log [WebServer log: On Server startup the current LoadBalancer Configuration is logged to Standart Output -> /export/home/tomcat7/logs/catalina.out] +++ init LoadBalancer:version_balancer ist aktiv+++ +++ init LoadBalancer:version_balancer, Log- Directory:/export/home/tomcat7/logs/version_balancer1317651659827.log +++ init LoadBalancer:version_balancer, Log- Directory:/export/home/tomcat7/logs/version_balancer_profile1317651659828.log 4
+++ init LoadBalancer:version_balancer, JMX-Registry:merten.thomas:type=version_balancer +++ init LoadBalancer:version_balancer, LOG_MONITORING:true +++ init LoadBalancer:version_balancer, JMX_MONITORING:true +++ init LoadBalancer:version_balancer,Max-Thread-Count:10 +++ init LoadBalancer:version_balancer, Thread-Blocking-Time:100 +++ init LoadBalancer:version_balancer, HTTP_MONITORING:true +++ init LoadBalancer:version_balancer, ASYNC_MODE:false 2 Monitoring 2.1. HTTP To Monitor the LoadBalancers Work via HTTP you must configure LoadBalancer Servlet in web.xml: <!-- LoadBalancer Servlet Section: HTTP-Monitoring --> <servlet> <servlet-name>version_balancer_servlet</servlet-name> <servlet-class>merten.thomas.loadbalancer</servlet-class> </servlet> <servlet-mapping> <servlet-name>version_balancer_servlet</servlet-name> <url-pattern>/services/version/loadbalancerservlet</url-pattern> </servlet-mapping> Note: Be careful about the right matching servlet-mapping/url-pattern. That means: servlet-mapping/url-pattern = filter-mapping/url-pattern/loadbalancerservlet Now you can test the HHTP-Monitoring Functionality via the URL in Browser: http://localhost:8080/axis2/services/version/loadbalancerservlet?input=test with the following result: 5
LoadBalancer für WebApplication: C:\tomcat5.5\apache-tomcat-5.5.27\webapps\axis2\ LOG_MONITORING: true HTTP_MONITORING: true ASYNC_MODE: false JMX_MONITORING: true FilterName: version_balancer Current_Thread_Count: 9 Max_Thread_Count: 10 Thread_Blocking_Timet: 100 WAITING_Thread_Count: 0 Request_TimeConsumption: 43 Test für Parameter("input"): test 2.2. JMX The Sun website includes the list of options and how to configure JMX Remote on Java 5. http://java.sun.com/j2se/1.5.0/docs/guide/management/agent.html. For quick installation you find here a short installation guide: Add the following parameters to your WebServer startup 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" After you have set up the WebServer with the jmx configuration, you can connect with jconsole to the WebServer. Start JConsole from command line with the following arguments: jconsole localhost:9004 Maybe you have to change the reload interval for JConsole(-interval=1). Change the to MBeans JConsole Tab: you will see all loaded LoadBalancer. There is a Mapping between the LoadBalancers filter-name and the MBean ObjectName version_balancer <=> merten.thomas:type= version_balancer While Benchmark Lasttests you can see the current LoadBalancer state via MBean Property 6
Current_Thread_Count: JMX Runtime Customizing of Semaphoren Parameter to get Best Fit profiling for your enviroment : 7
Set the parameter values for Max_Thread_Count or the parameter value for Thread_Blocking_Time for change configuration. 2.3 FILE LOGGING Historical Profiling is implemented and can be activated via Log-Directory and LOG- MONITORING Parameter in web.xml: Log-Directory: java.util.logging.facility FileHandler Directory LOG-MONITORING:true/false ->enable/disable File Logging/Monitoring =>2 Files: /export/home/tomcat7/logs/version_balancer_profile1317651659827.log [For each Request 1 Entry] 03.10.2011 16:21:41,10,9,0,100,0 03.10.2011 16:22:02,10,9,0,100,43 /export/home/tomcat7/logs/version_balancer1317651659816.log [For each Request 2 Entries] 03.10.2011 16:21:41,+++ version_balancer In Anzahl Requests:9 +++ 03.10.2011 16:21:41,+++ version_balancer Out Anzahl Requests:10 +++ The following Properties are profiled for each Request: Timestamp, Max_Thread_Count, Current_Thread_Count, 8
WAITING_Thread_Count, Thread_Blocking_Time, RequestTimeConsumtion Best Practise: If you use more than one loadbalancer in one Web Application - you have to normalize the different logfiles based on time log Parameter. So you can compare the different profiled Keynumbers in nominated context. Please be careful and analyze the results on different focus. Use a Plotter for graphical Monitoring. The JMX-MONITORING profiled Data in JConsole Viewer are interval Data, so they are approximated over the JConsole interval. Use this for Runtime 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. With this strategies you can create an Best Fit configuration for your EAI WebApplication. Thanks Thomas Merten [Java 3D Realtime Graphics - Logo by Thomas Merten] 3 Impressum / Copyright Thomas Merten 2011. All Rights Reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the 9
documentation and/or other materials provided with the distribution. - Neither the name of Thomas Merten nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 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. ----------------------------------------------------------------------------- Copyright 2011 Thomas Merten. All Rights Reserved. Impressum: Thomas Merten Talstr. 27 04275 Leipzg Deutschland Tel +49 176 62501816 10
thomas.merten(at)web.de Weitere Texte und Fotos auf den Seiten (inklusive Quelltext und Software)sind urheberrechtlich geschützt. Das Kopieren dieser Dateien und ihre Veränderung sind daher ohne Genehmigung des Urhebers (Thomas Merten) nicht gestattet. Unberührt davon bleibt das "Kopieren" der Dateien auf den eigenen Rechner, um sich die WWW-Seiten auf einem Browser anzuschauen. Haftungsausschluss Die Thomas Merten übernimmt keine Verantwortung für die Inhalte, Fehlerfreiheit, Rechtmäßigkeit und Funktionsfähigkeit der auf angebotenen Software, auf die auf den Thomas Merten-Seiten verwiesen wird (Links,Downloads,Testprogramme,SourceCode). 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. / 11
12