Clustering a Grails Application for Scalability and Availability



Similar documents
Table of contents. Reverse-engineers a database to Grails domain classes.

WEBLOGIC ADMINISTRATION

Database Migration Plugin - Reference Documentation

STREAMEZZO RICH MEDIA SERVER

CHAPTER 1 - JAVA EE OVERVIEW FOR ADMINISTRATORS

JBoss AS Administration Console User Guide. by Shelly McGowan and Ian Springer

No.1 IT Online training institute from Hyderabad URL: sriramtechnologies.com

MagDiSoft Web Solutions Office No. 102, Bramha Majestic, NIBM Road Kondhwa, Pune Tel: /

Oracle WebLogic Server 11g Administration

Securing your Apache Tomcat installation. Tim Funk November 2009

Oracle EXAM - 1Z Oracle Weblogic Server 11g: System Administration I. Buy Full Product.

3 Techniques for Database Scalability with Hibernate. Geert Bevin - SpringOne 2009

.NET UI Load Balancing & Clustering

WSO2 Business Process Server Clustering Guide for 3.2.0

Technical White Paper - JBoss Security

JBS-102: Jboss Application Server Administration. Course Length: 4 days

Oracle Weblogic. Setup, Configuration, Tuning, and Considerations. Presented by: Michael Hogan Sr. Technical Consultant at Enkitec

OpenReports: Users Guide

Kony MobileFabric. Sync Windows Installation Manual - WebSphere. On-Premises. Release 6.5. Document Relevance and Accuracy

Intro to Load-Balancing Tomcat with httpd and mod_jk

Using Apache Derby in the real world

JAMF Software Server Installation and Configuration Guide for OS X. Version 9.2

Table of contents. Jasig CAS support for the Spring Security plugin.

Chapter 1 - Web Server Management and Cluster Topology

Project Management (PM) Cell

SpagoBI exo Tomcat Installation Manual

mod_cluster A new httpd-based load balancer Brian Stansberry JBoss, a division of Red Hat

Performance Optimization of Teaching Web Application based SSH Framework

Grails - Rapid Web Application Development for the Java Platform

IBM WebSphere Application Server V8.5 lab Basic Liberty profile administration using the job manager

WebLogic Server: Installation and Configuration

Using Tomcat with CA Clarity PPM

StreamServe Persuasion SP5 StreamStudio

Create WebLogic Cluster application Prerequisites From Application director import-export service... 2

Apache Tomcat Tips and Tricks from the Pros

JAMF Software Server Installation and Configuration Guide for OS X. Version 9.0

JAMF Software Server Installation and Configuration Guide for Linux. Version 9.0

ZeroTurnaround License Server User Manual 1.4.0

Enterprise Edition Scalability. ecommerce Framework Built to Scale Reading Time: 10 minutes

Brekeke SIP Server Version 3 Using a Third-Party Database Tutorial Brekeke Software, Inc.

Operations and Monitoring with Spring

1z0-102 Q&A. DEMO Version

This training is targeted at System Administrators and developers wanting to understand more about administering a WebLogic instance.

Apache Tomcat Clustering

Glassfish Architecture.

TIBCO Silver Fabric Continuity User s Guide

WhatsUp Gold v16.3 Installation and Configuration Guide

Xpert.ivy 4.2. Server Guide

Install BA Server with Your Own BA Repository

TIBCO ActiveMatrix BusinessWorks Process Monitor Server. Installation

Oracle Exam 1z0-599 Oracle WebLogic Server 12c Essentials Version: 6.4 [ Total Questions: 91 ]

TIBCO ActiveMatrix BusinessWorks SmartMapper Plug-in Release Notes

Clustering with Tomcat. Introduction. O'Reilly Network: Clustering with Tomcat. by Shyam Kumar Doddavula 07/17/2002

Oracle WebLogic Server

Oracle WebLogic Server 11g: Administration Essentials

Instant Chime for IBM Sametime For IBM Websphere and IBM DB2 Installation Guide

About Me. Software Architect with ShapeBlue Specialise in. 3 rd party integrations and features in CloudStack

Project Manager 1 Post == Experience years in Project Management in reputed company, Salary Rs.1,20,000/-

