High-Performance Java EE
with JCache and CDI
Steve 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
Latency
Technology Latency Transfer Rate
DRAM 10s Nanos 120GB/s
SSD 0.1ms 600MB/s
Hard Disc 10ms 200MB/s
1Gb Ethernet Local :
50 micros
Lan Segment:
300 micros
Switch
4 ms
Within UK
30 ms
UK <-> USA
100ms
25 – 30 MB/s
Caching
Cures
Latency
Idea for Testing
http://data.highways.gov.uk/ha-
roadworks/he_roadworks_2016_02_29.xml
MySQL
DB
Highways
Agency
REST
MicroService
Component
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 Concepts
Caching
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”)
@Inject
Cache cache;
@Inject
CacheManager cm;
@Inject
HazelcastInstance instance;
Additional JCache Capabilities
Entry Processors
Application
Cache
Application
Cache
Application
Cache
Application
Cache
ProcessProcessProcessProcess
Cache Entry Listeners
Application
Cache
Application
Cache
Application
Cache
Application
CacheCache
Listener
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!

High performance java ee with j cache and cdi

Editor's Notes

  • #23 Moves the processing the the data not the other way around! Much more efficient and the processor will likely have a small amount of data associated with it whereas the cache size may be very large!
  • #24 Used for Chat Could be used for new trades for a trader or bids or offers on a security Asynchronous notification Management