SlideShare a Scribd company logo
Building Low Latency Java Applications with
Ehcache
Dhruv Kumar
Software Engineer, Terracotta Inc.
Dhruv.Kumar@terracottatech.com
Why In-Memory?
2
3
Data Center Machines
3
4
Data Center Machines
4
5
Data Center Machines
5
6
Memory Capacity Trends
6
7
Disk Capacity Trends
7
8
SSD Capacity Trends
8
9
CPU Speed Trends
9
10
Network I/O Trends
10
11
Memory Throughput Trends
11
12
SSD Throughput Trends
12
13
Disk Throughput Trends
13
14
Trend Summary
14
15
Trend Summary
15
§  Storage is cheap and increases exponentially
§  Most transfer rates increase exponentially except
disk throughput.
–  Gap between disk capacity and transfer rate is increasing
§  Accessing disk is very slow: transferring 100GB
@ 100 MB/s takes 1000s, or approx. 17 minutes.
–  Will get worse, as 512GB/node RAM will be common in 2
years.
–  Faster to access Network Attached Memory!
–  SSDs still not common due to unfavorable price performance
16
In-Memory Computing Opportunity
16
§  256 GB RAM * 4 nodes = 1 TB In-Memory Cluster
§  1 TB can hold many large datasets: 1 billion users
@ 1 KB each
§  Number of CPU cores double every 24 months:
memory/core increases exponentially
§  Bottomline: judiciously using RAM is key.
Ehcache System Architecture
17
18
Terracotta Server Array
Scale with Data and Processing Needs
18
BigMemory
App Server
Ehcache
App Server
Ehcache
Traditional
3-Tier Architecture
Scale Vertically Scale Horizontally
Elastic Scale
In the Cloud
App Server
Ehcache
Quartz
App Server
Ehcache
Quartz
Database
Database
Database
Database
App Server
Ehcache
App Server
Ehcache
BigMemory
Terracotta Server Array
BigMemory
Increase Data in Memory
Reduce Database Reliance
19
Hello Ehcache!
Database
Traditional
3-Tier Architecture
App Server
Ehcache
§  Reduction in database reliance
–  Store repetitively used data and access them
in memory speeds
§  Reduction of new objects created
–  Stored objects will be reused constantly thus
reducing the creation of new objects
§  Less network traffic
–  Stored data is already at the application layer
so no need to make a network call to get it
§  Reduce CPU usage
–  Objects in cache are already in the format you
need for use, no additional marshaling needed.
20
Example Configuration
Configuration via Ehcache.xml
20
Example Configuration
<ehcache>!
!
<cache name=”UserPreferencesCache"!
maxElementsInMemory="10000"!
timeToIdleSeconds="300”!
! ! !memoryStoreEvictionPolicy="LRU”/>!
!
<cache name=”ShoppingCartCache"!
maxElementsInMemory=”2500"!
timeToLiveSeconds=”6000”!
! ! !memoryStoreEvictionPolicy=”LFU"/>!
!
</ehcache>!
20
21
Simple API
21
Example Code
public Object testCache(String key) throws Exception {!
!CacheManager cacheManager = !
! !new CacheManager( “<path to my ehcache.xml>”);!
!Cache myCache = cacheManager.getCache("MyCache");!
!Object value;!
! !!
!Element element = myCache.get(key);!
!if (element == null) {!
! !value = "go get it from somewhere like DB or service,
! ! ! etc";!
! !myCache.put(new Element(key, value));!
!} else {!
! !value = (Object) element.getValue();!
!}!
! !!
!return value;!
}!
22
Ehcache Search
§  Intuitive, full-featured Search API
§  Fast, efficient implementation
§  Make cache searchable, then specify attributes
22
<cache name=”peopleCache”>
<searchable>
<searchAttribute name="age" expression="value.getAge()"/>
<searchAttribute name="gender" expression="value.getGender()"/>
</searchable>
</cache>
Example: Search for 32-year-old males
results = cache.createQuery().includeKeys()
.addCriteria(age.eq(32)).and (gender.eq("male"))
.execute();
Example Configuration and Code
23
Ehcache Search Using SQL-like Syntax
§  Can also search Ehcache using a SQL like syntax
§  String Queries mapped to Ehcache Search API
23
Example: Search for 32-year-old males
results = cache.createQuery().includeKeys()
.addCriteria(age.eq(32)).and (gender.eq("male"))
.execute();
// or using Ehcache Query Language
QueryManager qm = (new QueryManagerBuilder()).addEhcache(peopleCache).build();
String statement = “select age, gender from peopleCache
where age = 32 and gender =‘male’;”
results = qm.createQuery(statement).end().execute();
Example Configuration and Code
24
Ehcache Persistence
§  Persist actions in a log-append store (Fast Restart Store).
§  Each mutate operation is recorded. Optionally synchronous.
§  On restart, Ehcache entries and Index data are reconstructed from the
log.
24
Example ConfigurationExample Configuration
<ehcache>!
<cache name=”UserPreferencesCache"!
maxElementsInMemory="10000"!
timeToIdleSeconds="300”!
! ! persistenceStrategy=“localRestartable”>!
</ehcache>!
25
In-memory Data and Speed
25
Milliseconds
App Response Time
Microseconds
App Response Time
Memory
90% of Data in
Database
Database
90% of Data in
Memory
26
Storing Data away from Java Heap
(BigMemory)
Off-heap memory allocator. Uses NIO
DirectByteBuffers.
Bypasses Java Garbage Collection.
Only Serializable keys and values can be
placed in Off-heap.
Pure Java implementation compatible with
all popular JVMs
Requires no changes to application code,
JVM or OS
26
Database
Vertical Scaling
App Server
Ehcache
BigMemory
27
BigMemory Configuration
<ehcache>
<cache name= UserPreferencesCache"
maxBytesOnHeap=”512M"
timeToIdleSeconds="300
!memoryStoreEvictionPolicy="LRU
!overflowToOffHeap="true
! !maxBytesOffHeap= 30G"/>
<cache name= ShoppingCartCache"
maxElementsInMemory= 2500"
timeToLiveSeconds= 6000
!memoryStoreEvictionPolicy="LFU"/>
</ehcache>!
27
Example Configuration
28
Testing Offheap Performance
28
• Public URL:
http://svn.terracotta.org/svn/forge/offHeap-test/
• Our Configuration: Six 4-core Xeon CPUs @ 2.93
GHz, 128 GB RAM, RHEL 5.1, Sun JDK 1.6.0_21
in 64 bit mode.
• Load the cache and then run 50 threads doing
90% Read (get() call) calls and 10 % Writes (put()
call)
• Run in Heap and Offheap, and compare GC
duration, latency, throughput.
29
Offheap Perf Test: Garbage Collection Pauses
29
30
Offheap Perf Test: Maximum Latency
30
31
Offheap Perf Test: Mean Latency
31
Distributed
Ehcache
32
3333
Distributed Applications
Consistency?
3434
Distributed Ehcache using Terracotta Server
Array
§  Stateful Server Array
§  Synchronous TCP based connections to
clients
§  Highly Available using Master Slave
replication
§  Linear Scale Out Characteristics
§  Persistent
§  Various consistency optionsDatabase
Scale Out
App Server
Ehcache
Terracotta Server Array
BigMemory
App Server
Ehcache
35
Terracotta Server Array
35
Terracotta
ServerArray
Stripe
Pure Java
cache server on
commodity HW
Transactional
updated mirror for
high availability
Stripe
Commodity Server
Application
Terracotta Driver
Stripe Stripe Stripe Stripe
Commodity Server
Application
Terracotta Driver
Commodity Server
Application
Terracotta Driver
TCP
§ Durability
§ Mirroring
§ Striping
§ Developer Console
§ Plug-in Monitoring
§ Operations Center
Commodity Server
Disk
Active
Server
Commodity Server
Disk
BigMemory
Mirror
BigMemory
36
Example Configuration
Configuring Ehcache to use Terracotta
36
<ehcache>
!<terracottaConfig url="someserver:9510"/>
!<cache name= UserPreferencesCache
! !maxElementsInMemory="10000
! !timeToIdleSeconds= 300 />
!<cache name= ShoppingCartCache"
! !maxElementsInMemory= 25000"
! !timeToLiveSeconds= 6000 />!
!<terracotta />
</ehcache>!
Simply change two lines of configuration
37
Tiered Storage
In-Memory
Tiered Data Storage
37
Terracotta Heap
Heap
Store
BigMemory
Off-Heap Store
2,000,000+
1,000,000
100,000
2
1,000
10,000+
Speed (TPS)
1,000s
Size (GB)
External Data Source
(e.g., Database)
Terracotta Offheap
38
Example Configuration
Consistency options in TSA
38
Strongly
Consistent
Fully
Transactional
Eventually
Consistent
More Consistency More Performance
<cache name=”UserPreferencesCache"
maxElementsInMemory="10000"
timeToLiveSeconds="300”>
<terracotta consistency=”eventual"/>
</cache>
<cache name=”ShoppingCartCache"
maxElementsInMemory=”5000"
timeToIdleSeconds=”6000”>
<terracotta consistency=”strong"/>
</cache>
Example Configuration
39
Terracotta Server Array
Scale with Data and Processing Needs
39
BigMemory
App Server
Ehcache
App Server
Ehcache
Traditional
3-Tier Architecture
Scale Up Scale Out
Elastic Scale
In the Cloud
App Server
Ehcache
Quartz
App Server
Ehcache
Quartz
Database
Database
Database
Database
App Server
Ehcache
App Server
Ehcache
BigMemory
Terracotta Server Array
BigMemory
Increase Data in Memory
Reduce Database Reliance
40
Recent Developments
40
• JSR107
• Hadoop Integration: One way
(EhcacheOutputFormat)
• New Management and Monitoring
4141
Thank You
Dhruv.Kumar@terracottatech.com

