SlideShare a Scribd company logo
1 of 17
Download to read offline
www.mapdb.org
MapDB
Taking java collections to next level
www.mapdb.org
www.mapdb.org
Me
● Jan@Kotek.net
● @JanKotek
● Independent consultant
● I took over MapDB in 2010
(it started in 1999 under name JDBM)
● Last 3 years I work on MapDB full time
www.mapdb.org
MapDB
● MapDB is embedded database engine
● ACID, isolation etc..., this talks only covers
in-memory mode with transactions disabled
● Apache 2 licensed
● Maps and other Java collections
● Flexible component architecture
● Very fast
● Speed comporable to Java Collections
● No degradation by Garbage Collection
● 600 KB jar, no deps, pure java
www.mapdb.org
Hello World
DB db = DBMaker
.memoryDB()
.make();
Map<Long,UUID> map = db
.treeMapCreate("map")
.keySerializer(Serializer.LONG)
.valueSerializer(Serializer.UUID)
.nodeSize(64)
.make();
www.mapdb.org
Random Map<Long,UUID>.put() performance
Time to update 100M random keys on Map with 100M entries (smaller is better)
www.mapdb.org
Random Map<Long,UUID>.get() performance
Time to get 100M random keys on Map with 100M entries (smaller is better)
www.mapdb.org
HashMap
● Hashtable is tree with upto 3 levels
● (no fixed sized array)
● No rehashing and no reinsert on grow or
shrink
● Empty hash position does not use space
● Concurrent, 16 segments with separate locking
● Expiration
● Modification Listeners
www.mapdb.org
HashMap - expiration
● Expiration based on TTL, memory limit and number of
entries
● Aproximate expiration (+- 100 entries) for better performance
● Concurrent, 16 separate segment, each with separate queue
and lock
Map map = db
.hashMapCreate("cache")
.expireMaxSize(1000000)
.expireAfterWrite(30, TimeUnit.HOURS)
.expireAfterAccess(10, TimeUnit.HOURS)
.make();
www.mapdb.org
TreeMap
● Full ConcurrentNavigableMap implementation
● (only alternative implementation I know about)
● Transparent specialized keys
● Long → long
● Strings → byte[] or char[] depending on
encoding
● B-Link Tree ( Yehoshua Sagiv 1986)
● Highly concurrent
● No locks on read, one Lock per node on
update
● On delete empty nodes are not removed :-(
● Modification listeners
www.mapdb.org
TreeMap<Long,UUID> – number of entries in 1GB memory
www.mapdb.org
TreeMap – Key Representation
● class LeafNode{ Object[] keys, Object[] values}
● Data interpretation such as array size, binary search, update,
split... is done in plugable serializer
● Array of keys and values can be represented in many ways
● Object[]
● long[]
● char[][] → char[]
● Delta compression
● [ 6001, 6001, 6002 ] stored as [ 6000, 1, 1 ]
→ only 4 bytes in packed longs
● Common prefix compression
● [ “New Orleans, “New York” ] stored as
[ “New “, ”Orleans”, ”York”]
www.mapdb.org
TreeMap - Data Pump
● Imports TreeMap very fast
● First creates Leaf Nodes, than builds Tree
Nodes on top
● Insert only operation, no random updates
● Inserts millions of entries per second
● Insert speed is constant, no degradation with
large sets
● 1B (1e9) entry map is created overnight on
slow rotating HDD
www.mapdb.org
Bind
● Collections provide Modification Listeners
● Bind is utility on top of listeners which binds two
collections together
● Secondary collection is automatically modified
by changes in first
www.mapdb.org
Bind – secondary Map
HTreeMap<Long, String> primary =
DBMaker.memoryDB().make().hashMap("test");
// secondary map will hold String.size()
Map<Long,Integer> secondary = new HashMap();
//Bind maps together
Bind.secondaryValue(primary, secondary,
{ (Long key, String value) =>
return value.lenght()
});
primary.put(111L, "just some chars");
secondary.get(111L) => 15
www.mapdb.org
Bind – overflow to disk after expiration
// slow large collection on disk
HTreeMap onDisk = db.hashMap("onDisk").make();
// fast in-memory collection with limited size
// its content is moved to disk after it expires
HTreeMap inMemory = db
.hashMapCreate("inMemory")
.expireAfterAccess(1, TimeUnit.SECONDS)
// register overflow
.expireOverflow(onDisk, true)
.executorEnable()
.make();
www.mapdb.org
Current status
● MapDB 1.0 is out
● MapDB 2.0 release is coming soon
● At this point its faster and more stable than 1.0
● Issues with on-disk mode and recovery after crash
('kill -9' unit test fails now)
● MapDB 2.1 will follow soon
● It will improve concurrency
● Will have long term support for couple of years
(API, format)
● Java 8 Streams support
www.mapdb.org
Conclusion
● Better memory usage
● Reasonable performance
● Extra features such as expiration
● I hope you will find it useful :-)
● Resources
● www.mapdb.org
● github.com/jankotek/mapdb

