SlideShare ist ein Scribd-Unternehmen logo
1 von 32
Downloaden Sie, um offline zu lesen
galder@jboss.org | twitter.com/galderz | zamarreno.com
Thursday, October 7, 2010
Keeping Infinispan In Shape:
                                    Highly-Precise, Scalable
                                                 Data Eviction

                            Galder Zamarreño & Vladimir Blagojevic
                            Senior Engineer, Red Hat
                            7th October 2010, JUDCon - Berlin


                                                          galder@jboss.org | twitter.com/galderz | zamarreno.com
Thursday, October 7, 2010
Who is Galder?

                            • R&D engineer (Red Hat Inc):
                              • Infinispan developer
                              • JBoss Cache developer
                            • Contributor and committer:
                              • JBoss AS, Hibernate, JGroups, JBoss Portal,...etc
                            • Blog: zamarreno.com
                            • Twitter: @galderz



                                                          galder@jboss.org | twitter.com/galderz | zamarreno.com
Thursday, October 7, 2010
Agenda

                            • Eviction in:
                              • Java Collections Framework
                              • JBoss Cache
                              • Infinispan 4.0
                            • New in Infinispan 4.1:
                              • LIRS
                              • Batching Updates



                                                         galder@jboss.org | twitter.com/galderz | zamarreno.com
Thursday, October 7, 2010
Java Collections Framework


                            • Key building block of any Java app
                            • Introduced in Java 1.2
                            • Extended with concurrent collections in Java 1.5
                            • Collection element eviction ??




                                                           galder@jboss.org | twitter.com/galderz | zamarreno.com
Thursday, October 7, 2010
Collections cannot grow forever




                                           galder@jboss.org | twitter.com/galderz | zamarreno.com
Thursday, October 7, 2010
If using a collection as cache


                            • Forces clients to either:
                             • Remove elements proactively
                             • Or run a periodic cleanup process
                            • Which can be a PITA...




                                                          galder@jboss.org | twitter.com/galderz | zamarreno.com
Thursday, October 7, 2010
Eviction in JBoss Cache days




                                          galder@jboss.org | twitter.com/galderz | zamarreno.com
Thursday, October 7, 2010
JBoss Cache eviction issues


                            • Under heavy load, eviction queues could fill up - bottleneck
                             • Possibly a side effect of MVCC’s non-blocking reads
                            • Separating data into regions could alleviate the issue
                             • But it’s really a hack!




                                                           galder@jboss.org | twitter.com/galderz | zamarreno.com
Thursday, October 7, 2010
Original Infinispan 4.0 eviction

                            • Tried a different approach:
                            • Avoid using queues to hold events
                            • Taking advantage of tree to map change:
                             • Attempt to maintain map ordered as per eviction rules
                             • Could we use ConcurrentSkipListMap ?
                               • No. O(1) desired for all map operations


                                                            galder@jboss.org | twitter.com/galderz | zamarreno.com
Thursday, October 7, 2010
Doubly Linked
                                          ConcurrentHashMap

                            •   Based on H.Sundell and P.Tsigas paper:

                                •   Lock-Free Deques and Doubly Linked Lists (2008)

                            •   With each cache access or update update links

                            •   Eviction just a matter of walking the linked list one way




                                                                 galder@jboss.org | twitter.com/galderz | zamarreno.com
Thursday, October 7, 2010
Issues under heavy load


                            • Algorithm always uses same node (the tail) to append stuff
                            • With high concurrency, CAS stress lead to loads of retrying
                            • So much retrying, we’re getting infinite loops
                            • Before 4.0.0.Final, reverted to a more conservative algorithm




                                                            galder@jboss.org | twitter.com/galderz | zamarreno.com
Thursday, October 7, 2010
4.0.0.Final eviction




                                      galder@jboss.org | twitter.com/galderz | zamarreno.com
Thursday, October 7, 2010
LRU eviction algorithm issues

                            • Weak access locality
                             • One-time accessed keys not evicted timely
                             • In loops, soon to be accessed keys might get evicted first
                             • With distinct access frequencies, frequently accessed keys
                               can unfortunately get evicted
                            • LRU’s working set limited to cache size



                                                           galder@jboss.org | twitter.com/galderz | zamarreno.com