More Related Content

PPT
Caching for J2ee Enterprise Applications
Debajani Mohanty
 
ODP
Caching technology comparison
Rohit Kelapure
 
PPTX
Caching In Java- Best Practises and Pitfalls
HARIHARAN ANANTHARAMAN
 
PDF
Ehcache Architecture, Features And Usage Patterns
Eduardo Pelegri-Llopart
 
PDF
Overview of the ehcache
HyeonSeok Choi
 
ODP
Caching Strategies
Michal Špaček
 
PDF
Advanced caching techniques with ehcache, big memory, terracotta, and coldfusion
ColdFusionConference
 
PDF
Ehcache3 — JSR-107 on steroids
Alex Snaps
 
Caching for J2ee Enterprise Applications
Debajani Mohanty
 
Caching technology comparison
Rohit Kelapure
 
Caching In Java- Best Practises and Pitfalls
HARIHARAN ANANTHARAMAN
 
Ehcache Architecture, Features And Usage Patterns
Eduardo Pelegri-Llopart
 
Overview of the ehcache
HyeonSeok Choi
 
Caching Strategies
Michal Špaček
 
Advanced caching techniques with ehcache, big memory, terracotta, and coldfusion
ColdFusionConference
 
Ehcache3 — JSR-107 on steroids
Alex Snaps
 

