SlideShare ist ein Scribd-Unternehmen logo
1 von 37
Downloaden Sie, um offline zu lesen
Introduction to the
Grails Infinispan Plugin



     Tom Fuller
  Coherent Logic Limited
Overview
•   A story
•   Design principles
•   Code examples
•   Conclusion
Why all the stress?



     Application
       Server




     Application
       Server
Traffic spike = trouble

                                                   Hits per minute

100000
 90000
 80000
70000
60000
50000                                                                                            Hits per minute
40000
30000
20000
10000
    0

         01 02 03 04 05 06 07 08 09 10 11 12 13 30 40 43 45 50
     10 : 10 : 10 : 10 : 10 : 10 : 10 : 10 : 10 : 10 : 10 : 10 : 10 : 10 : 10 : 10 : 10 : 10 :
(CC) griffithchris
(CC) Mr. Gunn
Refactor here, optimise there…



          Application
            Server




          Application
            Server
Again – a traffic spike = trouble

                                                                                  Hits per minute

140000

120000

100000

80000
                                                                                                                                                                 Hits per minute
60000

40000

20000

    0
         10:01
                 10:02
                         10:03
                                 10:04
                                         10:05
                                                 10:06
                                                         10:07
                                                                 10:08
                                                                         10:09
                                                                                 10:10
                                                                                         10:11
                                                                                                 10:12
                                                                                                         10:13
                                                                                                                 10:30
                                                                                                                         10:40
                                                                                                                                 10:43
                                                                                                                                         10:45
                                                                                                                                                 10:50
                                                                                                                                                         10:55
(CC) amboo who?
(CC) Stephi 2006
Just buy bigger servers



     Application
       Server




     Application
       Server
0
            50000
                    100000
                                               150000
                                                        200000
                                                                 250000
10:01
10:02
10:03
10:04
10:05
10:06
10:07
10:08
10:09
10:10
10:11
10:12
                                                                          Hits per minute




10:13
10:30
10:40
10:43
10:45
10:50
10:55
                                                                                            Traffic spike = trouble




                             Hits per minute
(CC) fireflythegreat
(CC) Ray_from_LA
Replicate here, replicate there…


          Application
            Server




          Application
            Server




          Application
            Server
No surprise – a traffic spike =
                    trouble
                                                Hits per minute


400000
350000
300000
250000
200000                                                                                      Hits per minute
150000
100000
50000
    0

       01      03      05      07      09      11      13      40      45      55      05
    10:     10:     10:     10:     10:     10:     10:     10:     10:     10:     11:
(CC) Tweek
Where we’re at:
• Optimisation alone won’t solve this
  problem.
• Neither will larger servers.
• Scaling the application server and
  databases doesn’t work.
(CC) Mattastic!
A solution that works!
                         Cache



                 Cache




                         Cache
   Application
     Server

                 Cache




                         Cache



                 Cache




                         Cache



                 Cache
   Application
     Server
Infinispan
•   Based in part on code from JBoss Cache
•   Licensed under the LGPL
•   Is a distributed in-memory data grid
•   Has competition
•   As of May 2011 Infinispan is officially
    supported by Red Hat.
Traffic spike = not a problem!
                                                      Hits per minute


  600000

  500000

  400000

  300000                                                                                        Hits per minute

  200000

  100000

      0

         01      03      05      07      09      11       13      40       45      55      05
      10:     10:     10:     10:     10:     10:      10:     10:      10:     10:     11:
Just grow the grid!
                                                     Cache



                                             Cache



                                                     Cache



                                             Cache



                                                     Cache



                                             Cache




                                                     Cache
                               Application
                                 Server

                                             Cache




                                                     Cache



                                             Cache




                                                     Cache



                                             Cache
                               Application
                                 Server

                                                     Cache



                                             Cache




* NOTE: Caveat with session clustering.
Design Principles of the Grails
                Infinispan Plugin




