Your SlideShare is downloading. ×
0
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       mo...
Premature optimisation                           Profile                           ... then optimiseMonday, 30 May 2011   ...
Where can things be slow?                      Business           DB                    Network   UI                      ...
Server-side tools     •   Spring Insight     •   Profiler Plugin     •   Hibernate logging     •   P6Spy     •   Hibernate...
UI tools     • Google Speed Tracer (Chrome only)          – Spring Insight integration     • ySlow (Firefox only - require...
Monday, 30 May 2011   7
Database performance     • Reduce the number of queries          – Use appropriate fetch mode          – Don’t fetch data ...
Fetch mode and indexing       class User {         String username         String passwordHash         Profile profile      ...
Database performance     • Caching          – Hibernate 2nd-level cache          – Distributed cache/data grid            ...
Hibernate 2nd-level cache      •hibernate {        DomainClass.get()            – Works reliably and well             cach...
Data grid                           GemFire                            GemFire    Grails                      DB     GemFi...
Business logic     • Caching          – Spring Cache Plugin for service methods     • Go asynchronous          – Ideal for...
Business logic     • Fall back to Java          – Limited applicability          – Numerically intensive tasks?     • Groo...
Business logic      class MyService {        @Typed(TypePolicy.MIXED)        void doSomething() {          expensiveMethod...
Network and UI     • Reduce view processing          – Spring Cache plugin for views     • Reduce number of requests (late...
Spring Cache with views                                Sitemesh                               Spring Cache                ...
Spring Cache in code    import grails.plugin.springcache.annotations.*    class PostController {      @Cacheable("myCache"...
Compressing page content    • Container-dependent          – Tomcat has connector setting          – For Jetty, add GzipFi...
Resources plugin     • Modularise static content     • Bundle files of the same type     • Caching Resources plugin       ...
Monday, 30 May 2011   21
Rich UIs     •   Browser does the work     •   Minimal traffic     •   GWT, Flex, etc.     •   Data transfer          – JS...
Summary     •   Profile before you optimise!     •   Several tools available for profiling     •   Several plugins availab...
Resources     • Spring Insight          – http://www.springsource.com/developer/tcserver     • Grails Plugins          – h...
Thank you!              Q&AMonday, 30 May 2011   25
Upcoming SlideShare
Loading in...5
×

GR8Conf 2011: Tuning Grails Applications by Peter Ledbrook

3,963

Published on

Published in: Technology
1 Comment
5 Likes
Statistics
Notes
No Downloads
Views
Total Views
3,963
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
109
Comments
1
Likes
5
Embeds 0
No embeds

No notes for slide

Transcript of "GR8Conf 2011: Tuning Grails Applications by Peter Ledbrook"

  1. 1. Tuning Grails apps Peter LedbrookMonday, 30 May 2011 1
  2. 2. 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
  3. 3. Premature optimisation Profile ... then optimiseMonday, 30 May 2011 3
  4. 4. Where can things be slow? Business DB Network UI LogicMonday, 30 May 2011 4
  5. 5. Server-side tools • Spring Insight • Profiler Plugin • Hibernate logging • P6Spy • Hibernate Statistics – App Info & Hibernate Stats Plugins 5Monday, 30 May 2011 5
  6. 6. UI tools • Google Speed Tracer (Chrome only) – Spring Insight integration • ySlow (Firefox only - requires Firebug) 6Monday, 30 May 2011 6
  7. 7. Monday, 30 May 2011 7
  8. 8. 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
  9. 9. 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
  10. 10. Database performance • Caching – Hibernate 2nd-level cache – Distributed cache/data grid • Terracotta • GemFire • Alternative data store! 10Monday, 30 May 2011 10
  11. 11. 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
  12. 12. Data grid GemFire GemFire Grails DB GemFire App 12Monday, 30 May 2011 12
  13. 13. 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
  14. 14. Business logic • Fall back to Java – Limited applicability – Numerically intensive tasks? • Groovy++? – One JAR – @Typed on class or method 14Monday, 30 May 2011 14
  15. 15. Business logic class MyService { @Typed(TypePolicy.MIXED) void doSomething() { expensiveMethod() } @Typed void expensiveMethod() { // Do something } } 15Monday, 30 May 2011 15
  16. 16. 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
  17. 17. Spring Cache with views Sitemesh Spring Cache Render GSP Cached ViewMonday, 30 May 2011 17
  18. 18. Spring Cache in code import grails.plugin.springcache.annotations.* class PostController { @Cacheable("myCache") def list = { ... } @CacheFlush("myCache") def addPost = { ... } }Monday, 30 May 2011 18
  19. 19. 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
  20. 20. 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
  21. 21. Monday, 30 May 2011 21
  22. 22. Rich UIs • Browser does the work • Minimal traffic • GWT, Flex, etc. • Data transfer – JSON – XML – GWT-RPCMonday, 30 May 2011 22
  23. 23. 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
  24. 24. 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
  25. 25. Thank you! Q&AMonday, 30 May 2011 25
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×