What's hot (20)

PDF
Caching technology comparison
Rohit Kelapure
 
PPTX
Understanding Web Cache
ProdigyView
 
PDF
Distributed caching with java JCache
Kasun Gajasinghe
 
PPT
World Wide Web Caching
ersanbilik
 
PDF
Eh cache in Kaunas JUG
Kaunas Java User Group
 
PDF
Web session replication with Hazelcast
Emrah Kocaman
 
PDF
Distributed Caching Using the JCACHE API and ehcache, Including a Case Study ...
elliando dias
 
PPTX
Caching
Nascenia IT
 
PPT
Session Handling Using Memcache
Anand Ghaywankar
 
PPTX
[Hanoi-August 13] Tech Talk on Caching Solutions
ITviec
 
PPTX
Mini-Training: To cache or not to cache
Betclic Everest Group Tech Team
 
PPTX
Drupal performance optimization Best Practices
Ratnesh kumar, CSM
 
PPTX
Using memcache to improve php performance
Sudar Muthu
 
PDF
Skalowalna architektura na przykładzie soccerway.com
Spodek 2.0
 
ODP
Cassandra as Memcache
Edward Capriolo
 
PDF
Implementing High Availability Caching with Memcached
Gear6
 
PPTX
Share point 2013 distributed cache
Michael Nokhamzon
 
PPTX
캐시 분산처리 인프라
Park Chunduck
 
PDF
Memcached Presentation
Asif Ali
 
Caching technology comparison
Rohit Kelapure
 
