SlideShare una empresa de Scribd logo
1 de 25
Descargar para leer sin conexión
Tuning Grails apps


                        Peter Ledbrook




Monday, 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
       framework




Monday, 30 May 2011                   2
Premature optimisation

                           Profile
                           ... then optimise



Monday, 30 May 2011                            3
Where can things be slow?



                      Business
           DB                    Network   UI
                       Logic




Monday, 30 May 2011                             4
Server-side tools

     •   Spring Insight
     •   Profiler Plugin
     •   Hibernate logging
     •   P6Spy
     •   Hibernate Statistics
          – App Info & Hibernate Stats Plugins




                                                 5


Monday, 30 May 2011                                  5
UI tools

     • Google Speed Tracer (Chrome only)
          – Spring Insight integration
     • ySlow (Firefox only - requires Firebug)




                                                 6


Monday, 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




                                                  8


Monday, 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!




                                          10


Monday, 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 infrequently




Monday, 30 May 2011                                         11
Data grid




                           GemFire
                            GemFire    Grails
                      DB     GemFire
                                        App




                                                12


Monday, 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




                                                      13


Monday, 30 May 2011                                        13
Business logic

     • Fall back to Java
          – Limited applicability
          – Numerically intensive tasks?
     • Groovy++?
          – One JAR
          – @Typed on class or method




                                           14


Monday, 30 May 2011                             14
Business logic

      class MyService {
        @Typed(TypePolicy.MIXED)
        void doSomething() {
          expensiveMethod()
        }

            @Typed
            void expensiveMethod() {
              // Do something
            }
      }




                                       15


Monday, 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 View



Monday, 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 extension




Monday, 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-RPC




Monday, 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.4




Monday, 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/resources




Monday, 30 May 2011                                          24
Thank you!




              Q&A




Monday, 30 May 2011   25

Más contenido relacionado

La actualidad más candente

Salesforce Batch processing - Atlanta SFUG
Salesforce Batch processing - Atlanta SFUGSalesforce Batch processing - Atlanta SFUG
Salesforce Batch processing - Atlanta SFUG
vraopolisetti
 

La actualidad más candente (20)

StreamSQL Feature Store (Apache Pulsar Summit)
StreamSQL Feature Store (Apache Pulsar Summit)StreamSQL Feature Store (Apache Pulsar Summit)
StreamSQL Feature Store (Apache Pulsar Summit)
 
Nova states summit
Nova states summitNova states summit
Nova states summit
 
Provisioning and Capacity Planning Workshop (Dogpatch Labs, September 2015)
Provisioning and Capacity Planning Workshop (Dogpatch Labs, September 2015)Provisioning and Capacity Planning Workshop (Dogpatch Labs, September 2015)
Provisioning and Capacity Planning Workshop (Dogpatch Labs, September 2015)
 
Prometheus Is Good for Your Small Startup - ShuttleCloud Corp. - 2016
Prometheus Is Good for Your Small Startup - ShuttleCloud Corp. - 2016Prometheus Is Good for Your Small Startup - ShuttleCloud Corp. - 2016
Prometheus Is Good for Your Small Startup - ShuttleCloud Corp. - 2016
 
Illuminate - Performance Analystics driven by Machine Learning
Illuminate - Performance Analystics driven by Machine LearningIlluminate - Performance Analystics driven by Machine Learning
Illuminate - Performance Analystics driven by Machine Learning
 
Overhead Supercomputing 2011
Overhead Supercomputing 2011Overhead Supercomputing 2011
Overhead Supercomputing 2011
 
Salesforce Batch processing - Atlanta SFUG
Salesforce Batch processing - Atlanta SFUGSalesforce Batch processing - Atlanta SFUG
Salesforce Batch processing - Atlanta SFUG
 
Cluster schedulerの紹介
Cluster schedulerの紹介Cluster schedulerの紹介
Cluster schedulerの紹介
 