(CC) El Bibliomata
We aim to help developers:
Work with Grails and Groovy naturally.
We aim to help developers:
Work with Grails and Groovy naturally.
Avoid and diagnose problems quickly.
We aim to help developers:
Work with Grails and Groovy naturally.
Avoid and diagnose problems quickly.
Save time.
Configuring Infinispan in Grails
development {
    infinispan = {
       register {
          cacheManager {
            named "matrixCacheManager"
               configured {
                  externally {
                    using "grails-app/conf/infinispan/infinispan-config.xml"
                  }
               }
            caches "agentCache", “citiesCache"
          }
          queryHelper {
            named "agentQueryHelper"
            referencing "agentCache"
            properties queryHelperProperties
            classes infinispantestapp.Agent, infinispantestapp.SuperHero
          }
       }
    }
  }
}
Configuring Infinispan in Grails
production {
    infinispan = {
       register {
          cacheManager {
             named "matrixCacheManager"
             configured {
                declaratively {
                  using globalConfiguration
                  using configuration
                }
             }
             caches "agentCache", "illinoisCitiesCache"
          }
          queryHelper {
             named "agentQueryHelper"
             referencing "agentCache"
             properties queryHelperProperties
             classes infinispantestapp.Agent, infinispantestapp.SuperHero
          }
       }
    }
  }
}
Use the cache
LoadAgentCacheController {
  def agentCache
  def index = {
    for (int ctr in 1..1000) {
        agentCache.put (
          "person id $ctr",
          new Agent (name:"Agent Smith",
          weapon:"gun")
        )
    }
  }
}
Execute a transactional operation
cache.transactionally {
  cache.put(someKey, someValue);
  cache.remove(someOtherKey);
}
Query and iterate over the results
def term = new Term (WEAPON, GUN)
def termQuery = new TermQuery (term)

def results = agentCache.query (queryHelper,
  Agent, termQuery)

results.each {
  log.info ("it: $it")
}
Add closures as listeners
agentCache.onCacheEntryCreated {
  log.info ("Cache entry created: $it")
}
Food for Thought
• Infinispan 5.0 is currently under
  development and will deliver fork/join and
  map/reduce implementations.
• Infinispan can help reduce costs for any
  data source.
• Infinispan can be very useful in the cloud
  and service-oriented architectures (SOA).
A p p lic a tio n A p p lic a tio n
                                                                                                     S e rv e r        S e rv e r




                             C u s to m e r
                           I n fo r m a t io n
                                                                                                  O rd e r
                                                                                                 h is t o r y                            O rd e r
                                                                                                                                        h is t o r y




A p p lic a tio n
                                                                          A p p lic a tio n A p p lic a tio n          Paym ent
   S e rv e r                                        O rd e r
                                                                             S e rv e r        S e rv e r            p r o c e s s in g ,
                                                 p r o c e s s in g
                                                                                                                       S h ip p in g



A p p lic a tio n
   S e rv e r
                                             P ro d u ct
                                          in fo r m a t io n          P a rtn e r & p ro d u ct
                     A n a ly t ic s                                       in fo r m a t io n
                                                                                                                      P a rtn e r
                                                                                                                  r e g is t r a t io n




           A p p lic a tio n A p p lic a tio n             A p p lic a tio n A p p lic a tio n
              S e rv e r        S e rv e r                    S e rv e r        S e rv e r
Conclusion
• Three attempts that failed to deliver a
  solution that could cope with the load.
• Design principles behind the Grails
  Infinispan Plugin.
• Example code.
• Further documentation is available at
  http://www.grails.org/plugin/infinispan
Any questions?

           Contact me
             Email:
thomas.fuller@coherentlogic.com

Weitere ähnliche Inhalte

Ähnlich wie GR8Conf 2011: Grails Infinispanplugin, Tom Fuller

Ähnlich wie GR8Conf 2011: Grails Infinispanplugin, Tom Fuller (8)

Xtreme Telecoms Presentation
Xtreme Telecoms PresentationXtreme Telecoms Presentation
Xtreme Telecoms Presentation
 
Database Health Check
Database Health CheckDatabase Health Check
Database Health Check
 
Top Application Performance Landmines
Top Application Performance LandminesTop Application Performance Landmines
Top Application Performance Landmines
 
D max launch program 2010 revised by ayman (final) sheet2
D max launch program 2010 revised by ayman (final) sheet2D max launch program 2010 revised by ayman (final) sheet2
D max launch program 2010 revised by ayman (final) sheet2
 
DCT_TR802
DCT_TR802DCT_TR802
DCT_TR802
 
DCT_TR802
DCT_TR802DCT_TR802
DCT_TR802
 