Thursday, October 7, 2010
Enter the room... LIRS

                            • Eviction algorithm that can cope with weak access locality
                            • Based on S.Jiang and X.Zhang’s 2002 paper:
                             • LIRS: An efficient low inter-reference recency set
                               replacement policy to improve buffer cache performance
                            • LIRS based around two concepts: IRR and Recency




                                                         galder@jboss.org | twitter.com/galderz | zamarreno.com
Thursday, October 7, 2010
IRR and Recency
                            • Inter-Reference Recency (IRR):
                             • Number of other unique keys accessed between two
                               consecutive accesses to same key
                            • Recency (R)
                             • Number of other unique keys accessed from last reference
                               until now




                                                         galder@jboss.org | twitter.com/galderz | zamarreno.com
Thursday, October 7, 2010
How does LIRS work?


                            • If key has a high IRR, it’s next IRR is likely to be high again
                             • Keys with highest IRR are considered for eviction
                            • Once IRR is out of date, we start relying on Recency
                            • LIRS = Low Inter-reference Recency Set




                                                             galder@jboss.org | twitter.com/galderz | zamarreno.com
Thursday, October 7, 2010
How is LIRS implemented?

                            • Low IRR (LIR) area
                             • Holds hot keys!
                            • High IRR (HIR) area
                             • Holds recently accessed keys
                             • Keys here might get promoted to LIR area



                                                         galder@jboss.org | twitter.com/galderz | zamarreno.com
Thursday, October 7, 2010
Cache Hit - LIR area




                                      galder@jboss.org | twitter.com/galderz | zamarreno.com
Thursday, October 7, 2010
Cache Hit - LIR area




                                      galder@jboss.org | twitter.com/galderz | zamarreno.com
Thursday, October 7, 2010
Hit - HIR area and in LIR Q ...




                                           galder@jboss.org | twitter.com/galderz | zamarreno.com
Thursday, October 7, 2010
Hit - HIR area and in LIR Q




                                         galder@jboss.org | twitter.com/galderz | zamarreno.com
Thursday, October 7, 2010
Hit - HIR area and not in LIR Q




                                           galder@jboss.org | twitter.com/galderz | zamarreno.com
Thursday, October 7, 2010
Cache Miss




                                 galder@jboss.org | twitter.com/galderz | zamarreno.com
Thursday, October 7, 2010
Cache Miss




                                 galder@jboss.org | twitter.com/galderz | zamarreno.com
Thursday, October 7, 2010
Cache Miss




                                 galder@jboss.org | twitter.com/galderz | zamarreno.com
Thursday, October 7, 2010
LIRS implementation hurdles

                            • LIRS requires a lot of key shifting around
                             • It can lead to high contention
                            • Unless you can implement it in scalable way, it’s useless
                            • Low contended way to implement a high precision eviction
                              algorithm? Is it possible?




                                                            galder@jboss.org | twitter.com/galderz | zamarreno.com
Thursday, October 7, 2010
Batching Eviction Updates
                            • Original idea: X.Ding, S.Jiang and X.Zhang’s 2009 paper:
                             • BP-Wrapper: A System Framework Making Any
                               Replacement Algorithms (Almost) Lock Contention Free
                            • Keeping cache access per thread in a queue
                            • If queue reaches a threshold:
                             • Acquire locks and execute eviction as per algorithm
                            • Batching updates significantly lowers lock contention


                                                              galder@jboss.org | twitter.com/galderz | zamarreno.com
Thursday, October 7, 2010
Batching Updates in Infinispan

                            • Decided against recording access per thread
                             • 100s threads could be hitting cache; some short lived
                            • Created BoundedConcurrentHashMap
                             • Based on Doug Lea's ConcurrentHashMap
                             • Records accesses in a lock-free queue in each segment
                            • When threshold passed, acquire lock for segment and evict


                                                          galder@jboss.org | twitter.com/galderz | zamarreno.com
Thursday, October 7, 2010
Precision and Performance

                            • Segment level eviction does not affect overall precision
                            • Community member run some performance tests:
                             • After swapping their own LRU cache with BoundedCHM:
                               • Berlin SPARQL Benchmark performance increased
                                 55-60% for both cold and hot caches




                                                           galder@jboss.org | twitter.com/galderz | zamarreno.com