An Introduction to Prometheus
An Introduction to PrometheusAn Introduction to Prometheus
An Introduction to Prometheus
 
Application Performance Management
Application Performance ManagementApplication Performance Management
Application Performance Management
 
Data on its way to history, interrupted by analytics and silicon (@pavlobaron)
Data on its way to history, interrupted by analytics and silicon (@pavlobaron)Data on its way to history, interrupted by analytics and silicon (@pavlobaron)
Data on its way to history, interrupted by analytics and silicon (@pavlobaron)
 
Fixing Twitter Improving The Performance And Scalability Of The Worlds Most ...
Fixing Twitter  Improving The Performance And Scalability Of The Worlds Most ...Fixing Twitter  Improving The Performance And Scalability Of The Worlds Most ...
Fixing Twitter Improving The Performance And Scalability Of The Worlds Most ...
 
Building an Experimentation Platform in Clojure
Building an Experimentation Platform in ClojureBuilding an Experimentation Platform in Clojure
Building an Experimentation Platform in Clojure
 
Operating a High Velocity Large Organization with Spring Cloud Microservices
Operating a High Velocity Large Organization with Spring Cloud MicroservicesOperating a High Velocity Large Organization with Spring Cloud Microservices
Operating a High Velocity Large Organization with Spring Cloud Microservices
 
Microservices and Prometheus (Microservices NYC 2016)
Microservices and Prometheus (Microservices NYC 2016)Microservices and Prometheus (Microservices NYC 2016)
Microservices and Prometheus (Microservices NYC 2016)
 
Introduction to Prometheus and Cortex (WOUG)
Introduction to Prometheus and Cortex (WOUG)Introduction to Prometheus and Cortex (WOUG)
Introduction to Prometheus and Cortex (WOUG)
 
Ansible at FOSDEM (Ansible Dublin, 2016)
Ansible at FOSDEM (Ansible Dublin, 2016)Ansible at FOSDEM (Ansible Dublin, 2016)
Ansible at FOSDEM (Ansible Dublin, 2016)
 
Prometheus - Open Source Forum Japan
Prometheus  - Open Source Forum JapanPrometheus  - Open Source Forum Japan
Prometheus - Open Source Forum Japan
 
Prometheus with Grafana - AddWeb Solution
Prometheus with Grafana - AddWeb SolutionPrometheus with Grafana - AddWeb Solution
Prometheus with Grafana - AddWeb Solution
 
Functional reactive programming
Functional reactive programmingFunctional reactive programming
Functional reactive programming
 

Similar a GR8Conf 2011: Tuning Grails Applications by Peter Ledbrook

GR8Conf 2011: Grails Enterprise Integration by Peter Ledbrook
GR8Conf 2011: Grails Enterprise Integration by Peter LedbrookGR8Conf 2011: Grails Enterprise Integration by Peter Ledbrook
GR8Conf 2011: Grails Enterprise Integration by Peter Ledbrook
GR8Conf
 
O365Engage17 - How to Automate SharePoint Provisioning with PNP Framework
O365Engage17 - How to Automate SharePoint Provisioning with PNP FrameworkO365Engage17 - How to Automate SharePoint Provisioning with PNP Framework
O365Engage17 - How to Automate SharePoint Provisioning with PNP Framework
NCCOMMS
 
Implementing MongoDB at Shutterfly (Kenny Gorman)
Implementing MongoDB at Shutterfly (Kenny Gorman)Implementing MongoDB at Shutterfly (Kenny Gorman)
Implementing MongoDB at Shutterfly (Kenny Gorman)
MongoSF
 
AFCEA C4I Symposium: The 4th C in C4I Stands for Cloud:Factors Driving Adopti...
AFCEA C4I Symposium: The 4th C in C4I Stands for Cloud:Factors Driving Adopti...AFCEA C4I Symposium: The 4th C in C4I Stands for Cloud:Factors Driving Adopti...
AFCEA C4I Symposium: The 4th C in C4I Stands for Cloud:Factors Driving Adopti...
Patrick Chanezon
 