IceWarp to IceWarp Server Migration

Installation Guide for contineo

NGASI Universal APP Panel Administration and User Guide WebAppShowcase DBA NGASI

JAMF Software Server Installation and Configuration Guide for Linux. Version 9.2

Oracle Exam 1z0-102 Oracle Weblogic Server 11g: System Administration I Version: 9.0 [ Total Questions: 111 ]

WebLogic Server 11g Administration Handbook

LICENSE4J AUTO LICENSE GENERATION AND ACTIVATION SERVER USER GUIDE

Install guide for Websphere 7.0

Top Weblogic Tasks You can Automate Now

JAMF Software Server Installation and Configuration Guide for Windows. Version 9.3

ColdFusion 8. Performance Tuning, Multi-Instance Management and Clustering. Sven Ramuschkat MAX 2008 Milan

How To Use The Listerv Maestro With A Different Database On A Different System (Oracle) On A New Computer (Orora)

EISOO AnyBackup 5.1. Detailed Features

IUCLID 5 Guidance and Support

CA Workload Automation Agent for Databases

Working With Virtual Hosts on Pramati Server

OBIEE 11g Scaleout & Clustering

Setting Up B2B Data Exchange for High Availability in an Active/Active Configuration

<Insert Picture Here> Oracle Web Cache 11g Overview

Mastering Tomcat Development

1Z Oracle Weblogic Server 11g: System Administration I. Version: Demo. Page <<1/7>>

How Comcast Built An Open Source Content Delivery Network National Engineering & Technical Operations

tc Server Webinar Series Deployments

Apache Jakarta Tomcat

Kony MobileFabric. Sync Server Tomcat Installation Manual. On-Premises

NGASI Shared-Runtime Manager Administration and User Guide WebAppShowcase DBA NGASI

Informatica Corporation Proactive Monitoring for PowerCenter Operations Version 3.0 Release Notes May 2014

Lucid Key Server v2 Installation Documentation.

Trademarks: Yellowfin and the Yellowfin Logo are registered trademarks of Yellowfin International.

EMC Documentum Content Management Interoperability Services

Spectrum Technology Platform. Version 9.0. Spectrum Spatial Administration Guide

Spectrum Technology Platform Version Tutorial: Load Balancing Spectrum Spatial Services. Contents:

SAM Server Utility User s Guide

Apache Tomcat. Load-balancing and Clustering. Mark Thomas, 20 November Pivotal Software, Inc. All rights reserved.