More Related Content

What's hot

Rest3d BOF presentation at SigGraph 2013
Rest3d BOF presentation at SigGraph 2013Rest3d BOF presentation at SigGraph 2013
Rest3d BOF presentation at SigGraph 2013
Remi Arnaud
 

What's hot (20)

Debugging & Tuning in Spark
Debugging & Tuning in SparkDebugging & Tuning in Spark
Debugging & Tuning in Spark
 
Introduction to Apache Tajo: Data Warehouse for Big Data
Introduction to Apache Tajo: Data Warehouse for Big DataIntroduction to Apache Tajo: Data Warehouse for Big Data
Introduction to Apache Tajo: Data Warehouse for Big Data
 
Paralell
ParalellParalell
Paralell
 
Modern software design in Big data era
Modern software design in Big data eraModern software design in Big data era
Modern software design in Big data era
 
BDAS Shark study report 03 v1.1
BDAS Shark study report  03 v1.1BDAS Shark study report  03 v1.1
BDAS Shark study report 03 v1.1
 
Apache tajo configuration
Apache tajo configurationApache tajo configuration
Apache tajo configuration
 
Whirlwind tour of Hadoop and HIve
Whirlwind tour of Hadoop and HIveWhirlwind tour of Hadoop and HIve
Whirlwind tour of Hadoop and HIve
 
Alexander Ignatyev "MapReduce infrastructure"
Alexander Ignatyev "MapReduce infrastructure"Alexander Ignatyev "MapReduce infrastructure"
Alexander Ignatyev "MapReduce infrastructure"
 
9b. Document-Oriented Databases lab
9b. Document-Oriented Databases lab9b. Document-Oriented Databases lab
9b. Document-Oriented Databases lab
 
Intro to Apache Hadoop
Intro to Apache HadoopIntro to Apache Hadoop
Intro to Apache Hadoop
 
Introduction to mongo db
Introduction to mongo dbIntroduction to mongo db
Introduction to mongo db
 
Advanced Scenegraph Rendering Pipeline
Advanced Scenegraph Rendering PipelineAdvanced Scenegraph Rendering Pipeline
Advanced Scenegraph Rendering Pipeline
 
Postgres database Ibrahem Batta
Postgres database Ibrahem BattaPostgres database Ibrahem Batta
Postgres database Ibrahem Batta
 
Clique square storage
Clique square storageClique square storage
Clique square storage
 
Rest3d BOF presentation at SigGraph 2013
Rest3d BOF presentation at SigGraph 2013Rest3d BOF presentation at SigGraph 2013
Rest3d BOF presentation at SigGraph 2013
 
Java one2015 - Work With Hundreds of Hot Terabytes in JVMs
Java one2015 - Work With Hundreds of Hot Terabytes in JVMsJava one2015 - Work With Hundreds of Hot Terabytes in JVMs
Java one2015 - Work With Hundreds of Hot Terabytes in JVMs
 