Thursday, October 7, 2010
Summary

                            • In JBoss Cache, eviction can become a bottleneck
                            • Infinispan 4.0 uses conservative eviction
                            • Infinispan 4.1 has more precise eviction algorithm (LIRS)
                            • Batching updates, present in 4.1, significantly lowers lock
                              contention
                            • Result = Highly-concurrent, highly-precise implicit eviction



                                                            galder@jboss.org | twitter.com/galderz | zamarreno.com
Thursday, October 7, 2010
Questions?

                            infinispan.org
                            blog.infinispan.org
                            twitter.com/infinispan
                               #infinispan
                               #judcon

                                                     galder@jboss.org | twitter.com/galderz | zamarreno.com
Thursday, October 7, 2010

Weitere ähnliche Inhalte

Andere mochten auch

Infinispan, Data Grids, NoSQL, Cloud Storage and JSR 347
Infinispan, Data Grids, NoSQL, Cloud Storage and JSR 347Infinispan, Data Grids, NoSQL, Cloud Storage and JSR 347
Infinispan, Data Grids, NoSQL, Cloud Storage and JSR 347Manik Surtani
 
Infinspan: In-memory data grid meets NoSQL
Infinspan: In-memory data grid meets NoSQLInfinspan: In-memory data grid meets NoSQL
Infinspan: In-memory data grid meets NoSQLManik Surtani
 
Hacking Infinispan: the new open source data grid meets NoSQL
Hacking Infinispan: the new open source data grid meets NoSQLHacking Infinispan: the new open source data grid meets NoSQL
Hacking Infinispan: the new open source data grid meets NoSQLCodemotion
 
Apache Geode - The First Six Months
Apache Geode -  The First Six MonthsApache Geode -  The First Six Months
Apache Geode - The First Six MonthsAnthony Baker
 
Infinispan from POC to Production
Infinispan from POC to ProductionInfinispan from POC to Production
Infinispan from POC to ProductionC2B2 Consulting
 
Redis adaptor for Apache Geode
Redis adaptor for Apache GeodeRedis adaptor for Apache Geode
Redis adaptor for Apache GeodeSwapnil Bawaskar
 
Apache geode
Apache geodeApache geode
Apache geodeYogesh BG
 
Introduction to Apache Geode (Cork, Ireland)
Introduction to Apache Geode (Cork, Ireland)Introduction to Apache Geode (Cork, Ireland)
Introduction to Apache Geode (Cork, Ireland)Anthony Baker
 
Apache Geode Clubhouse - WAN-based Replication
Apache Geode Clubhouse - WAN-based ReplicationApache Geode Clubhouse - WAN-based Replication
Apache Geode Clubhouse - WAN-based ReplicationPivotalOpenSourceHub
 
인메모리 클러스터링 아키텍처
인메모리 클러스터링 아키텍처인메모리 클러스터링 아키텍처
인메모리 클러스터링 아키텍처Jaehong Cheon
 
Infinispan and Enterprise Data Grid
Infinispan and Enterprise Data GridInfinispan and Enterprise Data Grid
Infinispan and Enterprise Data GridJBug Italy
 
Building Apps with Distributed In-Memory Computing Using Apache Geode
Building Apps with Distributed In-Memory Computing Using Apache GeodeBuilding Apps with Distributed In-Memory Computing Using Apache Geode
Building Apps with Distributed In-Memory Computing Using Apache GeodePivotalOpenSourceHub
 
An Introduction to Apache Geode (incubating)
An Introduction to Apache Geode (incubating)An Introduction to Apache Geode (incubating)
An Introduction to Apache Geode (incubating)Anthony Baker
 
Going asynchronous with netty - SOSCON 2015
Going asynchronous with netty - SOSCON 2015Going asynchronous with netty - SOSCON 2015
Going asynchronous with netty - SOSCON 2015Kris Jeong
 
Apache ignite Datagrid
Apache ignite DatagridApache ignite Datagrid
Apache ignite DatagridSurinder Mehra
 
Pivotal 전략 업데이트 2015 Feb
Pivotal 전략 업데이트 2015 FebPivotal 전략 업데이트 2015 Feb
Pivotal 전략 업데이트 2015 Febseungdon Choi
 