Understanding Web Cache
ProdigyView
 
Distributed caching with java JCache
Kasun Gajasinghe
 
World Wide Web Caching
ersanbilik
 
Eh cache in Kaunas JUG
Kaunas Java User Group
 
Web session replication with Hazelcast
Emrah Kocaman
 
Distributed Caching Using the JCACHE API and ehcache, Including a Case Study ...
elliando dias
 
Caching
Nascenia IT
 
Session Handling Using Memcache
Anand Ghaywankar
 
[Hanoi-August 13] Tech Talk on Caching Solutions
ITviec
 
Mini-Training: To cache or not to cache
Betclic Everest Group Tech Team
 
Drupal performance optimization Best Practices
Ratnesh kumar, CSM
 
Using memcache to improve php performance
Sudar Muthu
 
Skalowalna architektura na przykładzie soccerway.com
Spodek 2.0
 
Cassandra as Memcache
Edward Capriolo
 
Implementing High Availability Caching with Memcached
Gear6
 
Share point 2013 distributed cache
Michael Nokhamzon
 
캐시 분산처리 인프라
Park Chunduck
 
Memcached Presentation
Asif Ali
 
Ad

Viewers also liked (20)

PDF
SAP and Red Hat JBoss Partner Webinar
SAP PartnerEdge program for Application Development
 
PDF
Developing High Performance and Scalable ColdFusion Application Using Terraco...
ColdFusionConference
 
KEY
Predicting Defects in SAP Java Code: An Experience Report
tilman.holschuh
 
PDF
Sap java
largeman
 
PDF
SAP Integration with Red Hat JBoss Technologies
hwilming
 
PDF
The new ehcache 2.0 and hibernate spi
Cyril Lakech
 
PDF
Intro To Sap Netweaver Java
Leland Bartlett
 
PDF
Practical SAP pentesting workshop (NullCon Goa)
ERPScan
 
PDF
Integrating SAP the Java EE Way - JBoss One Day talk 2012
hwilming
 
PDF
Low latency Java apps
Simon Ritter
 
PPTX
Sap java connector / Hybris RFC
Monsif Elaissoussi
 
PPT
Spcd hs batch 87 foundation
Ed Kissyou
 
PPTX
DGAE
Tania MicĂł
 
PDF
0721
wzsse
 
PDF
Modul lengkap
Thoriq Hadi
 
PDF
Ethnic Politics and the 2015 Elections in Myanmar
MYO AUNG Myanmar
 
PPTX
The Layout of iMovie
Dawn Anthony
 
PDF
Resultados ReuniĂłn N16
lucasmustaine
 
PDF
Ibne maryam - ابن مریم
muzaffertahir9
 
PPTX
Databazove systemy6
olc_user
 
SAP and Red Hat JBoss Partner Webinar
SAP PartnerEdge program for Application Development
 
Developing High Performance and Scalable ColdFusion Application Using Terraco...
ColdFusionConference
 
Predicting Defects in SAP Java Code: An Experience Report
tilman.holschuh
 
Sap java
largeman
 
SAP Integration with Red Hat JBoss Technologies
hwilming
 
The new ehcache 2.0 and hibernate spi
Cyril Lakech
 
Intro To Sap Netweaver Java
Leland Bartlett
 
Practical SAP pentesting workshop (NullCon Goa)
ERPScan
 
Integrating SAP the Java EE Way - JBoss One Day talk 2012
hwilming
 
Low latency Java apps
Simon Ritter
 
Sap java connector / Hybris RFC
Monsif Elaissoussi
 
Spcd hs batch 87 foundation
Ed Kissyou
 
0721
wzsse
 
Modul lengkap
Thoriq Hadi
 
Ethnic Politics and the 2015 Elections in Myanmar
MYO AUNG Myanmar
 
The Layout of iMovie
Dawn Anthony
 
Resultados ReuniĂłn N16
lucasmustaine
 
Ibne maryam - ابن مریم
muzaffertahir9
 
Databazove systemy6
olc_user
 
Ad

Similar to Building low latency java applications with ehcache (20)

PDF
Scale ColdFusion with Terracotta Distributed Caching for Ehchache
ColdFusionConference
 
PDF
Scaling Your Cache
Alex Miller
 
PDF
Ehcache 3 @ BruJUG
Louis Jacomet
 