Upgrading To The New Map Reduce API
Upgrading To The New Map Reduce APIUpgrading To The New Map Reduce API
Upgrading To The New Map Reduce API
 
An introduction to Big-Data processing applying hadoop
An introduction to Big-Data processing applying hadoopAn introduction to Big-Data processing applying hadoop
An introduction to Big-Data processing applying hadoop
 
Cliff Click Explains GBM at Netflix October 10 2013
Cliff Click Explains GBM at Netflix October 10 2013Cliff Click Explains GBM at Netflix October 10 2013
Cliff Click Explains GBM at Netflix October 10 2013
 
GBM in H2O with Cliff Click: H2O API
GBM in H2O with Cliff Click: H2O APIGBM in H2O with Cliff Click: H2O API
GBM in H2O with Cliff Click: H2O API
 

Viewers also liked

Viewers also liked (8)

STEMing Kids: One workshop at a time
STEMing Kids: One workshop at a timeSTEMing Kids: One workshop at a time
STEMing Kids: One workshop at a time
 
Actividad quinto mes monica araque.docx
Actividad quinto mes monica araque.docxActividad quinto mes monica araque.docx
Actividad quinto mes monica araque.docx
 
OrientDB and Hazelcast
OrientDB and HazelcastOrientDB and Hazelcast
OrientDB and Hazelcast
 
JavaOne 2013: Memory Efficient Java
JavaOne 2013: Memory Efficient JavaJavaOne 2013: Memory Efficient Java
JavaOne 2013: Memory Efficient Java
 
Web APIでThriftをシリアライザとして使う
Web APIでThriftをシリアライザとして使うWeb APIでThriftをシリアライザとして使う
Web APIでThriftをシリアライザとして使う
 
Hibernate performance tuning
Hibernate performance tuningHibernate performance tuning
Hibernate performance tuning
 
Thrift vs Protocol Buffers vs Avro - Biased Comparison
Thrift vs Protocol Buffers vs Avro - Biased ComparisonThrift vs Protocol Buffers vs Avro - Biased Comparison
Thrift vs Protocol Buffers vs Avro - Biased Comparison
 
Unique ID generation in distributed systems
Unique ID generation in distributed systemsUnique ID generation in distributed systems
Unique ID generation in distributed systems
 

Similar to MapDB - taking Java collections to the next level

Intro to Spark - for Denver Big Data Meetup
Intro to Spark - for Denver Big Data MeetupIntro to Spark - for Denver Big Data Meetup
Intro to Spark - for Denver Big Data Meetup
Gwen (Chen) Shapira
 
Hadoop - Introduction to map reduce programming - Reunião 12/04/2014
Hadoop - Introduction to map reduce programming - Reunião 12/04/2014Hadoop - Introduction to map reduce programming - Reunião 12/04/2014
Hadoop - Introduction to map reduce programming - Reunião 12/04/2014
soujavajug
 

Similar to MapDB - taking Java collections to the next level (20)

Geo data analytics
Geo data analyticsGeo data analytics
Geo data analytics
 
Scala and spark
Scala and sparkScala and spark
Scala and spark
 
Apache spark - Spark's distributed programming model
Apache spark - Spark's distributed programming modelApache spark - Spark's distributed programming model
Apache spark - Spark's distributed programming model
 
Apache Spark™ is a multi-language engine for executing data-S5.ppt
Apache Spark™ is a multi-language engine for executing data-S5.pptApache Spark™ is a multi-language engine for executing data-S5.ppt
Apache Spark™ is a multi-language engine for executing data-S5.ppt
 
Hadoop
HadoopHadoop
Hadoop
 
Spark 计算模型
Spark 计算模型Spark 计算模型
Spark 计算模型
 
Tuning and Debugging in Apache Spark
Tuning and Debugging in Apache SparkTuning and Debugging in Apache Spark
Tuning and Debugging in Apache Spark
 
Introduction to map reduce
Introduction to map reduceIntroduction to map reduce
Introduction to map reduce
 
