This book covers many topics with Terracotta Clustering and Grid Computing for server side, along with concrete theory and a good amount of code with clever and important images.
Integration with Spring, Hibernate are included in this book.
You can consider this chapter as an introduction. The Terracotta Framework is defined as a transparent clustering service for Java applications or JVM-level clustering. Operational benefits are explained such as:
Now something important to cover and perhaps the magic of Terracotta is Transparency of Memory Location with a useful and simple image the chapter explains how Terracotta sits between the application and the JVM
This is followed with Putting Transparency and Clustering Together - talking about how a developer can see sharing some part of a Java process's memory across process boundaries and machines. A snippet of a POJO class is used and the authors talk about of how some instances of such an object would be clustered in two servers. Therefore to get transparent clustering, threading and coordination are covered.
Next up, the Java Memory Model is explained, and how Terracotta works with such models to ensure proper cross-process behaviour and semantics, and how it to do it without breaking the first law of distributed computing
The chapter offers an interesting section, Being a Service has Advantages, where attention is brought to the service component by Terracotta, where a good image is included and explains how Terracotta components include libraries and a server process that communicates over TCP/IP. A further sub topic about Availability, Scalability and Avoiding Bottlenecks gives a good explanation and situations in real life. For instance, if all Java process were to stop, and if we start the process again we can gain access to these objects as they existed in memory before terminated
To end this chapter Use Cases are covered with the following topics:
This is a short, but really important chapter where it starts talking and offering an image about of n-tier architecture. Then Approaches To Scaling is introduced with some interesting sub topics
Scale The Database: here the authors use and explain an image of nondistributed cache working with a database and explain the difference of striping disk under databases versus striping databases under applications
In-Memory Replication: talks about keeping session data in memory (stateful). Possible problems when the replication crashes and mentions stateless and a difference between the implementations.
All Paths Lead to Partitioning: Again explain and use an image about a comparison of a non-partitioned CRUD application versus a partitioned implementation by spliting data into even and odd data.
After of this, the origin of Terracotta is introduced, which is interesting history where L2 cache is mentioned.
Among other things in the rest of the chapter, there is a section called Transparent Clustering Service Revisted which uses an image to compare Application-level clustering and JVM-level Clustering, where it illustrates that an application clustering requires many different approaches, while Terracotta does not.Chapter 3: Jumping Into Terracotta
The chapter starts with a Java class that outputs each character of a String to the console through a synchronized method the first time is executed alone. The authors show us how this class should be clustered through field-name tags and of course among others, uses an UML sequence diagram to see how the two JVM instances work together, and explain how the code would work with Terracotta.
After that, the authors do a tour about download and installation, with an explanation about directories structure and scripts.
Now it's time to configure our Java class with Terracotta. Here the authors explain the importants parts of Terracotta configuration with our class like persistence, roots, instrumentation, locks, and all these parts are shown together in tc-config.xml file. After being show how to start Terracotta and how to start two clustered instances of our Java class, you can clearly see how Terracotta does its magic. The authors now teach us about the Administration Console, now that you have all working, and proceed to explain how this application matches High Availability and Heap Durability features and behaviours
Even more, how do all this in Eclipse is explained to the reader.Chapter 4: POJO Clustering
Here the authors cover many topics about configuring objects with Terracotta root tag, code snippets are used, followedwith a good amount of theory about Clustered Objects, Virtual Heap and Memory Management, Managing Object Changes and Coordinating Threads, Locks including two snippets about Autolocks and Named Locks
Locks is really an interesting topic with the following variants:
Transparency and Bytecode Instrumentation is covered before we move onto Clustering POJOs, with two pages about What and Why Clustered POJO is introduced, with eight pages for pure Java POJOs. After that, configuration for tc-config-pojo.xml is covered for our code, and how to execute the code (with or without Eclipse). The authors show the output and the results that you should expect, including results from the Terracotta Administration ConsoleChapter 5: Caching
Here we start with an introduction to the Pain of Caching like:
Now is the turn of How Terracotta Can Help, the previous image now is turned with Terracotta Server based in Transparent Paging, you can see clearly a good solution.
An example for Caching is introduced where Java code is used and based principally in a variable Map interface and its methods about of put/get purposes among others. The code is executed alone and its output is shown. After that, Terracotta XML configuration in one page is shown to teaches us about how do the distributing caching and how should be executed
After this, detailed cover for Maps is offered including an explanation for autolocking for collections and how this can be used with Terracotta configurationA section called A Deeper Look at Caching is covered with good theory for topics like Eviction and Expiration, Persistence, Distributing Caching, Partioned Data including a good image showing the difference for Nonpartitioned and Partitioned
Caching with Ehcache ends the chapter. Our Java code is rewritten to do the integration with CacheManager. Ehcache configuration is introduced too, where parts are well explained, and finally of course, using EhCache with Terracotta is included too, based in a Terracotta Configuration (tc-config.xml).
Chapter 6: Hibernate With Terracotta (Using Terracotta to Offload the Database)
Here the authors start with an introduction about Object-Relational Mapping, and about How Hibernate Work with good explanations for:
An image about all these together is available (Simplied Hibernate Architecture). After this a snippet code about a Typical Hibernate Invocation is offered.
Now the most important part of this chapter is about How Terracotta Improves Hibernate Performance, where the authors emphasise the Basic steps for improving performance of a Hibernate application based on these points
See that from originally making nine calls to apply these steps we get a good performance doing only two. These changes in call reduction are shown for each image of the previous points already mentioned.
Configuring Hibernate to Work with Terracotta shows a good amount of steps with code snippets for
Refactoring the application is mandatory for Configuring Terracotta for use with Detached Instances, where are covered through other many stepsChapter 7: Extending HTTP Sessions with Terracotta
Another important topic, starts with a concrete explanation about What are HTTP Sessions, including a good image about how a HTTP sesion state is managed by the application server on behalf of the web browser
Many subtopics are covered:
Distributed HTTP Sessions is almost pure theory and explains:
For the previous second point an interesting image is offered, about Session failover with Terracotta. Alternatives to HTTP Sessions which covers:
While Distributted HTTP Sessions with Terracotta covers:
Then the benefits are explained about, No Serialization, Rolling Upgrades, Fine-Grained Changes among others. An important image is offered about Terracota transparent object versioning works well when rolling web application changes into production
Source code is used in a section called Using Terracotta and HTTP Sessions, where a custom servlet class is used, therefore we can't forget the web.xml configuration. Then through many images the authors teach us how install and run the application with the Terracotta Sessions Configuration, the script sessions-configurator is used.
After that the authors even include other sample code about HTTP Sessions with Structured Sessions Attributes where now a JSP file is used together and related with an entity. Another Java class is shown to manipulate our entity. web.xml is included again but now empty for sample purposes and then for this example Terracotta Configuration is available through tc-config.xml, a special configuration with Tomcat/Terracotta is covered too and execution output is shown
To end the chapter the section Understanding HTTP Sessions with Terracotta is covered with supported Platforms, interesting list and Architecture Considerations.Chapter 8: Clustering Spring
The chapter starts very practically with code for a section called A Sample: Spring Beans Without a Database.
Now is the turn to run the original Java classes in the example Clustered with Terracotta. Until here Spring is not included in the sample application, so you get to read one page for Terracotta configuration with pure objects (nothing related with Spring is shown).
Now we are show how to work with Spring and Terracotta together. First a section called Growing Spring Beans is explained, the first thing to do is apply DI for our Java classes in the Spring Application Context Configuration file (nothing about clustering yet). This is then followed with Clustering Spring Beans where the authors offer us the Terracotta Spring Configuration file, this is covered in almost two pages - the most important thing is that such configuration is simpleChapter 9: Integration Modules
This chapter is about of TIM (Terracotta Integration Module), therefore Using TIMs is covers Importing, Modules repositories (maven), Terracotta Forge.
After this the section Creating a TIM is covered, about anatomy, creating manifest where its properties (for OSGi and Terracotta) are explained in a table, Terracota configuration (about Autolocks)
After of this Creating a Simple TIM is covered (without Maven) where many steps are indicated of course, if you are a maven user, after of this Creating TIMs with Maven is available where the mvn command is introduced and the project structured generated is shown in an image.
Now is turn to Include Code in a TIM, well this is based with OSGi, covered with Defining a Bundle Activator where code and jars need it are explained, Configuration with Code where a table for Helper Methods for Configuration Terracotta is available, Class Replacement and Modification is included too where here two tables for methods are available for StandardDSOClientConfigHelper and TerracottaConfigurationModule and a short Java class about Replacing a Class with your own implementation using TIMs
To end the chapter Using Maven to Create TIMs with Code is covered where a pom file is introduced and a table about Exportable Properties and Options for Maven-Based Builds is available.Chapter 10: Thread Coordination
This chapter starts quickly with Terracotta and Thread Coordination which comes in two flavors Coordination of access to data and Coordination of Activities. Both are explained, followed by an interesting image about Terracotta hooks into MONITORENTER and MONITOREXIT bytecodes
Now is the turn for Clustering Threads, where it is cover with four approaches:
The second is Thread Coordination Using the Java.util.concurrent Package, other Java class is used, which has two variables of type CyclicBarrier, the new version for tc-config.xml is shown with a reduction of configuration (i.e: instrumented-classes and transient-fields tags not appear anymore) now you can see the output of the execution for this type of coordination
The third type is Thread Coordination and JMX Cluster Events, it list and depicts many methods briefly, like nodeConnected,nodeDisconnected and other more robust like nodeInit, nodeConnecting among others, then a varion of the previous Java code is introduced (in this case with an extention of SimpleListener) and including many simple implementations of the nodexxx methods, almost three pages for this class, afterwards tc-config.xml is shown and furthermore you can see the output of the execution for this type of coordination again.
The last type is Thread Coordination with Queues, this part of the section start offering an important image about Depicting thread coordination with queues graphically, then almost four pages is used for our Java code where some variables are the type NamedQueue, AtomicInteger, and a new version for tc-config.xml is shown, no output about execution is available for this type of coordination.
What Are Grids, covers sub topics such as Compute Grids vs Data Grids, How Grids Handle Scalability and How Grids Handle Failover and High Availability.
Then Master/Worker in Java is covered now, expanding with pure theory for these subtopics
For the second previous point an image is included about of a relation for Master/Worker/SharedQueue
Following now we have Using the CommonJ Work Manager Specification, almost one page of theory about this following with one page of many code about Workxxx interfaces
Now is the turn for the storm of code, starting with the section Getting Started: Naive Single Work Queue Implementation which cover many subtopics
Second Clustering Our Master/Worker with Terracotta where snippet code for Terracotta Configuration is available for our previous Java classes, no execution output for this section
Now the authors offer the section Refactoring for Large Workloads, Routing, and Work Failover, fourteen pages of almost pure Java code for these critical topics. Another section called Refactoring Work Batching, Worker Failover, and Dynamic Worker Management shows a good amount of theory for Work Batching and Dynamic Worker Management and has six pages of Java code and explanation.
A pure theory section called When Not Use Master/Worker Pattern ends the chapter.Chapter 12: Visualizing Applications
The chapter starts quickly with the section Observing an Application including an image about Measurement points for application tunning, such points are OS,JVM,Terracotta Library and Application.
Visualization Tools and Architecture has a concrete theory and another interesting image about Terracotta cluster vizualization database architecture, followed by The Sample Inventory Application. If you recall in previous chapters it this application was cover and now we have a image about the relations. The Java classes are listed in a table and changed in Modifying to Generate Load section, through some pages you going to see snippet codes about these changes for:
For such sub sections you going to see images about Lock batching and other clever images about Using separate roots means there are two copies of inventory for isolating JVMs. Changes for Terracotta Configuration are included too, after this, compilation and execution steps are covered
After all these changes Taking Performance Snapshots section is covered now, some images about snapshot tool are included.
Now a new section is available about Potential Bottlenecks where an interesting and detailed image about Terracotta is analagous to SMP motherboard is available following with another important image about Administration console snapshot options where all the seventeen options are explained in little more of two pages
Other section is Inside the Terracotta Server where SEDA is covered and an interesting image about The SEDA stages inside of Terracotta server is available.
Practically to end the chapter the section Visualizing the Bottlenecks is offered where some important images about test runs, SEDA queues, Lock profiler among others are available and explained in a concrete way
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)