Basic TCP/IP networking knowledge of client/server concepts Basic Linux commands and desktop navigation (if don't know we will cover it )

1.0 Hardware Requirements:

Oracle WebCenter Sites. Installing on Oracle WebLogic Application Server 11g Release 1 (11.1.1)

24x7 Scheduler Multi-platform Edition 5.2

TIBCO Spotfire Statistics Services Installation and Administration

How To Use The Jobscheduler On A Linux Box (Jid) On A Pcode (Jio) Or Macbook 2.2 On A Microsoft Powerbook 2 (For A Freebie

Tushar Joshi Turtle Networks Ltd

ITG Software Engineering

Transcription:

Clustering a Grails Application for Scalability and Availability Groovy & Grails exchange 9th December 2009 Burt Beckwith

My Background Java Developer for over 10 years Background in Spring, Hibernate, Spring Security Full-time Grails developer since February 2008, now an independent consultant Regular contributor on the Grails User mailing list Primary developer of Spring Security (Acegi) Grails plugin Created UI Performance, Datasources, Twitter, Spring MVC, and CodeNarc Grails plugins Technical Editor of Grails in Action http://burtbeckwith.com/blog/ http://twitter.com/burtbeckwith

Overview General strategies for scaling and availability Biased towards Tomcat/MySQL/Ehcache These are not the only options for scaling, more of an introduction and overview Not necessarily better performance, aim is to handle more load with the same response time per action (linear scale)

Goal: Handle being Slashdotted

What to Cluster Web sessions Replicated HTTP sessions in at least one other server instance allows failover after crash Hibernate 2 nd -level cache If you use a read-write cache you must update other servers' caches to avoid stale data Quartz Use the database to load-balance, as a mutex to avoid duplicate job execution, for failover Note: Terracotta is working on non-database clustered Quartz Database?

Tomcat Clustering Enable and configure clustering in server.xml For standard usage it's sufficient to uncomment the existing cluster configuration Change multicast port and/or address to avoid conflicts: <Membership classname='org.apache.catalina.tribes.membership.mcastservice' address='228.0.0.4' port='45564' frequency='500' droptime='3000'/>

Tomcat Cluster Directory Layout tomcat directory with bin and lib directories separate from shared to make upgrade easier shared directory with deployed war(s), shared logs, shared server.xml multiple instance_n directories with one cluster node containing nodespecific bin/setenv.sh and conf/catalina.properties, and logs, temp, and work directories

Create the Cluster All the scripts need the cluster root so it's best to set it as an environment variable: export CR=/usr/local/tomcatcluster On server 1 createcluster.sh $CR

Create the Cluster Then create nodes: createinstance.sh 1 1 $CR createinstance.sh 1 2 $CR

Create the Cluster Each node has bin/setenv.sh with memory, JMX params conf/catalina.properties ports, server and instance number logs, temp, and work directory

Create the Cluster Repeat for server 2, 3, etc. createcluster.sh $CR createinstance.sh 2 1 $CR createinstance.sh 2 2 $CR createcluster.sh $CR createinstance.sh 3 1 $CR createinstance.sh 3 2 $CR

Deployment Build as usual: grails clean && grails war Use the deploy script: deploy.sh../clustered-0.1.war $CR Deletes old war, copies and expands to $CR/shared/webapps/ROOT/ All nodes on a server share one war

Running On each server, for each node: run.sh start 1 $CR run.sh start 2 $CR Shutdown using run.sh stop 1 $CR run.sh stop 2 $CR Between runs, cleanup using cleanup.sh $CR for each node, deletes logs, temp files, work dir contents deletes shared logs

Web Cluster Load Balancing Ideally, use hardware load balancers Coyote Point F5 Cisco Can also use Apache HTTPD (JK/mod_proxy) Can also use a dedicated Tomcat instance using Balancer web app (not in 6.0?)

Quartz Running embedded in-memory instance per web server will run duplicate jobs A single instance is a point of failure Use JDBC support to store jobs in database, use database locking to prevent duplicates, load balance, support failover Need to create tables and do minor configuration

Quartz Configuration Fix quartzscheduler in resources.groovy, see GRAILSPLUGINS-1207 beans = { if (Environment.PRODUCTION == Environment.current) { quartzscheduler(schedulerfactorybean) { autostartup = false datasource = ref('datasource') transactionmanager = ref('transactionmanager') configlocation = 'classpath:quartz.properties' jobfactory = ref('quartzjobfactory') joblisteners = [ref("${sessionbinderjoblistener.name}")] globaljoblisteners = [ref("${exceptionprinterjoblistener.name}")] } } }

Quartz Configuration Also patch QuartzGrailsPlugin.groovy, see GRAILSPLUGINS-1420: if (scheduler.gettrigger(trigger.triggerattributes.name, trigger.triggerattributes.group)) { scheduler.reschedulejob(trigger.triggerattributes.name, trigger.triggerattributes.group, ctx.getbean("${key}trigger")) } else { scheduler.schedulejob(ctx.getbean("${key}trigger")) }

Quartz Configuration conf/quartzconfig.groovy: quartz { jdbcstore = true autostartup = true } environments { test { quartz { jdbcstore = false autostartup = false } } }

Quartz Configuration quartz.properties: org.quartz.scheduler.instancename clusterdemo_quartz org.quartz.scheduler.instanceid AUTO org.quartz.threadpool.class org.quartz.simpl.simplethreadpool org.quartz.threadpool.threadcount 5 org.quartz.threadpool.threadpriority 5 org.quartz.jobstore.misfirethreshold 60000 org.quartz.jobstore.class org.quartz.impl.jdbcjobstore.jobstoretx org.quartz.jobstore.driverdelegateclass org.quartz.impl.jdbcjobstore.stdjdbcdelegate org.quartz.jobstore.useproperties false org.quartz.jobstore.tableprefix QRTZ_ org.quartz.jobstore.isclustered true org.quartz.jobstore.clustercheckininterval 5000 org.quartz.plugin.shutdownhook.class org.quartz.plugins.management.shutdownhookplugin org.quartz.plugin.shutdownhook.cleanshutdown true

Quartz Configuration grails-app/conf/hibernate/hibernate.cfg.xml <hibernate-configuration> <session-factory> <mapping resource='quartz.mysql.innodb.hbm.xml'/> </session-factory> </hibernate-configuration>

Quartz Configuration Quartz.mysql.innodb.hbm.xml (see plugins/quartz- 0.4.1/src/templates/sql) <hibernate-mapping> <database-object> <create> CREATE TABLE QRTZ_PAUSED_TRIGGER_GRPS ( TRIGGER_GROUP VARCHAR(80) NOT NULL, PRIMARY KEY (TRIGGER_GROUP) ) ENGINE=InnoDB </create> <drop>drop TABLE IF EXISTS QRTZ_PAUSED_TRIGGER_GRPS</drop> <dialect-scope name='org.hibernate.dialect.mysql5innodbdialect' /> </database-object>...

Hibernate 2 nd -Level Cache DataSource.groovy: datasource { pooled = true driverclassname = 'com.mysql.jdbc.driver' url =... username =... password =... dialect = org.hibernate.dialect.mysql5innodbdialect } hibernate { cache.use_second_level_cache = true cache.use_query_cache = true cache.provider_class = 'org.hibernate.cache.ehcacheprovider' }

Mapping in Domain Classes class Book { static mapping = { cache true } } class Country { static mapping = { cache usage: 'read-only' } } class Author { static hasmany = [books:book] static mapping = { books cache: true } }

Query Cache Criteria queries: def criteria = DomainClass.createCriteria() def results = criteria.list { cacheable(true) } HQL queries: DomainClass.withSession { session -> return session.createquery( "select... from where...").setcacheable(true).list() } } In dynamic finders (new in 1.1) def person = Person.findByFirstName("Fred", [cache:true])

Hibernate query cache considered harmful? Most queries are not good candidates for caching; must be same query and same parameters Updates to domain classes will pessimistically flush all potentially affected cached results DomainClass.list() is a decent candidate if there aren't any (or many) updates and the total number isn't huge Great blog post by Alex Miller (of Terracotta) http://tech.puredanger.com/2009/07/10/hibern ate-query-cache/

Usage Notes The 1 st -level cache is the Hibernate Session Can significantly reduce database load by keeping instances and query results in memory "cache true" creates a read-write cache, best for readmostly objects since frequently-updated objects will result in excessive cache invalidation (and network traffic when distributed) "cache usage: 'read-only'" creates a read-only cache, best for lookup data (e.g. Countries, States, Zip Codes, Roles, etc.) that never change

Usage Notes DomainClass.get() always uses the 2nd-level cache By default nothing else always uses the cache but can be overridden Grails switched from Ehcache as default to OSCache but only because it handles dev mode restarts better switch back! Note: In Grails 1.2 Ehcache 1.7 is used which handles restarts well, so it's the default again Create ehcache.xml in root of classpath to customize; will use defaults from jar otherwise In dev mode you'll want to run standalone, but when deployed will be clustered, so there's a build step

ehcache.xml (Development) <ehcache> <diskstore path='java.io.tmpdir' /> <defaultcache maxelementsinmemory='10000' eternal='false' timetoidleseconds='120' timetoliveseconds='120' overflowtodisk='true' maxelementsondisk='10000000' diskpersistent='false' diskexpirythreadintervalseconds='120' memorystoreevictionpolicy='lru' /> <cache name='com.burtbeckwith.clusterdemo.role' maxelementsinmemory='1000' eternal='true' maxelementsondisk='0' /> <cache name='com.burtbeckwith.clusterdemo.user.authorities' maxelementsinmemory='10000' eternal='false' /> <cache name='org.hibernate.cache.standardquerycache' maxelementsinmemory='50' eternal='false' timetoliveseconds='120' maxelementsondisk='0' /> <cache name='org.hibernate.cache.updatetimestampscache' MaxElementsInMemory='5000' eternal='true' maxelementsondisk='0' /> </ehcache>

ehcache.xml (Deployed) <ehcache xmlns:xsi='http://www.w3.org/2001/xmlschema-instance' xsi:nonamespaceschemalocation='ehcache.xsd'> <diskstore path='java.io.tmpdir' /> <cachemanagerpeerproviderfactory class='net.sf.ehcache.distribution.rmicachemanagerpeerproviderfactory' properties='peerdiscovery=automatic,multicastgroupaddress=237.0.0.2, multicastgroupport=5557,timetolive=1' propertyseparator=',' /> <cachemanagerpeerlistenerfactory class='net.sf.ehcache.distribution.rmicachemanagerpeerlistenerfactory' /> <defaultcache maxelementsinmemory='10000' eternal='false' timetoidleseconds='120' timetoliveseconds='120' overflowtodisk='true' MaxElementsOnDisk='10000000' diskpersistent='false' diskexpirythreadintervalseconds='120' memorystoreevictionpolicy='lru'/>

ehcache.xml (Deployed) <cache name='com.burtbeckwith.clusterdemo.role' maxelementsinmemory='1000' eternal='true' maxelementsondisk='0'> <cacheeventlistenerfactory class='net.sf.ehcache.distribution.rmicachereplicatorfactory' properties='replicateasynchronously=false' /> </cache> <cache name='com.burtbeckwith.clusterdemo.user.authorities' maxelementsinmemory='10000' eternal='false'> <cacheeventlistenerfactory class='net.sf.ehcache.distribution.rmicachereplicatorfactory' properties='replicateasynchronously=false' /> </cache>

ehcache.xml (Deployed) <cache name='org.hibernate.cache.standardquerycache' maxelementsinmemory='50' eternal='false' timetoliveseconds='120' maxelementsondisk='0'> <cacheeventlistenerfactory class='net.sf.ehcache.distribution.rmicachereplicatorfactory' properties='replicateasynchronously=false' /> </cache> <cache name='org.hibernate.cache.updatetimestampscache' maxelementsinmemory='5000' eternal='true' maxelementsondisk='0'> <cacheeventlistenerfactory class='net.sf.ehcache.distribution.rmicachereplicatorfactory' properties='replicateasynchronously=false' /> </cache> </ehcache>

Sample App Uses Spring Security plugin (to demonstrate login failover and provide cacheable domain classes) Uses Quartz plugin MySQL database

Demo

General Configuration Steps Tomcat Run grails install-templates and add <distributable/> to src/templates/war/web.xml Configure server.xml Configure cluster elements Access log valve

General Configuration Steps Quartz QuartzConfig.groovy hibernate.cfg.xml and hbm file(s) for JDBC store quartz.properties Fix bugs

General Configuration Steps Hibernate 2nd-level cache Change cache.provider_class in DataSource.groovy to org.hibernate.cache.ehcacheprovider Make cached domain classes Serializable - remember that closures aren't serializable Configure domain class cache in mapping closure Configure queries for query cache where appropriate Create ehcache.xml in grails-app/conf or src/java, and a distributed version to be used in production (_Events.groovy)

General Configuration Steps Misc Configure grails.config.locations in Config.groovy for externalized configuration Configure log file logging using ServerAwareFileAppender

Database Oracle RAC $$$ MySQL Cluster not a general-purpose solution, joins are expensive, etc. C-JDBC, etc. com.mysql.jdbc.replicationdriver

MySQL ReplicationDriver Looks promising, included with standard MySQL JDBC driver Change JDBC URL to primary plus list of readonly replicated servers plus database name, e.g. jdbc:mysql://server1:3306,server2:3306, server3:3306/db Change driver class to com.mysql.jdbc.replicationdriver

MySQL ReplicationDriver Driver opens connection from primary and from random read-only and uses a connection proxy Defaults to read/write primary but switch to read-only by calling connection.setreadonly(true) Non-intrusive usage in Grails would require a filter that has controller action mappings to determine if read-only is safe

MySQL ReplicationDriver Read-only replication DB per web server

MySQL ReplicationDriver Shared read-only replication databases

Q&A