GR8Conf 2011: Grails 1.4 Update by Peter Ledbrook
GR8Conf 2011: Grails 1.4 Update by Peter LedbrookGR8Conf 2011: Grails 1.4 Update by Peter Ledbrook
GR8Conf 2011: Grails 1.4 Update by Peter Ledbrook
GR8Conf
 
Gaelyk - Guillaume Laforge - GR8Conf Europe 2011
Gaelyk - Guillaume Laforge - GR8Conf Europe 2011Gaelyk - Guillaume Laforge - GR8Conf Europe 2011
Gaelyk - Guillaume Laforge - GR8Conf Europe 2011
Guillaume Laforge
 

Similar a GR8Conf 2011: Tuning Grails Applications by Peter Ledbrook (20)

GR8Conf 2011: Grails Enterprise Integration by Peter Ledbrook
GR8Conf 2011: Grails Enterprise Integration by Peter LedbrookGR8Conf 2011: Grails Enterprise Integration by Peter Ledbrook
GR8Conf 2011: Grails Enterprise Integration by Peter Ledbrook
 
O365Engage17 - How to Automate SharePoint Provisioning with PNP Framework
O365Engage17 - How to Automate SharePoint Provisioning with PNP FrameworkO365Engage17 - How to Automate SharePoint Provisioning with PNP Framework
O365Engage17 - How to Automate SharePoint Provisioning with PNP Framework
 
AppEngine Performance Tuning
AppEngine Performance TuningAppEngine Performance Tuning
AppEngine Performance Tuning
 
Red Dirt Ruby Conference
Red Dirt Ruby ConferenceRed Dirt Ruby Conference
Red Dirt Ruby Conference
 
App Engine Meetup
App Engine MeetupApp Engine Meetup
App Engine Meetup
 
Build an Open Source Data Lake For Data Scientists
Build an Open Source Data Lake For Data ScientistsBuild an Open Source Data Lake For Data Scientists
Build an Open Source Data Lake For Data Scientists
 
Implementing MongoDB at Shutterfly (Kenny Gorman)
Implementing MongoDB at Shutterfly (Kenny Gorman)Implementing MongoDB at Shutterfly (Kenny Gorman)
Implementing MongoDB at Shutterfly (Kenny Gorman)
 
AFCEA C4I Symposium: The 4th C in C4I Stands for Cloud:Factors Driving Adopti...
AFCEA C4I Symposium: The 4th C in C4I Stands for Cloud:Factors Driving Adopti...AFCEA C4I Symposium: The 4th C in C4I Stands for Cloud:Factors Driving Adopti...
AFCEA C4I Symposium: The 4th C in C4I Stands for Cloud:Factors Driving Adopti...
 
Data Management - Full Stack Deep Learning
Data Management - Full Stack Deep LearningData Management - Full Stack Deep Learning
Data Management - Full Stack Deep Learning
 
GR8Conf 2011: Grails 1.4 Update by Peter Ledbrook
GR8Conf 2011: Grails 1.4 Update by Peter LedbrookGR8Conf 2011: Grails 1.4 Update by Peter Ledbrook
GR8Conf 2011: Grails 1.4 Update by Peter Ledbrook
 
Atlanta JUG - Integrating Spring Batch and Spring Integration
Atlanta JUG - Integrating Spring Batch and Spring IntegrationAtlanta JUG - Integrating Spring Batch and Spring Integration
Atlanta JUG - Integrating Spring Batch and Spring Integration
 
Spsatx slides (widescreen)
Spsatx slides (widescreen)Spsatx slides (widescreen)
Spsatx slides (widescreen)
 