PDF
Developing High Performance and Scalable ColdFusion Applications Using Terrac...
Shailendra Prasad
 
PDF
Terracotta Ehcache : Simpler, faster, distributed
Anthony Dahanne
 
PPTX
Jug Lugano - Scale over the limits
Davide Carnevali
 
PDF
In-Memory Data Management Goes Mainstream - OpenSlava 2015
Software AG
 
PDF
Ehcache 3: JSR-107 on steroids at Devoxx Morocco
Louis Jacomet
 
PPTX
From cache to in-memory data grid. Introduction to Hazelcast.
Taras Matyashovsky
 
PDF
Caching in applications still matters
Anthony Dahanne
 
PDF
Scaling Your Cache And Caching At Scale
Alex Miller
 
ODP
Clustering Made Easier: Using Terracotta with Hibernate and/or EHCache
Cris Holdorph
 
PPS
OSOM - Open source catching solutions
Marcela Oniga
 
PPTX
5 Reasons to Upgrade Ehcache to BigMemory Go
Software AG
 
PPTX
Cache Rules Everything Around Me - DevIntersection - December 2022
Matthew Groves
 
PPTX
Cache Rules Everything Around Me - Momentum - October 2022.pptx
Matthew Groves
 
PPTX
Distributed caching-computing v3.8
Rahul Gupta
 
PDF
Spring One 2 GX 2014 - CACHING WITH SPRING: ADVANCED TOPICS AND BEST PRACTICES
Michael PlĂśd
 
PPTX
5 Reasons to Upgrade Ehcache to BigMemory Go
Terracotta, a product line at Software AG
 
PPTX
Think Distributed: The Hazelcast Way
Rahul Gupta
 
Scale ColdFusion with Terracotta Distributed Caching for Ehchache
ColdFusionConference
 
Scaling Your Cache
Alex Miller
 
Ehcache 3 @ BruJUG
Louis Jacomet
 
Developing High Performance and Scalable ColdFusion Applications Using Terrac...
Shailendra Prasad
 
Terracotta Ehcache : Simpler, faster, distributed
Anthony Dahanne
 
Jug Lugano - Scale over the limits
Davide Carnevali
 
In-Memory Data Management Goes Mainstream - OpenSlava 2015
Software AG
 
Ehcache 3: JSR-107 on steroids at Devoxx Morocco
Louis Jacomet
 
From cache to in-memory data grid. Introduction to Hazelcast.
Taras Matyashovsky
 
Caching in applications still matters
Anthony Dahanne
 
Scaling Your Cache And Caching At Scale
Alex Miller
 
Clustering Made Easier: Using Terracotta with Hibernate and/or EHCache
Cris Holdorph
 
OSOM - Open source catching solutions
Marcela Oniga
 
5 Reasons to Upgrade Ehcache to BigMemory Go
Software AG
 
Cache Rules Everything Around Me - DevIntersection - December 2022
Matthew Groves
 
Cache Rules Everything Around Me - Momentum - October 2022.pptx
Matthew Groves
 
Distributed caching-computing v3.8
Rahul Gupta
 
Spring One 2 GX 2014 - CACHING WITH SPRING: ADVANCED TOPICS AND BEST PRACTICES
Michael PlĂśd
 
5 Reasons to Upgrade Ehcache to BigMemory Go
Terracotta, a product line at Software AG
 
Think Distributed: The Hazelcast Way
Rahul Gupta
 

More from Chris Westin (20)

PDF
Data torrent meetup-productioneng
Chris Westin
 
PDF
Gripshort
Chris Westin
 
PPTX
Ambari hadoop-ops-meetup-2013-09-19.final
Chris Westin
 
PDF
Cluster management and automation with cloudera manager
Chris Westin
 
PDF
SDN/OpenFlow #lspe
Chris Westin
 
ODP
cfengine3 at #lspe
Chris Westin
 
PPTX
mongodb-aggregation-may-2012
Chris Westin
 
PDF
Nimbula lspe-2012-04-19
Chris Westin
 
PPTX
mongodb-brief-intro-february-2012
Chris Westin
 
PDF
Stingray - Riverbed Technology
Chris Westin
 
PPTX
MongoDB's New Aggregation framework
Chris Westin
 
PPTX
Replication and replica sets
Chris Westin
 