DCT_TR802
DCT_TR802DCT_TR802
DCT_TR802
 
Bassa presentation
Bassa presentationBassa presentation
Bassa presentation
 

Mehr von GR8Conf

DevOps Enabling Your Team
DevOps Enabling Your TeamDevOps Enabling Your Team
DevOps Enabling Your TeamGR8Conf
 
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 GR8Conf
 
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 developerGR8Conf
 
Metaprogramming with Groovy
Metaprogramming with GroovyMetaprogramming with Groovy
Metaprogramming with GroovyGR8Conf
 
Scraping with Geb
Scraping with GebScraping with Geb
Scraping with GebGR8Conf
 
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 AndroidGR8Conf
 
Ratpack On the Docks
Ratpack On the DocksRatpack On the Docks
Ratpack On the DocksGR8Conf
 
Groovy Powered Clean Code
Groovy Powered Clean CodeGroovy Powered Clean Code
Groovy Powered Clean CodeGR8Conf
 
Cut your Grails application to pieces - build feature plugins
Cut your Grails application to pieces - build feature pluginsCut your Grails application to pieces - build feature plugins
Cut your Grails application to pieces - build feature pluginsGR8Conf
 
Performance tuning Grails applications
 Performance tuning Grails applications Performance tuning Grails applications
Performance tuning Grails applicationsGR8Conf
 
Ratpack and Grails 3
 Ratpack and Grails 3 Ratpack and Grails 3
Ratpack and Grails 3GR8Conf
 
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 cloudGR8Conf
 
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 GEBGR8Conf
 
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 VPCGR8Conf
 
The Grails introduction workshop
The Grails introduction workshopThe Grails introduction workshop
The Grails introduction workshopGR8Conf
 
Idiomatic spock
Idiomatic spockIdiomatic spock
Idiomatic spockGR8Conf
 
The Groovy Ecosystem Revisited
The Groovy Ecosystem RevisitedThe Groovy Ecosystem Revisited
The Groovy Ecosystem RevisitedGR8Conf
 
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 examplesGR8Conf
 
Integration using Apache Camel and Groovy
Integration using Apache Camel and GroovyIntegration using Apache Camel and Groovy
Integration using Apache Camel and GroovyGR8Conf
 
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 MachineGR8Conf
 

Mehr von 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
 
Cut your Grails application to pieces - build feature plugins
Cut your Grails application to pieces - build feature pluginsCut your Grails application to pieces - build feature plugins
Cut your Grails application to pieces - build feature plugins
 
Performance tuning Grails applications
 Performance tuning Grails applications Performance tuning Grails applications
Performance tuning Grails applications
 
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
 