祝 top-level project Apache Geode
祝 top-level project Apache Geode祝 top-level project Apache Geode
祝 top-level project Apache GeodeTomohiro Ichimura
 
Hazelcast 소개
Hazelcast 소개Hazelcast 소개
Hazelcast 소개sangyun han
 
오픈소스 성능 최적화 보고서 ch07. Infinispan
오픈소스 성능 최적화 보고서 ch07. Infinispan오픈소스 성능 최적화 보고서 ch07. Infinispan
오픈소스 성능 최적화 보고서 ch07. InfinispanHyeonSeok Choi
 

Andere mochten auch (20)

Infinispan, Data Grids, NoSQL, Cloud Storage and JSR 347
Infinispan, Data Grids, NoSQL, Cloud Storage and JSR 347Infinispan, Data Grids, NoSQL, Cloud Storage and JSR 347
Infinispan, Data Grids, NoSQL, Cloud Storage and JSR 347
 
Infinspan: In-memory data grid meets NoSQL
Infinspan: In-memory data grid meets NoSQLInfinspan: In-memory data grid meets NoSQL
Infinspan: In-memory data grid meets NoSQL
 
Hacking Infinispan: the new open source data grid meets NoSQL
Hacking Infinispan: the new open source data grid meets NoSQLHacking Infinispan: the new open source data grid meets NoSQL
Hacking Infinispan: the new open source data grid meets NoSQL
 
Apache Geode - The First Six Months
Apache Geode -  The First Six MonthsApache Geode -  The First Six Months
Apache Geode - The First Six Months
 
Infinispan from POC to Production
Infinispan from POC to ProductionInfinispan from POC to Production
Infinispan from POC to Production
 
Redis adaptor for Apache Geode
Redis adaptor for Apache GeodeRedis adaptor for Apache Geode
Redis adaptor for Apache Geode
 
Apache geode
Apache geodeApache geode
Apache geode
 
Introduction to Apache Geode (Cork, Ireland)
Introduction to Apache Geode (Cork, Ireland)Introduction to Apache Geode (Cork, Ireland)
Introduction to Apache Geode (Cork, Ireland)
 
Apache Geode Clubhouse - WAN-based Replication
Apache Geode Clubhouse - WAN-based ReplicationApache Geode Clubhouse - WAN-based Replication
Apache Geode Clubhouse - WAN-based Replication
 
인메모리 클러스터링 아키텍처
인메모리 클러스터링 아키텍처인메모리 클러스터링 아키텍처
인메모리 클러스터링 아키텍처
 
Infinispan and Enterprise Data Grid
Infinispan and Enterprise Data GridInfinispan and Enterprise Data Grid
Infinispan and Enterprise Data Grid
 
Building Apps with Distributed In-Memory Computing Using Apache Geode
Building Apps with Distributed In-Memory Computing Using Apache GeodeBuilding Apps with Distributed In-Memory Computing Using Apache Geode
Building Apps with Distributed In-Memory Computing Using Apache Geode
 
Data Grids and Data Caching
Data Grids and Data CachingData Grids and Data Caching
Data Grids and Data Caching
 
An Introduction to Apache Geode (incubating)
An Introduction to Apache Geode (incubating)An Introduction to Apache Geode (incubating)
An Introduction to Apache Geode (incubating)
 
Going asynchronous with netty - SOSCON 2015
Going asynchronous with netty - SOSCON 2015Going asynchronous with netty - SOSCON 2015
Going asynchronous with netty - SOSCON 2015
 
Apache ignite Datagrid
Apache ignite DatagridApache ignite Datagrid
Apache ignite Datagrid
 
Pivotal 전략 업데이트 2015 Feb
Pivotal 전략 업데이트 2015 FebPivotal 전략 업데이트 2015 Feb
Pivotal 전략 업데이트 2015 Feb
 
祝 top-level project Apache Geode
祝 top-level project Apache Geode祝 top-level project Apache Geode
祝 top-level project Apache Geode
 
Hazelcast 소개
Hazelcast 소개Hazelcast 소개
Hazelcast 소개
 
오픈소스 성능 최적화 보고서 ch07. Infinispan
오픈소스 성능 최적화 보고서 ch07. Infinispan오픈소스 성능 최적화 보고서 ch07. Infinispan
오픈소스 성능 최적화 보고서 ch07. Infinispan
 