Intro to Spark - for Denver Big Data Meetup
Intro to Spark - for Denver Big Data MeetupIntro to Spark - for Denver Big Data Meetup
Intro to Spark - for Denver Big Data Meetup
 
Hadoop - Introduction to map reduce programming - Reunião 12/04/2014
Hadoop - Introduction to map reduce programming - Reunião 12/04/2014Hadoop - Introduction to map reduce programming - Reunião 12/04/2014
Hadoop - Introduction to map reduce programming - Reunião 12/04/2014
 
Tuning and Debugging in Apache Spark
Tuning and Debugging in Apache SparkTuning and Debugging in Apache Spark
Tuning and Debugging in Apache Spark
 
Hadoop - Introduction to HDFS
Hadoop - Introduction to HDFSHadoop - Introduction to HDFS
Hadoop - Introduction to HDFS
 
Boston Apache Spark User Group (the Spahk group) - Introduction to Spark - 15...
Boston Apache Spark User Group (the Spahk group) - Introduction to Spark - 15...Boston Apache Spark User Group (the Spahk group) - Introduction to Spark - 15...
Boston Apache Spark User Group (the Spahk group) - Introduction to Spark - 15...
 
lecture11_GPUArchCUDA01.pptx
lecture11_GPUArchCUDA01.pptxlecture11_GPUArchCUDA01.pptx
lecture11_GPUArchCUDA01.pptx
 
Introduction to Apache Spark
Introduction to Apache SparkIntroduction to Apache Spark
Introduction to Apache Spark
 
DTCC '14 Spark Runtime Internals
DTCC '14 Spark Runtime InternalsDTCC '14 Spark Runtime Internals
DTCC '14 Spark Runtime Internals
 
Apache Spark
Apache SparkApache Spark
Apache Spark
 
Understanding Hadoop
Understanding HadoopUnderstanding Hadoop
Understanding Hadoop
 
Sorry - How Bieber broke Google Cloud at Spotify
Sorry - How Bieber broke Google Cloud at SpotifySorry - How Bieber broke Google Cloud at Spotify
Sorry - How Bieber broke Google Cloud at Spotify
 
Bsdtw17: brooks davis: is it time to replace mmap?
Bsdtw17: brooks davis: is it time to replace mmap?Bsdtw17: brooks davis: is it time to replace mmap?
Bsdtw17: brooks davis: is it time to replace mmap?
 

More from JavaDayUA

More from JavaDayUA (20)

Flavors of Concurrency in Java
Flavors of Concurrency in JavaFlavors of Concurrency in Java
Flavors of Concurrency in Java
 
What to expect from Java 9
What to expect from Java 9What to expect from Java 9
What to expect from Java 9
 
Continuously building, releasing and deploying software: The Revenge of the M...
Continuously building, releasing and deploying software: The Revenge of the M...Continuously building, releasing and deploying software: The Revenge of the M...
Continuously building, releasing and deploying software: The Revenge of the M...
 
The Epic Groovy Puzzlers S02: The Revenge of the Parentheses
The Epic Groovy Puzzlers S02: The Revenge of the ParenthesesThe Epic Groovy Puzzlers S02: The Revenge of the Parentheses
The Epic Groovy Puzzlers S02: The Revenge of the Parentheses
 
20 Years of Java
20 Years of Java20 Years of Java
20 Years of Java
 
How to get the most out of code reviews
How to get the most out of code reviewsHow to get the most out of code reviews
How to get the most out of code reviews
 
Unlocking the Magic of Monads with Java 8
Unlocking the Magic of Monads with Java 8Unlocking the Magic of Monads with Java 8
Unlocking the Magic of Monads with Java 8
 
Virtual Private Cloud with container technologies for DevOps
Virtual Private Cloud with container technologies for DevOpsVirtual Private Cloud with container technologies for DevOps
Virtual Private Cloud with container technologies for DevOps
 
JShell: An Interactive Shell for the Java Platform
JShell: An Interactive Shell for the Java PlatformJShell: An Interactive Shell for the Java Platform
JShell: An Interactive Shell for the Java Platform
 
