SlideShare a Scribd company logo
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

More Related Content

PDF
Equipment hire
KEY
Grails EE
PDF
GR8Conf 2009: Industrial Strength Groovy by Paul King
PDF
GR8Conf 2011: Groovy 1.8 update
PDF
GR8Conf 2011: Canoo RIA Suite
PDF
GR8Conf 2011: Building Progressive UIs with Grails
PDF
GR8Conf 2009: Griffon by Jim Shingler
PDF
Xtreme Telecoms Presentation
Equipment hire
Grails EE
GR8Conf 2009: Industrial Strength Groovy by Paul King
GR8Conf 2011: Groovy 1.8 update
GR8Conf 2011: Canoo RIA Suite
GR8Conf 2011: Building Progressive UIs with Grails
GR8Conf 2009: Griffon by Jim Shingler
Xtreme Telecoms Presentation

Similar to GR8Conf 2011: Grails Infinispanplugin, Tom Fuller (8)

PDF
Xtreme Telecoms Presentation
PDF
Database Health Check
PPTX
Top Application Performance Landmines
PDF
D max launch program 2010 revised by ayman (final) sheet2
PDF
DCT_TR802
PDF
DCT_TR802
PDF
DCT_TR802
PDF
Bassa presentation
Xtreme Telecoms Presentation
Database Health Check
Top Application Performance Landmines
D max launch program 2010 revised by ayman (final) sheet2
DCT_TR802
DCT_TR802
DCT_TR802
Bassa presentation
Ad

More from GR8Conf (20)

PDF
DevOps Enabling Your Team
PDF
Creating and testing REST contracts with Accurest Gradle
PDF
Mum, I want to be a Groovy full-stack developer
PDF
Metaprogramming with Groovy
PDF
Scraping with Geb
PDF
How to create a conference android app with Groovy and Android
PDF
Ratpack On the Docks
PDF
Groovy Powered Clean Code
PDF
Cut your Grails application to pieces - build feature plugins
PDF
Performance tuning Grails applications
PDF
Ratpack and Grails 3
PDF
Grails & DevOps: continuous integration and delivery in the cloud
PDF
Functional testing your Grails app with GEB
PDF
Deploying, Scaling, and Running Grails on AWS and VPC
PDF
The Grails introduction workshop
PDF
Idiomatic spock
PDF
The Groovy Ecosystem Revisited
PDF
Groovy 3 and the new Groovy Meta Object Protocol in examples
PDF
Integration using Apache Camel and Groovy
PDF
CRaSH the shell for the Java Virtual Machine
DevOps Enabling Your Team
Creating and testing REST contracts with Accurest Gradle
Mum, I want to be a Groovy full-stack developer
Metaprogramming with Groovy
Scraping with Geb
How to create a conference android app with Groovy and Android
Ratpack On the Docks
Groovy Powered Clean Code
Cut your Grails application to pieces - build feature plugins
Performance tuning Grails applications
Ratpack and Grails 3
Grails & DevOps: continuous integration and delivery in the cloud
Functional testing your Grails app with GEB
Deploying, Scaling, and Running Grails on AWS and VPC
The Grails introduction workshop
Idiomatic spock
The Groovy Ecosystem Revisited
Groovy 3 and the new Groovy Meta Object Protocol in examples
Integration using Apache Camel and Groovy
CRaSH the shell for the Java Virtual Machine
Ad

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