Top Banner
JCache (JSR107) David Brimley The standard for Java Caching
37
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: JCache -  It's finally here

JCache (JSR107)

David Brimley

The standard for Java Caching

Page 2: JCache -  It's finally here

Who is this guy?

Senior Solutions Architect @ Hazelcast

Java Developer for 17 years

@dbrimley

In Memory Data Grids for 8 years

Worked for Investment Banks

Started out coding Basic on a Commodore Vic-20

My fav computer was my old BBC Model B

Long suffering Spurs fan.

HSBC, Nomura, Credit Suisse, BZW, RBoS

Oracle Coherence 4 YearsPivotal Gemfire 4 Years

David Brimley

Runs HUGL (Hazelcast User Group London)

Low latency trading systems

Page 3: JCache -  It's finally here

What we’ll cover…• Why Caching? • Introduction to JCache. • Using Caches. • Entry Processors. • Listeners. • Annotations. • Missing Bits. • Questions.

Page 4: JCache -  It's finally here

Who uses caching?

Quick Show of hands

Page 5: JCache -  It's finally here

Why Caching?

Page 6: JCache -  It's finally here

Why Caching?The Speed Factor (Memory .v. Disk)

L1 cache reference 0.5 ns

Branch mispredict 5.0 ns

L2 cache reference 7.0 ns

Mutex lock/unlock 25.00 ns

Main memory reference 100.00 ns

Compress 1k bytes with ZupZ 3,000.00 ns

Send 1k bytes over 1Gpbs network 10,000.00 ns 0.01 ms

Read 4k randomly from SSD 150,000.00 ns 0.15 ms

Read 1 MB sequentially from memory 250,000.00 ns 0.25 ms

Round trip within same datacenter 500,000.00 ns 0.50 ms

Read 1 MB sequentially from SSD 1,000,000.00 ns 1.00 ms

Disk seek 10,000,000.00 ns 10.00 ms

Read 1 MB sequentially from disk 20,000,000.00 ns 20.00 ms

Send packet CA->Netherlands->CA 150,000,000.00 ns 150.00 ms

https://gist.github.com/jboner/2841832

Page 7: JCache -  It's finally here

Why Caching?

Graph of Memory Prices Decreasing with Time (1957-2014)

http://www.jcmit.com/mem2014.htm

The Cost Factor

Page 8: JCache -  It's finally here

Why Caching?Lots of Use Cases

Slow Database

HTTP Proxy

Browser

Persistence Framework

Disk

Application

Hard to scale Database

Lots of Cache Types

Local Cache Data Grid

Document Store JPA Second Level

JPA First Level

Page 9: JCache -  It's finally here

Introduction to JCache

Page 10: JCache -  It's finally here

Introduction to JCache• Caching for the Java Platform

• Produced via the JCP / JSR107

• Ratified March 2014

• 10 years in the making.

• Works with SDK.

• Spec Leads: Greg Luck, Brian Oliver

Page 11: JCache -  It's finally here

java.util.Map (Java 6/7)

Key-Value Based API

Supports Atomic Updates

Entries Don’t Expire

Entries Aren’t Evicted

Entries Stored On-Heap

Store-By-Reference

https://gist.github.com/jboner/2841832

Introduction to JCacheMap .v. Cache

javax.cache.Cache (Java 6)

Key-Value Based API

Supports Atomic Updates

Entries May Expire

Entries May Be Evicted

Entries Stored Anyware (ie: topologies)

Store-By-Value and Store-By-Reference

Supports Integration (ie: Loaders/Writers)

Supports Observation (ie: Listeners

Entry Processors

Statistics

Page 12: JCache -  It's finally here

JCache makes NO assumptions about

topology.

Single Process or Distributed

Introduction to JCache

Page 13: JCache -  It's finally here

Introduction to JCache

• JCP Project http://jcp.org/en/jsr/detail?id=107

• Source Code https://github.com/jsr107

• Forum https://groups.google.com/forum/?fromgroups#!forum/jsr107

Page 14: JCache -  It's finally here

JSR107 TCK Compliant Vendors

Introduction to JCache

https://jcp.org/aboutJava/communityprocess/implementations/jsr107/index.html

I pity the fool that claims to support JCache without

TCK compliance

As of 5th March 2015

Page 15: JCache -  It's finally here

Introduction to JCacheSomething to remember when comparing vendors of distributed caches…

Do NOT Benchmark with a single instance!

Page 16: JCache -  It's finally here

Using Caches

Page 17: JCache -  It's finally here

Using Caches

<dependency> <groupId>javax.cache</groupId> <artifactId>cache-api</artifactId> <version>1.0.0</version> </dependency>

Maven Central

Page 18: JCache -  It's finally here

Using CachesClasses

Caching “service loader”

CachingProvider “SPI Implementation”

CacheManager “manager of caches”

Cache “interface to a Cache”

Page 19: JCache -  It's finally here

Using CachesClasses

Code Walkthrough

Page 20: JCache -  It's finally here

Entry Processors

Page 21: JCache -  It's finally here

Entry ProcessorsCompute in place

• Atomic Operations in situ of data.• Eliminate Round-Trips (if distributed)

• Lock Free• Needs Serialisation (if distributed)

Application Application

Cache Cache

Page 22: JCache -  It's finally here

Entry ProcessorsClasses

Code Walkthrough

Page 23: JCache -  It's finally here

Listeners

Page 24: JCache -  It's finally here

ListenersCallbacks for events in Cache

• Follows Observer Pattern

• Interface per event type

• Created, Updated, Removed, Expired

• Iterations of Events passed back

• MutableCacheEntryListenerConfiguration

Page 25: JCache -  It's finally here

ListenersClasses

Code Walkthrough

Page 26: JCache -  It's finally here

Cache Loaders / Writers

Page 27: JCache -  It's finally here

Cache Loaders / WriterCache Misses / Cache Persist

Application

Cache

Backing Store

Page 28: JCache -  It's finally here

Cache Loaders / WriterClasses

Code Walkthrough

Page 29: JCache -  It's finally here

Annotations

Page 30: JCache -  It's finally here

AnnotationsSpring 4.1, Guice, CDI

• @CacheResult

• @CachePut

• @CacheRemove

• @CacheRemoveAll

Page 31: JCache -  It's finally here

AnnotationsClasses

Code Walkthrough

Page 32: JCache -  It's finally here

Missing Bits

Page 33: JCache -  It's finally here

Missing BitsThe Future of JCache

• Async API

• Query

• JEE 8

• Servlet 4.0 (Session Cache)

• Java 8 Lang Features (Lambda/Streams)

Page 34: JCache -  It's finally here

Questions ?

Page 35: JCache -  It's finally here
Page 36: JCache -  It's finally here

HAZELCAST• Free London Training • Hazelcast User Group• Visit our Booth

Visit our Booth 5th Floor Get Free Training (Canary Wharf, Thursday 12th March) http://hazelcast.com/events/

Join the Hazelcast User Group London (HUGL) http://www.meetup.com/Hazelcast-User-Group-London-HUGL/

Download Hazelcast, the leading open source IMDG http://www.hazelcast.org

Page 37: JCache -  It's finally here

THANK YOU.@dbrimley

[email protected]