Kürzlich hochgeladen

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbuapidays
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 

Kürzlich hochgeladen (20)

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 

Keeping Infinispan In Shape: Highly-Precise, Scalable Data Eviction

  • 1. galder@jboss.org | twitter.com/galderz | zamarreno.com Thursday, October 7, 2010
  • 2. Keeping Infinispan In Shape: Highly-Precise, Scalable Data Eviction Galder Zamarreño & Vladimir Blagojevic Senior Engineer, Red Hat 7th October 2010, JUDCon - Berlin galder@jboss.org | twitter.com/galderz | zamarreno.com Thursday, October 7, 2010
  • 3. Who is Galder? • R&D engineer (Red Hat Inc): • Infinispan developer • JBoss Cache developer • Contributor and committer: • JBoss AS, Hibernate, JGroups, JBoss Portal,...etc • Blog: zamarreno.com • Twitter: @galderz galder@jboss.org | twitter.com/galderz | zamarreno.com Thursday, October 7, 2010
  • 4. Agenda • Eviction in: • Java Collections Framework • JBoss Cache • Infinispan 4.0 • New in Infinispan 4.1: • LIRS • Batching Updates galder@jboss.org | twitter.com/galderz | zamarreno.com Thursday, October 7, 2010
  • 5. Java Collections Framework • Key building block of any Java app • Introduced in Java 1.2 • Extended with concurrent collections in Java 1.5 • Collection element eviction ?? galder@jboss.org | twitter.com/galderz | zamarreno.com Thursday, October 7, 2010
  • 6. Collections cannot grow forever galder@jboss.org | twitter.com/galderz | zamarreno.com Thursday, October 7, 2010
  • 7. If using a collection as cache • Forces clients to either: • Remove elements proactively • Or run a periodic cleanup process • Which can be a PITA... galder@jboss.org | twitter.com/galderz | zamarreno.com Thursday, October 7, 2010
  • 8. Eviction in JBoss Cache days galder@jboss.org | twitter.com/galderz | zamarreno.com Thursday, October 7, 2010
  • 9. JBoss Cache eviction issues • Under heavy load, eviction queues could fill up - bottleneck • Possibly a side effect of MVCC’s non-blocking reads • Separating data into regions could alleviate the issue • But it’s really a hack! galder@jboss.org | twitter.com/galderz | zamarreno.com Thursday, October 7, 2010
  • 10. Original Infinispan 4.0 eviction • Tried a different approach: • Avoid using queues to hold events • Taking advantage of tree to map change: • Attempt to maintain map ordered as per eviction rules • Could we use ConcurrentSkipListMap ? • No. O(1) desired for all map operations galder@jboss.org | twitter.com/galderz | zamarreno.com Thursday, October 7, 2010
  • 11. Doubly Linked ConcurrentHashMap • Based on H.Sundell and P.Tsigas paper: • Lock-Free Deques and Doubly Linked Lists (2008) • With each cache access or update update links • Eviction just a matter of walking the linked list one way galder@jboss.org | twitter.com/galderz | zamarreno.com Thursday, October 7, 2010
  • 12. Issues under heavy load • Algorithm always uses same node (the tail) to append stuff • With high concurrency, CAS stress lead to loads of retrying • So much retrying, we’re getting infinite loops • Before 4.0.0.Final, reverted to a more conservative algorithm galder@jboss.org | twitter.com/galderz | zamarreno.com Thursday, October 7, 2010
  • 13. 4.0.0.Final eviction galder@jboss.org | twitter.com/galderz | zamarreno.com Thursday, October 7, 2010
  • 14. LRU eviction algorithm issues • Weak access locality • One-time accessed keys not evicted timely • In loops, soon to be accessed keys might get evicted first • With distinct access frequencies, frequently accessed keys can unfortunately get evicted • LRU’s working set limited to cache size galder@jboss.org | twitter.com/galderz | zamarreno.com Thursday, October 7, 2010
  • 15. Enter the room... LIRS • Eviction algorithm that can cope with weak access locality • Based on S.Jiang and X.Zhang’s 2002 paper: • LIRS: An efficient low inter-reference recency set replacement policy to improve buffer cache performance • LIRS based around two concepts: IRR and Recency galder@jboss.org | twitter.com/galderz | zamarreno.com Thursday, October 7, 2010
  • 16. IRR and Recency • Inter-Reference Recency (IRR): • Number of other unique keys accessed between two consecutive accesses to same key • Recency (R) • Number of other unique keys accessed from last reference until now galder@jboss.org | twitter.com/galderz | zamarreno.com Thursday, October 7, 2010
  • 17. How does LIRS work? • If key has a high IRR, it’s next IRR is likely to be high again • Keys with highest IRR are considered for eviction • Once IRR is out of date, we start relying on Recency • LIRS = Low Inter-reference Recency Set galder@jboss.org | twitter.com/galderz | zamarreno.com Thursday, October 7, 2010
  • 18. How is LIRS implemented? • Low IRR (LIR) area • Holds hot keys! • High IRR (HIR) area • Holds recently accessed keys • Keys here might get promoted to LIR area galder@jboss.org | twitter.com/galderz | zamarreno.com Thursday, October 7, 2010
  • 19. Cache Hit - LIR area galder@jboss.org | twitter.com/galderz | zamarreno.com Thursday, October 7, 2010
  • 20. Cache Hit - LIR area galder@jboss.org | twitter.com/galderz | zamarreno.com Thursday, October 7, 2010
  • 21. Hit - HIR area and in LIR Q ... galder@jboss.org | twitter.com/galderz | zamarreno.com Thursday, October 7, 2010
  • 22. Hit - HIR area and in LIR Q galder@jboss.org | twitter.com/galderz | zamarreno.com Thursday, October 7, 2010
  • 23. Hit - HIR area and not in LIR Q galder@jboss.org | twitter.com/galderz | zamarreno.com Thursday, October 7, 2010
  • 24. Cache Miss galder@jboss.org | twitter.com/galderz | zamarreno.com Thursday, October 7, 2010
  • 25. Cache Miss galder@jboss.org | twitter.com/galderz | zamarreno.com Thursday, October 7, 2010
  • 26. Cache Miss galder@jboss.org | twitter.com/galderz | zamarreno.com Thursday, October 7, 2010
  • 27. LIRS implementation hurdles • LIRS requires a lot of key shifting around • It can lead to high contention • Unless you can implement it in scalable way, it’s useless • Low contended way to implement a high precision eviction algorithm? Is it possible? galder@jboss.org | twitter.com/galderz | zamarreno.com Thursday, October 7, 2010
  • 28. Batching Eviction Updates • Original idea: X.Ding, S.Jiang and X.Zhang’s 2009 paper: • BP-Wrapper: A System Framework Making Any Replacement Algorithms (Almost) Lock Contention Free • Keeping cache access per thread in a queue • If queue reaches a threshold: • Acquire locks and execute eviction as per algorithm • Batching updates significantly lowers lock contention galder@jboss.org | twitter.com/galderz | zamarreno.com Thursday, October 7, 2010
  • 29. Batching Updates in Infinispan • Decided against recording access per thread • 100s threads could be hitting cache; some short lived • Created BoundedConcurrentHashMap • Based on Doug Lea's ConcurrentHashMap • Records accesses in a lock-free queue in each segment • When threshold passed, acquire lock for segment and evict galder@jboss.org | twitter.com/galderz | zamarreno.com Thursday, October 7, 2010
  • 30. Precision and Performance • Segment level eviction does not affect overall precision • Community member run some performance tests: • After swapping their own LRU cache with BoundedCHM: • Berlin SPARQL Benchmark performance increased 55-60% for both cold and hot caches galder@jboss.org | twitter.com/galderz | zamarreno.com Thursday, October 7, 2010
  • 31. Summary • In JBoss Cache, eviction can become a bottleneck • Infinispan 4.0 uses conservative eviction • Infinispan 4.1 has more precise eviction algorithm (LIRS) • Batching updates, present in 4.1, significantly lowers lock contention • Result = Highly-concurrent, highly-precise implicit eviction galder@jboss.org | twitter.com/galderz | zamarreno.com Thursday, October 7, 2010
  • 32. Questions? infinispan.org blog.infinispan.org twitter.com/infinispan #infinispan #judcon galder@jboss.org | twitter.com/galderz | zamarreno.com Thursday, October 7, 2010