PPTX
Architecting a Scale Out Cloud Storage Solution
Chris Westin
 
PPTX
FlashCache
Chris Westin
 
PPTX
Large Scale Cacti
Chris Westin
 
PPTX
MongoDB: An Introduction - July 2011
Chris Westin
 
PPTX
Practical Replication June-2011
Chris Westin
 
PPTX
MongoDB: An Introduction - june-2011
Chris Westin
 
PPT
Ganglia Overview-v2
Chris Westin
 
PPTX
MongoDB Aggregation MongoSF May 2011
Chris Westin
 
Data torrent meetup-productioneng
Chris Westin
 
Gripshort
Chris Westin
 
Ambari hadoop-ops-meetup-2013-09-19.final
Chris Westin
 
Cluster management and automation with cloudera manager
Chris Westin
 
SDN/OpenFlow #lspe
Chris Westin
 
cfengine3 at #lspe
Chris Westin
 
mongodb-aggregation-may-2012
Chris Westin
 
Nimbula lspe-2012-04-19
Chris Westin
 
mongodb-brief-intro-february-2012
Chris Westin
 
Stingray - Riverbed Technology
Chris Westin
 
MongoDB's New Aggregation framework
Chris Westin
 
Replication and replica sets
Chris Westin
 
Architecting a Scale Out Cloud Storage Solution
Chris Westin
 
FlashCache
Chris Westin
 
Large Scale Cacti
Chris Westin
 
MongoDB: An Introduction - July 2011
Chris Westin
 
Practical Replication June-2011
Chris Westin
 
MongoDB: An Introduction - june-2011
Chris Westin
 
Ganglia Overview-v2
Chris Westin
 
MongoDB Aggregation MongoSF May 2011
Chris Westin
 

Recently uploaded (20)

PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
PPTX
ChatGPT's Deck on The Enduring Legacy of Fax Machines
Greg Swan
 
PDF
DevOps & Developer Experience Summer BBQ
AUGNYC
 
PDF
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
 
PPTX
Coupa-Overview _Assumptions presentation
annapureddyn
 
PDF
Why Your AI & Cybersecurity Hiring Still Misses the Mark in 2025
Virtual Employee Pvt. Ltd.
 
PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
PDF
Doc9.....................................
SofiaCollazos
 
PDF
Software Development Company | KodekX
KodekX
 
PDF
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
PDF
Chapter 2 Digital Image Fundamentals.pdf
Getnet Tigabie Askale -(GM)
 
PDF
Best ERP System for Manufacturing in India | Elite Mindz
Elite Mindz
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PDF
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
PPTX
How to Build a Scalable Micro-Investing Platform in 2025 - A Founder’s Guide ...
Third Rock Techkno
 
PDF
CIFDAQ'S Market Insight: BTC to ETH money in motion
CIFDAQ
 
PPTX
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
PDF
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
ChatGPT's Deck on The Enduring Legacy of Fax Machines
Greg Swan
 
DevOps & Developer Experience Summer BBQ
AUGNYC
 
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
 
Coupa-Overview _Assumptions presentation
annapureddyn
 
Why Your AI & Cybersecurity Hiring Still Misses the Mark in 2025
Virtual Employee Pvt. Ltd.
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
Doc9.....................................
SofiaCollazos
 
Software Development Company | KodekX
KodekX
 
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
Chapter 2 Digital Image Fundamentals.pdf
Getnet Tigabie Askale -(GM)
 
Best ERP System for Manufacturing in India | Elite Mindz
Elite Mindz
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
How to Build a Scalable Micro-Investing Platform in 2025 - A Founder’s Guide ...
Third Rock Techkno
 
CIFDAQ'S Market Insight: BTC to ETH money in motion
CIFDAQ
 
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
 