Interactive Java Support to your tool -- The JShell API and Architecture
Interactive Java Support to your tool -- The JShell API and ArchitectureInteractive Java Support to your tool -- The JShell API and Architecture
Interactive Java Support to your tool -- The JShell API and Architecture
 
Design rationales in the JRockit JVM
Design rationales in the JRockit JVMDesign rationales in the JRockit JVM
Design rationales in the JRockit JVM
 
Next-gen DevOps engineering with Docker and Kubernetes by Antons Kranga
Next-gen DevOps engineering with Docker and Kubernetes by Antons KrangaNext-gen DevOps engineering with Docker and Kubernetes by Antons Kranga
Next-gen DevOps engineering with Docker and Kubernetes by Antons Kranga
 
Apache Cassandra. Inception - all you need to know by Mikhail Dubkov
Apache Cassandra. Inception - all you need to know by Mikhail DubkovApache Cassandra. Inception - all you need to know by Mikhail Dubkov
Apache Cassandra. Inception - all you need to know by Mikhail Dubkov
 
Solution Architecture tips & tricks by Roman Shramkov
Solution Architecture tips & tricks by Roman ShramkovSolution Architecture tips & tricks by Roman Shramkov
Solution Architecture tips & tricks by Roman Shramkov
 
Testing in Legacy: from Rags to Riches by Taras Slipets
Testing in Legacy: from Rags to Riches by Taras SlipetsTesting in Legacy: from Rags to Riches by Taras Slipets
Testing in Legacy: from Rags to Riches by Taras Slipets
 
Reactive programming and Hystrix fault tolerance by Max Myslyvtsev
Reactive programming and Hystrix fault tolerance by Max MyslyvtsevReactive programming and Hystrix fault tolerance by Max Myslyvtsev
Reactive programming and Hystrix fault tolerance by Max Myslyvtsev
 
Spark-driven audience counting by Boris Trofimov
Spark-driven audience counting by Boris TrofimovSpark-driven audience counting by Boris Trofimov
Spark-driven audience counting by Boris Trofimov
 
API first with Swagger and Scala by Slava Schmidt
API first with Swagger and Scala by  Slava SchmidtAPI first with Swagger and Scala by  Slava Schmidt
API first with Swagger and Scala by Slava Schmidt
 
JavaFX 8 everywhere; write once run anywhere by Mohamed Taman
JavaFX 8 everywhere; write once run anywhere by Mohamed TamanJavaFX 8 everywhere; write once run anywhere by Mohamed Taman
JavaFX 8 everywhere; write once run anywhere by Mohamed Taman
 
Web-application I have always dreamt of by Victor Polischuk
Web-application I have always dreamt of by Victor PolischukWeb-application I have always dreamt of by Victor Polischuk
Web-application I have always dreamt of by Victor Polischuk
 

Recently uploaded

%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
chiefasafspells
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 

Recently uploaded (20)

WSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AIWSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AI
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 

