Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.
Scaling Hibernate with Terracotta
Alex Miller (@puredanger)
Architecture and Scale
Applications in Three Tiers


                      Client



                      Server



                    Database
How do we scale?


   Client           Client    Client



   Server           Server    Server



                   Data...
But what about failover?
Option 1: Servers share state


    Client            Client    Client



   Server            Server     Server



      ...
How?

• RMI


• JMS


• Custom (JGroups, etc)
Option 2: Database (“stateless”)


    Client            Client       Client



   Server            Server        Server
...
Stateless == “State in the database”

• Database load


• Serialization to and from the database


• Network bandwidth


•...
Option 3: Terracotta!


   Client                Client       Client



   Server                Server      Server
  Terr...
Why is this better?

• Hub and spoke vs peer to peer


• Avoid object / relational translation


• Avoid serialization


•...
What state should go in Terracotta?

        Appropriateness   Memory     Terracotta    Database




                     ...
How does Terracotta work?
Core Concepts

• Roots


• Instrumented Classes


• Locks


• Integration Modules
Clustered Heap

        App   App app = new App();
              app.run();
Clustered Heap

        App         EmployeeManager employeeMgr =
                       new EmployeeManager();


        ...
Clustered Heap

        App




         Employee
                                                    " U9 9 4 1 1 "
     ...
Clustered Heap

        App         employeeMgr.addEmployee(employee);



         Employee
                              ...
Clustered Heap

        App




         Employee
                                                          "U99411"
     ...
Configuration

• Roots


  • app.App.employeeMgr - a root of the clustered heap


• Instrumented classes


  • app.* - inst...
Integration Modules

• Pre-built configuration


• Integration with specific 3rd-party libraries


   • Hibernate


   • Spr...
Scaling Hibernate

• Hibernate Second Level Cache


• Clustered detached entities


  • Close session, detach entities


 ...
Hibernate Caching


                      Application Thread            Application Thread



                           S...
Entity and collection caches

• Entity and collection cache regions


• Mark a Hibernate entity or a collection in an enti...
Query Cache

• Query cache regions


   • Mark HQL, Criteria, Query as cacheable


   • Store result set id values


• Tim...
Terracotta Hibernate Second Level Cache

 • Easy integration and configuration


 • Supports entity, collection, and query ...
Enabling Second Level Cache

• Mark your entities with a cache concurrency strategy


  • In hibernate.cfg.xml:   <cache u...
Enabling Second Level Cache
• Define the tc-hibernate-cache.xml in your classpath

<?xml version=”1.0” encoding=”UTF-8”?>
<...
Tooling Demo
Performance - Read-Only Comparison


                                           Throughput                                ...
How else is Terracotta used?

• Distributed cache


• Clustered HTTP sessions


• Batch processing


• Grid


• Messaging ...
Who Uses It?

• e-Commerce


• Online gaming


• Financial services


• Travel & leisure


• Social networking
Thanks!

• Terracotta Open Source JVM clustering:

   • http://www.terracotta.org

• Apress: “The Definitive Guide to Terra...
Prochain SlideShare
Chargement dans…5
×

Scaling Hibernate with Terracotta

7 371 vues

Publié le

Terracotta (an open source technology) provides a clustered, durable virtual heap. Terracotta's goal is to make Java apps scale with as little effort as possible. If you are using Hibernate, there are several patterns that can be used to leverage Terracotta and reduce the load on your database so your app can scale.

First, you can use the Terracotta clustered Hibernate cache. This is a high-performance clustered cache and allows you to avoid hitting the database on all nodes in your cluster. It's suitable, not just for read-only, but also for read-mostly and read-write use cases, which traditionally have not been viewed as good use cases for Hibernate second level cache.

Another high performance option is to disconnect your POJOs from their Hibernate session and manage them entirely in Terracotta shared heap instead. This is a great option for conversational data where the conversational data is not of long-term interest but must be persistent and highly-available. This pattern can significantly reduce your database load but does require more changes to your application than using second-level cache.

