220 likes | 287 Views
Cluster Your JVM to SIMPLIFY application architecture. Terracotta, Inc. Goal of This Session. Learn how TRANSPARENT CLUSTERING works at a high level An in-depth look at clustering inside OSS stack. Shared Drawing Editor. Demo. Since a picture is worth a thousand words …. Agenda.
E N D
Cluster Your JVM to SIMPLIFY application architecture Terracotta, Inc.
Goal of This Session • Learn how TRANSPARENT CLUSTERING works at a high level • An in-depth look at clustering inside OSS stack
Shared Drawing Editor Demo Since a picture is worth a thousand words…
Agenda • Why Runtime Clustering • How Runtime Clustering Works • Our Implementation: Terracotta Architecture • Use what you need: OSS on Terracotta
Programming Should Be Fun • The moment of joy: • That’s awesome • I made that happen • Ergo, I’m awesome • Java used to be fun • Object oriented, built-in GUI, threading, networking, GC, and a VM • Lets you do awesome stuff
Inevitably, the Real World Intrudes • High-availability & scalability => scale-out • Scale-out forces externalized object state: stateless programming model • Alphabet soup of infrastructure development frameworks creep in • EJB, JMS, JDBC, SOAP, O/R… Ugh. That’s not awesome.
Impact of API-based Clustering • Scale-out solutions rely on Java Serialization • This breaks object identity • Data put into the cache and then read back will fail: • (obj == obj) false • Perturbs the Domain Model • Management of object references using primary keys • "Fake POJOs" • Adds new coding rules • Need to put() changes back - easy to forget • Can’t trust callers outside the caching class to put a top-level object back in the cache if they edited it • This is not as simple as the Java language can be
Managed Runtimes to the Rescue • Example: Memory Management • Remember malloc() and free(), heap vs. stack • The JVM introduced most developers to garbage collection, but compile-time used to win • Today, the JVM is faster; it decides what do do at runtime instead of at compile time • More information available at runtime • “…only 12 times faster than C means you haven't started optimizing” – Doug Lea • Other Java features that make Developers’ lives easier: • Platform-independent thread coordination / locking • Fat / thin locks in Jrockit decided at runtime • Platform specific optimizations
Clustering at Runtime…Stateful Applications: Code Like Your Mom Used to Make • TC lets you cluster Java in a natural fashion • No Serialization • No API No “cluster-aware” code creeping in The runtime can do it better than you • Byte Code Instrumentation • GETFIELD • PUTFIELD • MONITORENTER; • MONITOREXIT; • Object.wait() • Object.notify()
Capabilities Heap Level Replication - share almost any object graph ACID Replication - no new exceptions or error scenarios Central storage - keeps app state across restarts Comm. Hub - manage shared object comms w/o multicast or split brain Virtual Memory - page in objects on demand Coordination - We have extended our support to wait / notify and other useful tools Terracotta Architecture: Cluster w/o JEE Resources Scale-out App Server App Server App Server Web App Web App Web App Shared Objects Shared Objects Shared Objects JVM JVM JVM DSO Libraries DSO Libraries DSO Libraries Terracotta Server Clustering the JVM
HTTP Session clustering for HA + scalability Add-a-server capacity Efficient replication: no serialization, write only deltas and only where needed no need to tear objects apart into session attributes no "put-back"-- nothing to remember (and get wrong) at dev time No zipper-effect from very large sessions Clustered caches Write and update cache once, not N-times Eliminate the 1/N effect Choose an existing cache implementation or use your own, Terracotta clusters underneath Clustered POJOs Clustered Spring Collaboration / Coordination / Eventing Distributed work management Shared Memory / Large Virtual Memory Fundamentally open-ended Wherever thread communication across JVMs and an unlimited, efficiently replicated heap is useful Common Use-cases
DEMO 2 Geronimo HTTP Session Clustering Shared JTable (spreadsheet) Inside Geronimo
Entire Swing Application package demo.jtable; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.table.DefaultTableModel; class TableDemo extends JFrame { // Shared object private DefaultTableModel model; privatestatic Object[][] tableData = { { " 9:00", "", "", ""}, { "10:00", "", "", ""}, { "11:00", "", "", ""}, { "12:00", "", "", ""}, { " 1:00", "", "", ""}, { " 2:00", "", "", ""}, { " 3:00", "", "", ""}, { " 4:00", "", "", ""}, { " 5:00", "", "", ""} }; TableDemo() { super("Table Demo"); setSize(350, 220); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Object[] header = {"Time", "Room A", "Room B", "Room C"}; model = new DefaultTableModel(tableData, header); JTable schedule = new JTable(model); getContentPane().add(new JScrollPane(schedule), java.awt.BorderLayout.CENTER); } publicstaticvoid main(String[] args) { new TableDemo().setVisible(true); } }
Web Application: Root Declaration package demo.jtable; import javax.swing.table.DefaultTableModel; publicclass Roots { // shared root privatestaticfinal DefaultTableModel model; // … initialization publicstatic DefaultTableModel getModel() { returnmodel; } }
Web Application: Table Rendering publicclass Table { privatefinal DefaultTableModel model; // … initialization public String toString() { StringBuffer buf = new StringBuffer(); Vector<Vector<String>> dataVector = this.model.getDataVector(); buf.append("<table border=\"" + this.border + "\">\n"); synchronized (dataVector) { buf.append(" <tr>\n"); for (int i = 0; i < this.model.getColumnCount(); i++) { buf.append(" <th>").append(this.model.getColumnName(i)).append("</th>\n"); } buf.append(" </tr>\n"); for (Iterator<Vector<String>> i = dataVector.iterator(); i.hasNext();) { buf.append(" <tr>\n"); Vector<String> data = i.next(); for (Iterator<String> j = data.iterator(); j.hasNext();) { buf.append(" <td>"); buf.append(j.next()); buf.append("</td>\n"); } buf.append(" </tr>\n"); } } buf.append("</table>"); return buf.toString(); } }
Web Application: JSP <%@ page language="java" import="demo.jtable.Roots" pageEncoding="ISO-8859-1"%> <%@ page language="java" import="demo.jtable.web.Table"%> <html> <head> <title>Open Terracotta JTable</title> </head> <body> <h1>JTable</h1> <% Table table = new Table(Roots.getModel()); table.setBorder(1); %> <%=table%> </body> </html>
Configuration File <terracotta-config> <dso> <server-host>localhost</server-host> <server-port>9510</server-port> <dso-client> <roots> <root> <field-name>demo.jtable.Main.model</field-name> <root-name>demo_jtable_model</root-name> </root> <root> <field-name>demo.jtable.Roots.model</field-name> <root-name>demo_jtable_model</root-name> </root> </roots> <included-classes> <include><class-expression>demo..*</class-expression></include> </included-classes> <web-applications> <web-application>Cart</web-application> </web-applications> </dso-client> </dso> </terracotta-config>
Stateful Model in a Stateless World • Hub and Spoke as a SPOF? • Field-level changes too chatty? • Networking overhead to clustering?
Stateful Model in a Stateless World • Hub and Spoke scale the hub • Field-level changes batched • Network overhead runtime optimized
Stateful Model in a Stateless World • Simple programming model • Clustered code looks, acts, and smells like regular Java • Testable • Scale-out: high-availability AND scalability • Jettison the traditional trade-offs between simplicity, reliability, and scalability • The power of Terracotta makes programming fun-- increases the frequency of moments of joy
Learn more… • http://www.terracotta.org/ • http://blog.terracottatech.com/ • http://apache.geronimo.com/
Summary • Infrastructure services are the responsibility of the Runtime, not the developer • New API’s and developer frameworks are not the answer • Technology exists to cluster and cache transparently today • Terracotta works in Geronimo (beta), Tomcat, Weblogic, JBoss (beta), WebsphereCE (beta), and standalone Java apps • Coming soon: Jetty (by JavaOne), Glassfish, Websphere • Scale lightweight stacks: Spring, iBATIS, RIFE, Wicket, Struts, OSCache, Ehcache...