Gaelyk - Guillaume Laforge - GR8Conf Europe 2011
Gaelyk - Guillaume Laforge - GR8Conf Europe 2011Gaelyk - Guillaume Laforge - GR8Conf Europe 2011
Gaelyk - Guillaume Laforge - GR8Conf Europe 2011
 
Internals of Presto Service
Internals of Presto ServiceInternals of Presto Service
Internals of Presto Service
 
OpenMetadata Community Meeting - 4th April, 2024
OpenMetadata Community Meeting - 4th April, 2024OpenMetadata Community Meeting - 4th April, 2024
OpenMetadata Community Meeting - 4th April, 2024
 
Large scale computing
Large scale computing Large scale computing
Large scale computing
 
Power Platform Leeds - November 2019 - Microsoft Ignite Announcements
Power Platform Leeds - November 2019 - Microsoft Ignite AnnouncementsPower Platform Leeds - November 2019 - Microsoft Ignite Announcements
Power Platform Leeds - November 2019 - Microsoft Ignite Announcements
 
Browser Fuzzing with a Twist (and a Shake) -- ZeroNights 2015
Browser Fuzzing with a Twist (and a Shake) -- ZeroNights 2015Browser Fuzzing with a Twist (and a Shake) -- ZeroNights 2015
Browser Fuzzing with a Twist (and a Shake) -- ZeroNights 2015
 
Debugging Skynet: A Machine Learning Approach to Log Analysis - Ianir Ideses,...
Debugging Skynet: A Machine Learning Approach to Log Analysis - Ianir Ideses,...Debugging Skynet: A Machine Learning Approach to Log Analysis - Ianir Ideses,...
Debugging Skynet: A Machine Learning Approach to Log Analysis - Ianir Ideses,...
 
Blastn plus jupyter on Docker
Blastn plus jupyter on DockerBlastn plus jupyter on Docker
Blastn plus jupyter on Docker
 

Más de GR8Conf

Más de GR8Conf (20)

DevOps Enabling Your Team
DevOps Enabling Your TeamDevOps Enabling Your Team
DevOps Enabling Your Team
 
Creating and testing REST contracts with Accurest Gradle
Creating and testing REST contracts with Accurest Gradle Creating and testing REST contracts with Accurest Gradle
Creating and testing REST contracts with Accurest Gradle
 
Mum, I want to be a Groovy full-stack developer
Mum, I want to be a Groovy full-stack developerMum, I want to be a Groovy full-stack developer
Mum, I want to be a Groovy full-stack developer
 
Metaprogramming with Groovy
Metaprogramming with GroovyMetaprogramming with Groovy
Metaprogramming with Groovy
 
Scraping with Geb
Scraping with GebScraping with Geb
Scraping with Geb
 
How to create a conference android app with Groovy and Android
How to create a conference android app with Groovy and AndroidHow to create a conference android app with Groovy and Android
How to create a conference android app with Groovy and Android
 
Ratpack On the Docks
Ratpack On the DocksRatpack On the Docks
Ratpack On the Docks
 
Groovy Powered Clean Code
Groovy Powered Clean CodeGroovy Powered Clean Code
Groovy Powered Clean Code
 
Ratpack and Grails 3
 Ratpack and Grails 3 Ratpack and Grails 3
Ratpack and Grails 3
 
Grails & DevOps: continuous integration and delivery in the cloud
Grails & DevOps: continuous integration and delivery in the cloudGrails & DevOps: continuous integration and delivery in the cloud
Grails & DevOps: continuous integration and delivery in the cloud
 
Functional testing your Grails app with GEB
Functional testing your Grails app with GEBFunctional testing your Grails app with GEB
Functional testing your Grails app with GEB
 
Deploying, Scaling, and Running Grails on AWS and VPC
Deploying, Scaling, and Running Grails on AWS and VPCDeploying, Scaling, and Running Grails on AWS and VPC
Deploying, Scaling, and Running Grails on AWS and VPC
 
The Grails introduction workshop
The Grails introduction workshopThe Grails introduction workshop
The Grails introduction workshop
 
