high performance java ee with j cache and cdi

27
High-Performance Java EE with JCache and CDI Steve Millidge – Founder Payara

Upload: payara

Post on 12-Jan-2017

814 views

Category:

Software


3 download

TRANSCRIPT

Page 1: High performance java ee with j cache and cdi

High-Performance Java EE with JCache and CDISteve Millidge – Founder Payara

Page 2: High performance java ee with j cache and cdi

Later Today

Java EE Microservice platforms -

which is best?

Page 3: High performance java ee with j cache and cdi

What is a Microservice?In computing, microservices is a software architecture style in which complex applications are composed of small, independent processes communicating with each other using language-agnostic APIs.

Wikipedia

Page 4: High performance java ee with j cache and cdi

Fallacies of Distributed Computing

1.The network is reliable.2.Latency is zero.3.Bandwidth is infinite.4.The network is secure.5.Topology doesn't change.6.There is one administrator.7.Transport cost is zero.8.The network is homogeneous.

Wikipedia

Page 5: High performance java ee with j cache and cdi

LATENCY

Page 6: High performance java ee with j cache and cdi

LatencyTechnology Latency Transfer Rate

DRAM 10s Nanos 120GB/s

SSD 0.1ms 600MB/s

Hard Disc 10ms 200MB/s

1Gb Ethernet Local :50 microsLan Segment:300 microsSwitch4 msWithin UK30 msUK <-> USA100ms

25 – 30 MB/s

Page 7: High performance java ee with j cache and cdi

CachingCures

Latency

Page 8: High performance java ee with j cache and cdi

Idea for Testing

http://data.highways.gov.uk/ha-roadworks/he_roadworks_2016_02_29.xml

Page 9: High performance java ee with j cache and cdi

MySQLDB

HighwaysAgency

RESTMicroServiceComponent

REST Interface

/roadworks/roadworks/now/roadworks/{road}/now/roadworks/{region}/roadworks/{region}/now

Page 10: High performance java ee with j cache and cdi

What is Payara Micro• Small Footprint Java EE Runtime• Supports Java EE Web Profile• Embeds JCache Support• Auto clusters using Hazelcast• Fully Embeddable API• Later today compare with SpringBoot, WildFly

Swarm

java –jar payara-micro.jar –deploy test.war

Page 11: High performance java ee with j cache and cdi

Coding Interlude

Page 12: High performance java ee with j cache and cdi

What Just Happened?

Page 13: High performance java ee with j cache and cdi

JCACHE

• Standard Java API for Caching• JSR107

• API and CDI binding• Supported by Many Cache Providers• Hazelcast, EhCache, Coherence, Infinispan, Apache Ignite

• Built in to Payara Server• Uses Hazelcast

Page 14: High performance java ee with j cache and cdi

Caching ConceptsCaching Provider

Cache Manager

Cache

Entry

Key

Value

Page 15: High performance java ee with j cache and cdi

Core Concepts• CachingProvider• Retrieves and closes Cache Managers

• CacheManager• Creates and destroys caches

• Cache• Contains Objects in Key Value Pairs

Page 16: High performance java ee with j cache and cdi

Magic Behind @CacheResult

• CDI Interceptor • Obtains CacheManager from CachingProvider• Creates Cache Name (Based on Method)• Looks up Cache in CacheManager• Takes Method Parameter Values and creates Cache Key• Does Cache.get before invoking method• If not in cache invokes method and does cache.put on

the result.

Page 17: High performance java ee with j cache and cdi

CachingProvider cp = Caching.getCachingProvider();

CacheManager cm = cp.getCacheManager();

MutableConfiguration<String, Stock> config = new MutableConfiguration<>();

config.setStoreByValue(true).setTypes(String.class,String.class).setManagementEnabled(true).setStatisticsEnabled(true);

Cache<String, String> cache = cm.createCache(“PizzaCache", config);String key = createKey();Cache.put(“Key”,methodCall())

Page 18: High performance java ee with j cache and cdi

Further CDI• @CacheResult• Caches the result of a method call

• @CachePut• Cache a specific method parameter

• @CacheRemove• Removes a cache entry based on parameters

• @CacheRemoveAll• Removes all entries in the cache

Page 19: High performance java ee with j cache and cdi

Coding Interlude

Page 20: High performance java ee with j cache and cdi

Payara CDI Extensions@NamedCache(cacheName = "cache”)@InjectCache cache;

@InjectCacheManager cm;

@InjectHazelcastInstance instance;

Page 21: High performance java ee with j cache and cdi

Additional JCache Capabilities

Page 22: High performance java ee with j cache and cdi

Entry ProcessorsApplication

Cache

Application

Cache

Application

Cache

Application

Cache

ProcessProcessProcessProcess

Page 23: High performance java ee with j cache and cdi

Cache Entry ListenersApplication

Cache

Application

Cache

Application

Cache

Application

CacheCacheListener

Page 24: High performance java ee with j cache and cdi

Summary• Use caching to defeat latency• JCache standard api for caches• Using JCache on Payara is simple

• Jcache, Hazelcast and CDI are built in

• Build micro-services with distributed caching on Payara Micro• Hazelcast Provides Performance, Resilience and Scalability• JCache also provides Data Grid capabilities like compute

and events.

Page 25: High performance java ee with j cache and cdi

More Info• https://jcp.org/en/jsr/detail?id=107

• JSR 107 Jcache specification

• http://www.payara.fish• Payara information and downloads

• http://www.hazelcast.com• Get Hazelcast

• https://github.com/smillidge/JDays2016• Code for this talk

• https://github.com/payara/Payara-Examples/tree/master/rest-examples/rest-jcache• Example key value store

• https://github.com/payara/Payara-Examples/tree/master/JCache-Examples• Further JCache on Payara Examples

Page 26: High performance java ee with j cache and cdi

Questions

Page 27: High performance java ee with j cache and cdi

Kentor are now sponsoring for Coffee break

WELCOME!