high performance java ee with j cache and cdi
TRANSCRIPT
High-Performance Java EE with JCache and CDISteve Millidge – Founder Payara
Later Today
Java EE Microservice platforms -
which is best?
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
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
LATENCY
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
CachingCures
Latency
Idea for Testing
http://data.highways.gov.uk/ha-roadworks/he_roadworks_2016_02_29.xml
MySQLDB
HighwaysAgency
RESTMicroServiceComponent
REST Interface
/roadworks/roadworks/now/roadworks/{road}/now/roadworks/{region}/roadworks/{region}/now
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
Coding Interlude
What Just Happened?
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
Caching ConceptsCaching Provider
Cache Manager
Cache
Entry
Key
Value
Core Concepts• CachingProvider• Retrieves and closes Cache Managers
• CacheManager• Creates and destroys caches
• Cache• Contains Objects in Key Value Pairs
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.
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())
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
Coding Interlude
Payara CDI Extensions@NamedCache(cacheName = "cache”)@InjectCache cache;
@InjectCacheManager cm;
@InjectHazelcastInstance instance;
Additional JCache Capabilities
Entry ProcessorsApplication
Cache
Application
Cache
Application
Cache
Application
Cache
ProcessProcessProcessProcess
Cache Entry ListenersApplication
Cache
Application
Cache
Application
Cache
Application
CacheCacheListener
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.
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
Questions
Kentor are now sponsoring for Coffee break
WELCOME!