Idiomatic spock
Idiomatic spockIdiomatic spock
Idiomatic spock
 
The Groovy Ecosystem Revisited
The Groovy Ecosystem RevisitedThe Groovy Ecosystem Revisited
The Groovy Ecosystem Revisited
 
Groovy 3 and the new Groovy Meta Object Protocol in examples
Groovy 3 and the new Groovy Meta Object Protocol in examplesGroovy 3 and the new Groovy Meta Object Protocol in examples
Groovy 3 and the new Groovy Meta Object Protocol in examples
 
Integration using Apache Camel and Groovy
Integration using Apache Camel and GroovyIntegration using Apache Camel and Groovy
Integration using Apache Camel and Groovy
 
CRaSH the shell for the Java Virtual Machine
CRaSH the shell for the Java Virtual MachineCRaSH the shell for the Java Virtual Machine
CRaSH the shell for the Java Virtual Machine
 
Grooscript gr8conf
Grooscript gr8confGrooscript gr8conf
Grooscript gr8conf
 
CRaSH the shell for the Java Virtual Machine
CRaSH the shell for the Java Virtual MachineCRaSH the shell for the Java Virtual Machine
CRaSH the shell for the Java Virtual Machine
 

Último

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 

Último (20)

Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 

GR8Conf 2011: Tuning Grails Applications by Peter Ledbrook

  • 1. Tuning Grails apps Peter Ledbrook Monday, 30 May 2011 1
  • 2. Everyone wants to be Facebook • Few apps start with millions of hits a day • Scaling throws up many more issues than just the framework Monday, 30 May 2011 2
  • 3. Premature optimisation Profile ... then optimise Monday, 30 May 2011 3
  • 4. Where can things be slow? Business DB Network UI Logic Monday, 30 May 2011 4
  • 5. Server-side tools • Spring Insight • Profiler Plugin • Hibernate logging • P6Spy • Hibernate Statistics – App Info & Hibernate Stats Plugins 5 Monday, 30 May 2011 5
  • 6. UI tools • Google Speed Tracer (Chrome only) – Spring Insight integration • ySlow (Firefox only - requires Firebug) 6 Monday, 30 May 2011 6
  • 7. Monday, 30 May 2011 7
  • 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 8 Monday, 30 May 2011 8
  • 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. Database performance • Caching – Hibernate 2nd-level cache – Distributed cache/data grid • Terracotta • GemFire • Alternative data store! 10 Monday, 30 May 2011 10
  • 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 infrequently Monday, 30 May 2011 11
  • 12. Data grid GemFire GemFire Grails DB GemFire App 12 Monday, 30 May 2011 12
  • 13. Business logic • Caching – Spring Cache Plugin for service methods • Go asynchronous – Ideal for long running tasks – Spring Events, Executor – Messaging: JMS, AMQP 13 Monday, 30 May 2011 13
  • 14. Business logic • Fall back to Java – Limited applicability – Numerically intensive tasks? • Groovy++? – One JAR – @Typed on class or method 14 Monday, 30 May 2011 14
  • 15. Business logic class MyService { @Typed(TypePolicy.MIXED) void doSomething() { expensiveMethod() } @Typed void expensiveMethod() { // Do something } } 15 Monday, 30 May 2011 15
  • 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. Spring Cache with views Sitemesh Spring Cache Render GSP Cached View Monday, 30 May 2011 17
  • 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. 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. 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 extension Monday, 30 May 2011 20
  • 21. Monday, 30 May 2011 21
  • 22. Rich UIs • Browser does the work • Minimal traffic • GWT, Flex, etc. • Data transfer – JSON – XML – GWT-RPC Monday, 30 May 2011 22
  • 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.4 Monday, 30 May 2011 23
  • 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/resources Monday, 30 May 2011 24
  • 25. Thank you! Q&A Monday, 30 May 2011 25