Building low latency java applications with ehcache

  • 1. Building Low Latency Java Applications with Ehcache Dhruv Kumar Software Engineer, Terracotta Inc. [email protected]
  • 15. 15 Trend Summary 15 §  Storage is cheap and increases exponentially §  Most transfer rates increase exponentially except disk throughput. –  Gap between disk capacity and transfer rate is increasing §  Accessing disk is very slow: transferring 100GB @ 100 MB/s takes 1000s, or approx. 17 minutes. –  Will get worse, as 512GB/node RAM will be common in 2 years. –  Faster to access Network Attached Memory! –  SSDs still not common due to unfavorable price performance
  • 16. 16 In-Memory Computing Opportunity 16 §  256 GB RAM * 4 nodes = 1 TB In-Memory Cluster §  1 TB can hold many large datasets: 1 billion users @ 1 KB each §  Number of CPU cores double every 24 months: memory/core increases exponentially §  Bottomline: judiciously using RAM is key.
  • 18. 18 Terracotta Server Array Scale with Data and Processing Needs 18 BigMemory App Server Ehcache App Server Ehcache Traditional 3-Tier Architecture Scale Vertically Scale Horizontally Elastic Scale In the Cloud App Server Ehcache Quartz App Server Ehcache Quartz Database Database Database Database App Server Ehcache App Server Ehcache BigMemory Terracotta Server Array BigMemory Increase Data in Memory Reduce Database Reliance
  • 19. 19 Hello Ehcache! Database Traditional 3-Tier Architecture App Server Ehcache §  Reduction in database reliance –  Store repetitively used data and access them in memory speeds §  Reduction of new objects created –  Stored objects will be reused constantly thus reducing the creation of new objects §  Less network traffic –  Stored data is already at the application layer so no need to make a network call to get it §  Reduce CPU usage –  Objects in cache are already in the format you need for use, no additional marshaling needed.
  • 20. 20 Example Configuration Configuration via Ehcache.xml 20 Example Configuration <ehcache>! ! <cache name=”UserPreferencesCache"! maxElementsInMemory="10000"! timeToIdleSeconds="300”! ! ! !memoryStoreEvictionPolicy="LRU”/>! ! <cache name=”ShoppingCartCache"! maxElementsInMemory=”2500"! timeToLiveSeconds=”6000”! ! ! !memoryStoreEvictionPolicy=”LFU"/>! ! </ehcache>! 20
  • 21. 21 Simple API 21 Example Code public Object testCache(String key) throws Exception {! !CacheManager cacheManager = ! ! !new CacheManager( “<path to my ehcache.xml>”);! !Cache myCache = cacheManager.getCache("MyCache");! !Object value;! ! !! !Element element = myCache.get(key);! !if (element == null) {! ! !value = "go get it from somewhere like DB or service, ! ! ! etc";! ! !myCache.put(new Element(key, value));! !} else {! ! !value = (Object) element.getValue();! !}! ! !! !return value;! }!
  • 22. 22 Ehcache Search §  Intuitive, full-featured Search API §  Fast, efficient implementation §  Make cache searchable, then specify attributes 22 <cache name=”peopleCache”> <searchable> <searchAttribute name="age" expression="value.getAge()"/> <searchAttribute name="gender" expression="value.getGender()"/> </searchable> </cache> Example: Search for 32-year-old males results = cache.createQuery().includeKeys() .addCriteria(age.eq(32)).and (gender.eq("male")) .execute(); Example Configuration and Code
  • 23. 23 Ehcache Search Using SQL-like Syntax §  Can also search Ehcache using a SQL like syntax §  String Queries mapped to Ehcache Search API 23 Example: Search for 32-year-old males results = cache.createQuery().includeKeys() .addCriteria(age.eq(32)).and (gender.eq("male")) .execute(); // or using Ehcache Query Language QueryManager qm = (new QueryManagerBuilder()).addEhcache(peopleCache).build(); String statement = “select age, gender from peopleCache where age = 32 and gender =‘male’;” results = qm.createQuery(statement).end().execute(); Example Configuration and Code
  • 24. 24 Ehcache Persistence §  Persist actions in a log-append store (Fast Restart Store). §  Each mutate operation is recorded. Optionally synchronous. §  On restart, Ehcache entries and Index data are reconstructed from the log. 24 Example ConfigurationExample Configuration <ehcache>! <cache name=”UserPreferencesCache"! maxElementsInMemory="10000"! timeToIdleSeconds="300”! ! ! persistenceStrategy=“localRestartable”>! </ehcache>!
  • 25. 25 In-memory Data and Speed 25 Milliseconds App Response Time Microseconds App Response Time Memory 90% of Data in Database Database 90% of Data in Memory
  • 26. 26 Storing Data away from Java Heap (BigMemory) Off-heap memory allocator. Uses NIO DirectByteBuffers. Bypasses Java Garbage Collection. Only Serializable keys and values can be placed in Off-heap. Pure Java implementation compatible with all popular JVMs Requires no changes to application code, JVM or OS 26 Database Vertical Scaling App Server Ehcache BigMemory
  • 27. 27 BigMemory Configuration <ehcache> <cache name= UserPreferencesCache" maxBytesOnHeap=”512M" timeToIdleSeconds="300 !memoryStoreEvictionPolicy="LRU !overflowToOffHeap="true ! !maxBytesOffHeap= 30G"/> <cache name= ShoppingCartCache" maxElementsInMemory= 2500" timeToLiveSeconds= 6000 !memoryStoreEvictionPolicy="LFU"/> </ehcache>! 27 Example Configuration
  • 28. 28 Testing Offheap Performance 28 • Public URL: http://svn.terracotta.org/svn/forge/offHeap-test/ • Our Configuration: Six 4-core Xeon CPUs @ 2.93 GHz, 128 GB RAM, RHEL 5.1, Sun JDK 1.6.0_21 in 64 bit mode. • Load the cache and then run 50 threads doing 90% Read (get() call) calls and 10 % Writes (put() call) • Run in Heap and Offheap, and compare GC duration, latency, throughput.
  • 29. 29 Offheap Perf Test: Garbage Collection Pauses 29
  • 30. 30 Offheap Perf Test: Maximum Latency 30
  • 31. 31 Offheap Perf Test: Mean Latency 31
  • 34. 3434 Distributed Ehcache using Terracotta Server Array §  Stateful Server Array §  Synchronous TCP based connections to clients §  Highly Available using Master Slave replication §  Linear Scale Out Characteristics §  Persistent §  Various consistency optionsDatabase Scale Out App Server Ehcache Terracotta Server Array BigMemory App Server Ehcache
  • 35. 35 Terracotta Server Array 35 Terracotta ServerArray Stripe Pure Java cache server on commodity HW Transactional updated mirror for high availability Stripe Commodity Server Application Terracotta Driver Stripe Stripe Stripe Stripe Commodity Server Application Terracotta Driver Commodity Server Application Terracotta Driver TCP § Durability § Mirroring § Striping § Developer Console § Plug-in Monitoring § Operations Center Commodity Server Disk Active Server Commodity Server Disk BigMemory Mirror BigMemory
  • 36. 36 Example Configuration Configuring Ehcache to use Terracotta 36 <ehcache> !<terracottaConfig url="someserver:9510"/> !<cache name= UserPreferencesCache ! !maxElementsInMemory="10000 ! !timeToIdleSeconds= 300 /> !<cache name= ShoppingCartCache" ! !maxElementsInMemory= 25000" ! !timeToLiveSeconds= 6000 />! !<terracotta /> </ehcache>! Simply change two lines of configuration
  • 37. 37 Tiered Storage In-Memory Tiered Data Storage 37 Terracotta Heap Heap Store BigMemory Off-Heap Store 2,000,000+ 1,000,000 100,000 2 1,000 10,000+ Speed (TPS) 1,000s Size (GB) External Data Source (e.g., Database) Terracotta Offheap
  • 38. 38 Example Configuration Consistency options in TSA 38 Strongly Consistent Fully Transactional Eventually Consistent More Consistency More Performance <cache name=”UserPreferencesCache" maxElementsInMemory="10000" timeToLiveSeconds="300”> <terracotta consistency=”eventual"/> </cache> <cache name=”ShoppingCartCache" maxElementsInMemory=”5000" timeToIdleSeconds=”6000”> <terracotta consistency=”strong"/> </cache> Example Configuration
  • 39. 39 Terracotta Server Array Scale with Data and Processing Needs 39 BigMemory App Server Ehcache App Server Ehcache Traditional 3-Tier Architecture Scale Up Scale Out Elastic Scale In the Cloud App Server Ehcache Quartz App Server Ehcache Quartz Database Database Database Database App Server Ehcache App Server Ehcache BigMemory Terracotta Server Array BigMemory Increase Data in Memory Reduce Database Reliance
  • 40. 40 Recent Developments 40 • JSR107 • Hadoop Integration: One way (EhcacheOutputFormat) • New Management and Monitoring