GR8Conf 2011: Grails Infinispanplugin, Tom Fuller

  • 1. Introduction to the Grails Infinispan Plugin Tom Fuller Coherent Logic Limited
  • 2. Overview • A story • Design principles • Code examples • Conclusion
  • 3. Why all the stress? Application Server Application Server
  • 4. Traffic spike = trouble Hits per minute 100000 90000 80000 70000 60000 50000 Hits per minute 40000 30000 20000 10000 0 01 02 03 04 05 06 07 08 09 10 11 12 13 30 40 43 45 50 10 : 10 : 10 : 10 : 10 : 10 : 10 : 10 : 10 : 10 : 10 : 10 : 10 : 10 : 10 : 10 : 10 : 10 :
  • 7. Refactor here, optimise there… Application Server Application Server
  • 8. Again – a traffic spike = trouble Hits per minute 140000 120000 100000 80000 Hits per minute 60000 40000 20000 0 10:01 10:02 10:03 10:04 10:05 10:06 10:07 10:08 10:09 10:10 10:11 10:12 10:13 10:30 10:40 10:43 10:45 10:50 10:55
  • 11. Just buy bigger servers Application Server Application Server
  • 12. 0 50000 100000 150000 200000 250000 10:01 10:02 10:03 10:04 10:05 10:06 10:07 10:08 10:09 10:10 10:11 10:12 Hits per minute 10:13 10:30 10:40 10:43 10:45 10:50 10:55 Traffic spike = trouble Hits per minute
  • 15. Replicate here, replicate there… Application Server Application Server Application Server
  • 16. No surprise – a traffic spike = trouble Hits per minute 400000 350000 300000 250000 200000 Hits per minute 150000 100000 50000 0 01 03 05 07 09 11 13 40 45 55 05 10: 10: 10: 10: 10: 10: 10: 10: 10: 10: 11:
  • 18. Where we’re at: • Optimisation alone won’t solve this problem. • Neither will larger servers. • Scaling the application server and databases doesn’t work.
  • 20. A solution that works! Cache Cache Cache Application Server Cache Cache Cache Cache Cache Application Server
  • 21. Infinispan • Based in part on code from JBoss Cache • Licensed under the LGPL • Is a distributed in-memory data grid • Has competition • As of May 2011 Infinispan is officially supported by Red Hat.
  • 22. Traffic spike = not a problem! Hits per minute 600000 500000 400000 300000 Hits per minute 200000 100000 0 01 03 05 07 09 11 13 40 45 55 05 10: 10: 10: 10: 10: 10: 10: 10: 10: 10: 11:
  • 23. Just grow the grid! Cache Cache Cache Cache Cache Cache Cache Application Server Cache Cache Cache Cache Cache Application Server Cache Cache * NOTE: Caveat with session clustering.
  • 24. Design Principles of the Grails Infinispan Plugin (CC) El Bibliomata
  • 25. We aim to help developers: Work with Grails and Groovy naturally.
  • 26. We aim to help developers: Work with Grails and Groovy naturally. Avoid and diagnose problems quickly.
  • 27. We aim to help developers: Work with Grails and Groovy naturally. Avoid and diagnose problems quickly. Save time.
  • 28. Configuring Infinispan in Grails development { infinispan = { register { cacheManager { named "matrixCacheManager" configured { externally { using "grails-app/conf/infinispan/infinispan-config.xml" } } caches "agentCache", “citiesCache" } queryHelper { named "agentQueryHelper" referencing "agentCache" properties queryHelperProperties classes infinispantestapp.Agent, infinispantestapp.SuperHero } } } } }
  • 29. Configuring Infinispan in Grails production { infinispan = { register { cacheManager { named "matrixCacheManager" configured { declaratively { using globalConfiguration using configuration } } caches "agentCache", "illinoisCitiesCache" } queryHelper { named "agentQueryHelper" referencing "agentCache" properties queryHelperProperties classes infinispantestapp.Agent, infinispantestapp.SuperHero } } } } }
  • 30. Use the cache LoadAgentCacheController { def agentCache def index = { for (int ctr in 1..1000) { agentCache.put ( "person id $ctr", new Agent (name:"Agent Smith", weapon:"gun") ) } } }
  • 31. Execute a transactional operation cache.transactionally { cache.put(someKey, someValue); cache.remove(someOtherKey); }
  • 32. Query and iterate over the results def term = new Term (WEAPON, GUN) def termQuery = new TermQuery (term) def results = agentCache.query (queryHelper, Agent, termQuery) results.each { log.info ("it: $it") }
  • 33. Add closures as listeners agentCache.onCacheEntryCreated { log.info ("Cache entry created: $it") }
  • 34. Food for Thought • Infinispan 5.0 is currently under development and will deliver fork/join and map/reduce implementations. • Infinispan can help reduce costs for any data source. • Infinispan can be very useful in the cloud and service-oriented architectures (SOA).
  • 35. A p p lic a tio n A p p lic a tio n S e rv e r S e rv e r C u s to m e r I n fo r m a t io n O rd e r h is t o r y O rd e r h is t o r y A p p lic a tio n A p p lic a tio n A p p lic a tio n Paym ent S e rv e r O rd e r S e rv e r S e rv e r p r o c e s s in g , p r o c e s s in g S h ip p in g A p p lic a tio n S e rv e r P ro d u ct in fo r m a t io n P a rtn e r & p ro d u ct A n a ly t ic s in fo r m a t io n P a rtn e r r e g is t r a t io n A p p lic a tio n A p p lic a tio n A p p lic a tio n A p p lic a tio n S e rv e r S e rv e r S e rv e r S e rv e r
  • 36. Conclusion • Three attempts that failed to deliver a solution that could cope with the load. • Design principles behind the Grails Infinispan Plugin. • Example code. • Further documentation is available at http://www.grails.org/plugin/infinispan
  • 37. Any questions? Contact me Email: thomas.fuller@coherentlogic.com