GR8Conf 2011: Tuning Grails Applications by Peter Ledbrook
Upcoming SlideShare
Loading in...5
×
 

GR8Conf 2011: Tuning Grails Applications by Peter Ledbrook

on

  • 4,076 views

 

Statistics

Views

Total Views
4,076
Slideshare-icon Views on SlideShare
4,036
Embed Views
40

Actions

Likes
6
Downloads
101
Comments
1

4 Embeds 40

http://blog.ultrainno.com 35
http://2011.gr8conf.eu 3
http://universegroovygrails.blogspot.com 1
http://www.gennemtaenkt.dk 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel

11 of 1

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    GR8Conf 2011: Tuning Grails Applications by Peter Ledbrook GR8Conf 2011: Tuning Grails Applications by Peter Ledbrook Presentation Transcript

    • Tuning Grails apps Peter LedbrookMonday, 30 May 2011 1
    • Everyone wants to be Facebook • Few apps start with millions of hits a day • Scaling throws up many more issues than just the frameworkMonday, 30 May 2011 2
    • Premature optimisation Profile ... then optimiseMonday, 30 May 2011 3
    • Where can things be slow? Business DB Network UI LogicMonday, 30 May 2011 4
    • Server-side tools • Spring Insight • Profiler Plugin • Hibernate logging • P6Spy • Hibernate Statistics – App Info & Hibernate Stats Plugins 5Monday, 30 May 2011 5
    • UI tools • Google Speed Tracer (Chrome only) – Spring Insight integration • ySlow (Firefox only - requires Firebug) 6Monday, 30 May 2011 6
    • Monday, 30 May 2011 7
    • Database performance • Reduce the number of queries – Use appropriate fetch mode – Don’t fetch data you don’t need • Tune your queries – Add appropriate indexes – Don’t be afraid to change the model 8Monday, 30 May 2011 8
    • Fetch mode and indexing class User { String username String passwordHash Profile profile static hasMany = [ roles: Role ] static mapping = { username index: username_idx profile fetch: join roles lazy: false } }Monday, 30 May 2011 9
    • Database performance • Caching – Hibernate 2nd-level cache – Distributed cache/data grid • Terracotta • GemFire • Alternative data store! 10Monday, 30 May 2011 10
    • Hibernate 2nd-level cache •hibernate { DomainClass.get() – Works reliably and well cache.use_second_level_cache = true • Query cache cache.use_query_cache = true – Each query must be declared= cached cache.provider_class as – Changes to data clear the cache net.sf.ehcache.hibernate.EhCacheProvider } – Best for data that changes infrequentlyMonday, 30 May 2011 11
    • Data grid GemFire GemFire Grails DB GemFire App 12Monday, 30 May 2011 12
    • Business logic • Caching – Spring Cache Plugin for service methods • Go asynchronous – Ideal for long running tasks – Spring Events, Executor – Messaging: JMS, AMQP 13Monday, 30 May 2011 13
    • Business logic • Fall back to Java – Limited applicability – Numerically intensive tasks? • Groovy++? – One JAR – @Typed on class or method 14Monday, 30 May 2011 14
    • Business logic class MyService { @Typed(TypePolicy.MIXED) void doSomething() { expensiveMethod() } @Typed void expensiveMethod() { // Do something } } 15Monday, 30 May 2011 15
    • Network and UI • Reduce view processing – Spring Cache plugin for views • Reduce number of requests (latency) – Expires HTTP header – Bundle CSS & Javascript files – Image spriting • Reduce amount of data transferred to browser (bandwidth) – Minify Javascript – Compress data • Plugins – Performance UI, JAWR – Resources et al.Monday, 30 May 2011 16
    • Spring Cache with views Sitemesh Spring Cache Render GSP Cached ViewMonday, 30 May 2011 17
    • Spring Cache in code import grails.plugin.springcache.annotations.* class PostController { @Cacheable("myCache") def list = { ... } @CacheFlush("myCache") def addPost = { ... } }Monday, 30 May 2011 18
    • Compressing page content • Container-dependent – Tomcat has connector setting – For Jetty, add GzipFilter to your web.xml • Enable gzip compression in Tomcat plugin: eventConfigureTomcat = { tomcat -> tomcat.connector.setAttribute( "compression", "on") tomcat.connector.port = serverPort }Monday, 30 May 2011 19
    • Resources plugin • Modularise static content • Bundle files of the same type • Caching Resources plugin – Sets HTTP Expires header 1 year ahead – Gives static files a unique name • Zipped Resources plugin – Gzips static content – Can exclude files by extensionMonday, 30 May 2011 20
    • Monday, 30 May 2011 21
    • Rich UIs • Browser does the work • Minimal traffic • GWT, Flex, etc. • Data transfer – JSON – XML – GWT-RPCMonday, 30 May 2011 22
    • Summary • Profile before you optimise! • Several tools available for profiling • Several plugins available for improving performance • Many techniques apply to any web application • Law of diminishing returns – At some point, further performance improvements aren’t worth the required effort • Resources will be in Grails 1.4Monday, 30 May 2011 23
    • Resources • Spring Insight – http://www.springsource.com/developer/tcserver • Grails Plugins – http://grails.org/plugin/profiler – http://grails.org/plugin/springcache – http://grails.org/plugin/resourcesMonday, 30 May 2011 24
    • Thank you! Q&AMonday, 30 May 2011 25