building highly scalable spring applications using in-memory data grids
TRANSCRIPT
SPRINGONE2GXWASHINGTON, DC
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/l icenses/by-nc/3.0/
Building Highly Scalable Spring Applications using In-Memory Data Grids
By John Blum & Luke Shannon@john_blum
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/l icenses/by-nc/3.0/ 2
Presenters
John Blum - @john_blumSpring Data GemFire Project LeadApache Geode CommitterGemFire Engineer/Technical LeadPivotal Software, Inc
Luke ShannonField/Community EngineerApache Geode CommitterPivotal Software, Inc.
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/l icenses/by-nc/3.0/ 3
Agenda• Introduction to Apache Geode
• Distributed System & In-Memory Database Concepts
• Overview of Spring Data GemFire• How to build highly scalable applications
• Spring Data GemFire in Action• Fast Foot Shoes Demo• Caching Demo (?)
• What’s New
• QA
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/l icenses/by-nc/3.0/ 4
Why Apache Geode?Motivation…1. Volume of Data (Big Data)2. Velocity of Data (Fast Data)3. Verity of Data (Data Accuracy)
Enables new and existing Spring applications to operate at cloud-scale in a consistent, highly-available and predictable manner in order to transact and analyze big, fast data in real-time thereby achieving meaningful and impactful business results.
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/l icenses/by-nc/3.0/ 5
What is Apache Geode?In a nutshell…
• Open Source core of Pivotal GemFire• https://pivotal.io/big-data/pivotal-gemfire
• Apache Incubator project• https://wiki.apache.org/incubator/GeodeProposal• http://geode.incubator.apache.org/
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/l icenses/by-nc/3.0/ 6
What is Apache Geode?
“A distributed, in-memory compute and data management platform that elastically scales to achieve high-throughput, low-latency access to big, fast data powering business critical, analytical applications in real-time.” – John Blum,
Elastic capacity +/-
Nodes
Ops / SecLinear scalability
Latency optimizeddata distribution
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/l icenses/by-nc/3.0/ 7
Apache Geode Use Cases• Persistent, OLTP/OLAP Database (System of Record)• JSR-107 Cache Provider (Key/Value Store)• HTTP Session State Management• Distributed L2 Caching for Hibernate• Memcached Server (Gemcached)• Message Bus with guaranteed message delivery• Glorified version of ConcurrentHashMap
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/l icenses/by-nc/3.0/ 8
China Railway Corporation
GemFire runs on ten primary x86 servers with over two terabytes of memory and there are ten backup servers – this has replaced the 72 UNIX boxes and traditional RDBMS with a more efficient, cost-effective approach.
With so many people relying on the website for travel, it must be continuously available. Demand has far exceeded expectations and the future shows as much as 50% growth per year as mobile phone access is added.
https://pivotal.io/big-data/case-study/scaling-online-sales-for-the-largest-railway-in-the-world-china-railway-corporation
China Railway Corporation
• 20 million users per day; 40,000 visits per second
• 4.5 million ticket purchases &.• Spikes of 15,000 tickets sold per
minute
“The system is operating with solid performance and uptime. Now, we have a reliable, economically sound production system that supports record volumes and has room to grow”
Dr. Jiansheng Zhu, Vice Director of China Academy of Railway Sciences
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/l icenses/by-nc/3.0/ 9
How Apache Geode Works• Stores data In-Memory
• JVM Heap + Off-Heap• Functions as a Distributed System, In-Memory Data Grid (IMDG)
• Pools system resources across multiple nodes in a cluster to manage both application state and behavior
• Includes: Memory, CPU, Network & (optionally) Disk
• (optional) Stores data to Disk• In OPLOGS | HDFS for Overflow & Persistence
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/l icenses/by-nc/3.0/ 10
Memory ManagementApache Geode manages memory using…• Eviction: LRU• Expiration: Time-To-Live (TTL), Idle Timeout (TTI)• Auto resource management: critical/eviction HEAP % thresholds• (Region) Data Compression: Snappy• JVM/GC Tuning
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/l icenses/by-nc/3.0/ 11
Where to begin?
Data NodeData Node
Application
What about load?
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/l icenses/by-nc/3.0/ 12
Where to begin?
Data Node
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/l icenses/by-nc/3.0/ 13
Where to begin?
Locator
High read throughput What about writes?
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/l icenses/by-nc/3.0/ 14
Where to begin?
Locator
Partition
XYZ
Partition
XYZPartitio
n
ABC
Partition
ABC
High read/write throughput
What about consistency?
Partition
XYZ
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/l icenses/by-nc/3.0/ 15
Partition Region
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/l icenses/by-nc/3.0/ 16
Where to begin?
Locator
Partition
XYZ
Partition
XYZ
Partition
ABC
Partition
ABC Partitio
n
XYZ
Partition
ABC
Partition
XYZ
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/l icenses/by-nc/3.0/ 17
Network Partition Resolution
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/l icenses/by-nc/3.0/ 18
Apache Geode Topologies
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/l icenses/by-nc/3.0/ 19
Summary of Apache Geode• Open Source• In-Memory• Distributed• Scalable (scale-out)• High Throughput & Low/Predictable Latency• Highly Available• Consistent• Durable• Fault Tolerant (resilient)• Data-Aware / Parallel Compute
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/l icenses/by-nc/3.0/ 20
Other Features of Apache Geode• Data Serialization (PDX, Java Serialization)• Delta Propagation• Transactions (Local & Global JTA-based TX)• Querying (OQL) + Continuous Queries• Functions (Stored Procedures)• Native Client Support (C#/C++)• REST API• Management & Monitoring (JMX with Gfsh & Pulse)• Security (Auth, Secure Transport with SSL, No Encryption)• Statistics & Logging (Log4j)
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/l icenses/by-nc/3.0/ 21
Spring Data GemFire
22
“Simple things should be simple; complex things should be possible”
– Alan Kay
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/l icenses/by-nc/3.0/ 23
Spring Data GemFire (SDG)Applies Spring's powerful, non-invasive programming model to simplify configuration and development of Apache Geode applications.
Spring Ecosystem Integration– Spring Cache Abstraction / Transaction Management– Spring Data Commons + REST– Spring Integration (Inbound/Outbound Channel Adapters)– Spring Session (coming soon)– Spring XD (Sources & Sinks)
24
Apache Geode with Spring Data GemFire and Spring’s Cache Abstraction is a JSR-107 (JCache) caching provider
+ +
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/l icenses/by-nc/3.0/ 25
Spring Data GemFire Use Cases• Configure & Bootstrap Apache Geode
– Replacement for cache.xml; Can be used with Cluster Configuration
• Build an Application Peer Cache (Cache)– Embedded Cache
• Build an Application Cache Client (ClientCache)– Client/Server
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/l icenses/by-nc/3.0/ 26
Spring Data GemFire Features• Pivotal GemFire / Apache Geode Configuration & Bootstrapping• Spring Data Repositories
• CRUD + Querying (OQL) + (basic) POJO Mapping• Annotated-based Function Implementation / Execution• Transaction Management with Spring Transaction Infrastructure• Exception Translation into Spring DAO Exception Hierarchy• Register Interests & Continuous Querying Support• JSON Region Proxies• Data Snapshots Imports/Exports• Client/Server Applications• WAN Architecture Support• GemFire / Geode caching provider support in Spring’s Cache Abstraction
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/l icenses/by-nc/3.0/ 27
Spring Data GemFire / Apache Geode Coordinates
<repository> <id>spring-libs-snapshot</id> <name>Spring Maven libs-snapshot Repository</name> <url>https://repo.spring.io/libs-snapshot</url></repository>
<dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-gemfire</artifactId> <version>1.7.0.APACHE-GEODE-EA-SNAPSHOT</version></dependency>
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/l icenses/by-nc/3.0/ 28
Configuration & Bootstrapping
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/l icenses/by-nc/3.0/ 29
Configuring Apache Geode with SpringXML Java-based Configuration
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/l icenses/by-nc/3.0/ 30
Bootstrapping Apache Geode with Spring@SpringBootApplication@ImportResource("/spring-gemfire-context.xml")public class SpringGemFireApplication { public static void main(String[] args) { SpringApplication.run(SpringGemFireApplication.class, args); }}
gfsh>start server -–name=Example --spring-xml-location= <classpath-to-spring-application-context.xml>
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/l icenses/by-nc/3.0/ 31
EXAMPLE
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/l icenses/by-nc/3.0/ 32
Spring Data GemFire in ActionFast Foot Shoes Demo
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/l icenses/by-nc/3.0/ 41
Caching
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/l icenses/by-nc/3.0/
Spring Cache Abstraction
Caching is useful in cases when an “expensive” operation (i.e. CPU, IO bound) produces the same output given identical input; results can be reused.
Spring enables Declarative, Annotation-based Caching…
@Cacheable – triggers cache population
@CacheEvict – triggers cache eviction
@CachePut – updates cache without interfering with method execution
@Caching – groups multiple cache operations per method
@CacheConfig – class-level cache-related settings
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/l icenses/by-nc/3.0/
Spring Supports JSR-107 (JCache)Spring JCache@Cacheable @CacheResult
@CachePut @CachePut
@CacheEvict @CacheRemove
@CacheEvict(allEntries=true) @CacheRemoveAll
@CacheConfig @CacheDefaults
http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#cache-jsr-107
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/l icenses/by-nc/3.0/
Apache Geode Caching Provider@Configuration@EnableCaching@Import(GemFireConfiguration.class)class ApplicationConfiguration {
@Bean public CacheManager cacheManager( Cache gemfireCache) {
GemfireCacheManager cacheManager = new GemfireCacheManager();
cacheManager.setCache(gemfireCache);
return cacheManager; }}
<beans … xmlns:cache=“http://www.springframework.org/schema/cache”…>
<gfe:cache properties-ref="gemfireProperties"/>
<cache:annotation-driven/>
<bean id="cacheManager" class= ”o.s.data.gemfire.support.GemfireCacheManager"
p:cache-ref="gemfireCache"/>
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/l icenses/by-nc/3.0/ 45
EXAMPLE
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/l icenses/by-nc/3.0/ 46
What’s New – Annotation-based Expiration@TimeToLiveExpiration(timeout=“@expirationSettings[‘spel-defined-timeout’]”, action=“DESTROY”)@IdleTimeout(timeout=“300”, action=“${property.placeholder.defined.action}”)class ApplicationDomainObject { .. }
<gfe:partitioned-region id="Example" persistent="false"> <gfe:custom-entry-ttl> <bean class=“org.springframework.data.gemfire.support.AnnotationBasedExpiration” factoryMethod=“forTimeToLive”/> </gfe:custom-etnry-ttl> <gfe:custom-entry-tti ref="ttiExpiration"/></gfe:partitioned-region>
<bean id="ttiExpiration" class=”….AnnotationBasedExpiration” factory-method="forIdleTimeout"> <constructor-arg ref="defaultExpirationAttributes"/></bean>
<bean id="defaultExpirationAttributes" class="com.gemstone.gemfire.cache.ExpirationAttributes"> <constructor-arg value="600"/> <constructor-arg value="#{T(com.gemstone.gemfire.cache.ExpirationAction).DESTROY}"/></bean>
http://docs.spring.io/spring-data-gemfire/docs/current/reference/html/#bootstrap:region:expiration:annotation
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/l icenses/by-nc/3.0/ 47
What’s New – Annotation-based OQL extensionsinterface CustomerRepository extends GemfireRepository<Customer, Long> {
@Trace @Limit(25) @Import(“org.example.app.domain.Customer”) @Hint({ “CustomerIdIdx”, “CustomerLastNameIdx” }) List<Customer> findByLastName(String lastName);
}
http://docs.spring.io/spring-data-gemfire/docs/current/reference/html/#gemfire-repositories.oql-extension
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/l icenses/by-nc/3.0/ 48
What’s New – Data Snapshot Imports/Exports<gfe:cache/>
<gfe:partitioned-region id=“Users” persistent=“true” … /><gfe:partitioned-region id=“GuestUsers” persistent=“false” … />
<gfe-data:snapshot-service id=“cacheSnapshotService”> <gfe-data:snapshot-import location=“/path/to/users.zip”/> <gfe-data:snapshot-export location=“/path/to/snapshot/directory”/></gfe-data:snapshot-service/>
<gfe-data:snapshot-service id=“guestUsersSnapshotService” region-ref=“GuestUsers”> <gfe-data:snapshot-import location=“/path/to/users.snapshot”> <bean class=“example.GuestUsersSnapshotFilter”/> </gfe-data:snapshot-import> <gfe-data:snapshot-export location=“/path/to/activeUsers.snapshot” filter-ref=“activeUsersFilter”/></gfe-data:snapshot-service>
http://docs.spring.io/spring-data-gemfire/docs/current/reference/html/#bootstrap:snapshot
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/l icenses/by-nc/3.0/
Presentation References Presentation Slides - http://www.slideshare.net/john_blum
Configuration / Bootstrapping & Caching Example Source Code - https://github.com/jxblum/scalable-spring-gemfire
Fast Foot Shoes Example Source Code - https://github.com/Pivotal-Open-Source-Hub/geode-demo-application
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/l icenses/by-nc/3.0/
Apache Geode References Project Page - http://geode.incubator.apache.org/contribute/
Community Events - http://geode.incubator.apache.org/community/
Contribute - http://geode.incubator.apache.org/contribute/– Ideas - https://cwiki.apache.org/confluence/display/GEODE/How+to+Contribute
Documentation - http://geode.incubator.apache.org/docs/– Docs Project - https://github.com/project-geode/docs
Source Code - https://github.com/apache/incubator-geode
JIRA - https://issues.apache.org/jira/browse/GEODE
StackOverflow - http://stackoverflow.com/questions/tagged/gemfire+and+geode
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/l icenses/by-nc/3.0/
Spring Data GemFire References Project Page - http://projects.spring.io/spring-data/
Documentation –– Reference Guide - http://docs.spring.io/spring-data-gemfire/docs/current/reference/html/– API - http://docs.spring.io/spring-data-gemfire/docs/current/api/– Spring IO Guides - http://spring.io/guides– Spring GemFire Examples –
Source Code - https://github.com/spring-projects/spring-data-gemfire
Examples - https://github.com/spring-projects/spring-gemfire-examples
JIRA – https://jira.spring.io/browse/SGF
StackOverflow - http://stackoverflow.com/questions/tagged/spring-data-gemfire
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/l icenses/by-nc/3.0/ 52
Boot Your Search with Spring12:45 – 14:15 - Salon M - Christoph Strobl
Learn More. Stay Connected.
@springcentral Spring.io/video
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/l icenses/by-nc/3.0/ 53
Spring Data REST – Data Meets Hypermedia + Security14:30 – 16:00 – Salon M – Roy Clarkson & Greg Turnquist
Learn More. Stay Connected.
@springcentral Spring.io/video
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/l icenses/by-nc/3.0/ 54
Questions
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/l icenses/by-nc/3.0/ 55
Thank You