MapDB - taking Java collections to the next level

  • 1. www.mapdb.org MapDB Taking java collections to next level www.mapdb.org
  • 2. www.mapdb.org Me ● Jan@Kotek.net ● @JanKotek ● Independent consultant ● I took over MapDB in 2010 (it started in 1999 under name JDBM) ● Last 3 years I work on MapDB full time
  • 3. www.mapdb.org MapDB ● MapDB is embedded database engine ● ACID, isolation etc..., this talks only covers in-memory mode with transactions disabled ● Apache 2 licensed ● Maps and other Java collections ● Flexible component architecture ● Very fast ● Speed comporable to Java Collections ● No degradation by Garbage Collection ● 600 KB jar, no deps, pure java
  • 4. www.mapdb.org Hello World DB db = DBMaker .memoryDB() .make(); Map<Long,UUID> map = db .treeMapCreate("map") .keySerializer(Serializer.LONG) .valueSerializer(Serializer.UUID) .nodeSize(64) .make();
  • 5. www.mapdb.org Random Map<Long,UUID>.put() performance Time to update 100M random keys on Map with 100M entries (smaller is better)
  • 6. www.mapdb.org Random Map<Long,UUID>.get() performance Time to get 100M random keys on Map with 100M entries (smaller is better)
  • 7. www.mapdb.org HashMap ● Hashtable is tree with upto 3 levels ● (no fixed sized array) ● No rehashing and no reinsert on grow or shrink ● Empty hash position does not use space ● Concurrent, 16 segments with separate locking ● Expiration ● Modification Listeners
  • 8. www.mapdb.org HashMap - expiration ● Expiration based on TTL, memory limit and number of entries ● Aproximate expiration (+- 100 entries) for better performance ● Concurrent, 16 separate segment, each with separate queue and lock Map map = db .hashMapCreate("cache") .expireMaxSize(1000000) .expireAfterWrite(30, TimeUnit.HOURS) .expireAfterAccess(10, TimeUnit.HOURS) .make();
  • 9. www.mapdb.org TreeMap ● Full ConcurrentNavigableMap implementation ● (only alternative implementation I know about) ● Transparent specialized keys ● Long → long ● Strings → byte[] or char[] depending on encoding ● B-Link Tree ( Yehoshua Sagiv 1986) ● Highly concurrent ● No locks on read, one Lock per node on update ● On delete empty nodes are not removed :-( ● Modification listeners
  • 11. www.mapdb.org TreeMap – Key Representation ● class LeafNode{ Object[] keys, Object[] values} ● Data interpretation such as array size, binary search, update, split... is done in plugable serializer ● Array of keys and values can be represented in many ways ● Object[] ● long[] ● char[][] → char[] ● Delta compression ● [ 6001, 6001, 6002 ] stored as [ 6000, 1, 1 ] → only 4 bytes in packed longs ● Common prefix compression ● [ “New Orleans, “New York” ] stored as [ “New “, ”Orleans”, ”York”]
  • 12. www.mapdb.org TreeMap - Data Pump ● Imports TreeMap very fast ● First creates Leaf Nodes, than builds Tree Nodes on top ● Insert only operation, no random updates ● Inserts millions of entries per second ● Insert speed is constant, no degradation with large sets ● 1B (1e9) entry map is created overnight on slow rotating HDD
  • 13. www.mapdb.org Bind ● Collections provide Modification Listeners ● Bind is utility on top of listeners which binds two collections together ● Secondary collection is automatically modified by changes in first
  • 14. www.mapdb.org Bind – secondary Map HTreeMap<Long, String> primary = DBMaker.memoryDB().make().hashMap("test"); // secondary map will hold String.size() Map<Long,Integer> secondary = new HashMap(); //Bind maps together Bind.secondaryValue(primary, secondary, { (Long key, String value) => return value.lenght() }); primary.put(111L, "just some chars"); secondary.get(111L) => 15
  • 15. www.mapdb.org Bind – overflow to disk after expiration // slow large collection on disk HTreeMap onDisk = db.hashMap("onDisk").make(); // fast in-memory collection with limited size // its content is moved to disk after it expires HTreeMap inMemory = db .hashMapCreate("inMemory") .expireAfterAccess(1, TimeUnit.SECONDS) // register overflow .expireOverflow(onDisk, true) .executorEnable() .make();
  • 16. www.mapdb.org Current status ● MapDB 1.0 is out ● MapDB 2.0 release is coming soon ● At this point its faster and more stable than 1.0 ● Issues with on-disk mode and recovery after crash ('kill -9' unit test fails now) ● MapDB 2.1 will follow soon ● It will improve concurrency ● Will have long term support for couple of years (API, format) ● Java 8 Streams support
  • 17. www.mapdb.org Conclusion ● Better memory usage ● Reasonable performance ● Extra features such as expiration ● I hope you will find it useful :-) ● Resources ● www.mapdb.org ● github.com/jankotek/mapdb