This talk will examine the basics of what Terracotta provides and examples of how you can scale your Hibernate application with both clustered second level cache and detached clustered state. Also, we'll take a look at Terracotta's Hibernate-specific monitoring tools.

Publié dans : Technologie, Business
  • DOWNLOAD THE BOOK INTO AVAILABLE FORMAT (New Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://urlzs.com/UABbn } ......................................................................................................................... Download Full EPUB Ebook here { https://urlzs.com/UABbn } ......................................................................................................................... Download Full doc Ebook here { https://urlzs.com/UABbn } ......................................................................................................................... Download PDF EBOOK here { https://urlzs.com/UABbn } ......................................................................................................................... Download EPUB Ebook here { https://urlzs.com/UABbn } ......................................................................................................................... Download doc Ebook here { https://urlzs.com/UABbn } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THE can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THE is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBOOK .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, CookBOOK, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, EBOOK, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THE Helped Ignite a Movement,-- Atomic Habits: An Easy &amp; Proven Way to Build Good Habits &amp; Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THE the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THE Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Répondre 
    Voulez-vous vraiment ?  Oui  Non
    Votre message apparaîtra ici
  • Dating for everyone is here: ❤❤❤ http://bit.ly/39pMlLF ❤❤❤
       Répondre 
    Voulez-vous vraiment ?  Oui  Non
    Votre message apparaîtra ici
  • Dating direct: ❤❤❤ http://bit.ly/39pMlLF ❤❤❤
       Répondre 
    Voulez-vous vraiment ?  Oui  Non
    Votre message apparaîtra ici
  • DOWNLOAD FULL BOOKS, INTO AVAILABLE FORMAT ......................................................................................................................... ......................................................................................................................... ,DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ,DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ,DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ,DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ,DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ,DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Répondre 
    Voulez-vous vraiment ?  Oui  Non
    Votre message apparaîtra ici

Scaling Hibernate with Terracotta

  1. 1. Scaling Hibernate with Terracotta Alex Miller (@puredanger)
  2. 2. Architecture and Scale
  3. 3. Applications in Three Tiers Client Server Database
  4. 4. How do we scale? Client Client Client Server Server Server Database
  5. 5. But what about failover?
  6. 6. Option 1: Servers share state Client Client Client Server Server Server Database
  7. 7. How? • RMI • JMS • Custom (JGroups, etc)
  8. 8. Option 2: Database (“stateless”) Client Client Client Server Server Server Database
  9. 9. Stateless == “State in the database” • Database load • Serialization to and from the database • Network bandwidth • Object / relational mapping due to impedance mismatch
  10. 10. Option 3: Terracotta! Client Client Client Server Server Server Terracotta Terracotta Terracotta Terracotta Terracotta Database Server Server Instance Instance
  11. 11. Why is this better? • Hub and spoke vs peer to peer • Avoid object / relational translation • Avoid serialization • Reduce database overload • Programming model you already know • Focus on your app, not scalability and high availability
  12. 12. What state should go in Terracotta? Appropriateness Memory Terracotta Database Data Lifetime
  13. 13. How does Terracotta work?
  14. 14. Core Concepts • Roots • Instrumented Classes • Locks • Integration Modules
  15. 15. Clustered Heap App App app = new App(); app.run();
  16. 16. Clustered Heap App EmployeeManager employeeMgr = new EmployeeManager(); Employee Manager Object lock Object lock = new Object(); Map<String,Employee> = new HashMap<String,Employee>(); HashMap employees
  17. 17. Clustered Heap App Employee " U9 9 4 1 1 " M anag er Ob ject lock Employee.AC T IV E = = 1 Employee " Gandalf" HashM ap employees Employee employee = new Employee( “U99411”, “Gandalf”, Employee.ACTIVE);
  18. 18. Clustered Heap App employeeMgr.addEmployee(employee); Employee "U99411" Manager Object lock Employee.ACT IVE == 1 "U99411" Employee "Gandalf" HashMap employees synchronized(lock) { employees.put(e.getId(), e); }
  19. 19. Clustered Heap App Employee "U99411" Manager Object lock Employee.ACT IVE == 1 "U99411" Employee "Gandalf" HashMap employees "U23526" Employee "U23526" Employee.ACT IVE = 1 "U99411"
  20. 20. Configuration • Roots • app.App.employeeMgr - a root of the clustered heap • Instrumented classes • app.* - instrument app classes at load time • Locks • employeeMgr.addEmployee() -> cluster synchronized blocks
  21. 21. Integration Modules • Pre-built configuration • Integration with specific 3rd-party libraries • Hibernate • Spring • Ehcache • Quartz • Lucene • many more...
  22. 22. Scaling Hibernate • Hibernate Second Level Cache • Clustered detached entities • Close session, detach entities • Cluster those entities in Terracotta • Merge with new session later
  23. 23. Hibernate Caching Application Thread Application Thread Session Session 1st Level Cache Cache Cache Cache Concurrency Concurrency Concurrency Hibernate Strategy Strategy Strategy CacheProvider 2nd Level Cache Cache Cache Cache Region Region Region Database
  24. 24. Entity and collection caches • Entity and collection cache regions • Mark a Hibernate entity or a collection in an entity as @Cacheable • Specify a cache concurrency strategy • ReadOnly, ReadWrite, NonstrictReadWrite, Transactional • Turn on second level caching in the Hibernate config
  25. 25. Query Cache • Query cache regions • Mark HQL, Criteria, Query as cacheable • Store result set id values • Timestamp cache region - last update time for each entity type • Useful for caching natural key lookups (non-primary key) • ...but lots of hidden issues
  26. 26. Terracotta Hibernate Second Level Cache • Easy integration and configuration • Supports entity, collection, and query cache regions • Supports read-only, read-write, and nonstrict-read-write cache concurrency strategies • Hibernate-specific tooling • High performance with cache coherency
  27. 27. Enabling Second Level Cache • Mark your entities with a cache concurrency strategy • In hibernate.cfg.xml: <cache usage="read-write"/> • With annotations: @Cache(usage=CacheConcurrencyStrategy.READ_WRITE) • hibernate.cfg.xml • <property name="cache.use_second_level_cache">true</property> • <property name="cache.provider_class"> org.terracotta.hibernate.TerracottaHibernateCacheProvider</property>
  28. 28. Enabling Second Level Cache • Define the tc-hibernate-cache.xml in your classpath <?xml version=”1.0” encoding=”UTF-8”?> <terracotta-hibernate-cache-configuration> <default-configuration> <time-to-idle-seconds>7200</time-to-idle-seconds> <time-to-live-seconds>7200</time-to-live-seconds> </default-configuration> <cache> <region-name>org.terracotta.authinator.domain.Account</region-name> <!-- as many region-names here as you want --> <configuration> <time-to-idle-seconds>600</time-to-idle-seconds> <time-to-live-seconds>600</time-to-live-seconds> </configuration> </cache> </terracotta-hibernate-cache-configuration> • Add the Terracotta Hibernate cache provider jar to your classpath • -cp terracotta-hibernate-cache-1.0.0.jar • Add the Terracotta Hibernate cache agent jar to your command line • -javaagent:terracotta-hibernate-agent-1.0.0.jar
  29. 29. Tooling Demo
  30. 30. Performance - Read-Only Comparison Throughput Latency 200K 100 Transactions per second 80 150K Avg Latency (ms) 60 100K 40 50K 20 0K 0 Database IMDG EhcacheTerracotta Database IMDG EhcacheTerracotta
  31. 31. How else is Terracotta used? • Distributed cache • Clustered HTTP sessions • Batch processing • Grid • Messaging and events
  32. 32. Who Uses It? • e-Commerce • Online gaming • Financial services • Travel & leisure • Social networking
  33. 33. Thanks! • Terracotta Open Source JVM clustering: • http://www.terracotta.org • Apress: “The Definitive Guide to Terracotta” • by Ari Zilka, Alex Miller, Geert Bevin, Jonas Boner, Orion Letizi, Taylor Gautier • Alex Miller • @puredanger • http://tech.puredanger.com

×