SlideShare a Scribd company logo
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 (20)

PDF
Debugging & Tuning in Spark
Shiao-An Yuan
 
PDF
Introduction to Apache Tajo: Data Warehouse for Big Data
Jihoon Son
 
PPTX
Paralell
Mark Vicuna
 
PPTX
Modern software design in Big data era
Bill GU
 
PPT
BDAS Shark study report 03 v1.1
Stefanie Zhao
 
PDF
Apache tajo configuration
Jihoon Son
 
PPT
Whirlwind tour of Hadoop and HIve
Edward Capriolo
 
PDF
Alexander Ignatyev "MapReduce infrastructure"
Yandex
 
PPT
9b. Document-Oriented Databases lab
Fabio Fumarola
 
PDF
Intro to Apache Hadoop
Sufi Nawaz
 
PDF
Introduction to mongo db
Lawrence Mwai
 
PDF
Advanced Scenegraph Rendering Pipeline
Narann29
 
PDF
Postgres database Ibrahem Batta
Ibrahem Batta
 
PDF
Clique square storage
INRIA-OAK
 
PPTX
Rest3d BOF presentation at SigGraph 2013
Remi Arnaud
 
PPTX
Java one2015 - Work With Hundreds of Hot Terabytes in JVMs
Speedment, Inc.
 
PPT
Upgrading To The New Map Reduce API
Tom Croucher
 
PDF
An introduction to Big-Data processing applying hadoop
Amir Sedighi
 
PDF
Cliff Click Explains GBM at Netflix October 10 2013
Sri Ambati
 
PDF
GBM in H2O with Cliff Click: H2O API
Sri Ambati
 
Debugging & Tuning in Spark
Shiao-An Yuan
 
Introduction to Apache Tajo: Data Warehouse for Big Data
Jihoon Son
 
Paralell
Mark Vicuna
 
Modern software design in Big data era
Bill GU
 
BDAS Shark study report 03 v1.1
Stefanie Zhao
 
Apache tajo configuration
Jihoon Son
 
Whirlwind tour of Hadoop and HIve
Edward Capriolo
 
Alexander Ignatyev "MapReduce infrastructure"
Yandex
 
9b. Document-Oriented Databases lab
Fabio Fumarola
 
Intro to Apache Hadoop
Sufi Nawaz
 
Introduction to mongo db
Lawrence Mwai
 
Advanced Scenegraph Rendering Pipeline
Narann29
 
Postgres database Ibrahem Batta
Ibrahem Batta
 
Clique square storage
INRIA-OAK
 
Rest3d BOF presentation at SigGraph 2013
Remi Arnaud
 
Java one2015 - Work With Hundreds of Hot Terabytes in JVMs
Speedment, Inc.
 
Upgrading To The New Map Reduce API
Tom Croucher
 
An introduction to Big-Data processing applying hadoop
Amir Sedighi
 
Cliff Click Explains GBM at Netflix October 10 2013
Sri Ambati
 
GBM in H2O with Cliff Click: H2O API
Sri Ambati
 

Viewers also liked (8)

PDF
STEMing Kids: One workshop at a time
JavaDayUA
 
PPTX
Actividad quinto mes monica araque.docx
moni tosca
 
PDF
OrientDB and Hazelcast
Luca Garulli
 
PDF
JavaOne 2013: Memory Efficient Java
Chris Bailey
 
PDF
Web APIでThriftをシリアライザとして使う
h_kishi
 
PPTX
Hibernate performance tuning
Mikalai Alimenkou
 
PPTX
Thrift vs Protocol Buffers vs Avro - Biased Comparison
Igor Anishchenko
 
PPTX
Unique ID generation in distributed systems
Dave Gardner
 
STEMing Kids: One workshop at a time
JavaDayUA
 
Actividad quinto mes monica araque.docx
moni tosca
 
OrientDB and Hazelcast
Luca Garulli
 
JavaOne 2013: Memory Efficient Java
Chris Bailey
 
Web APIでThriftをシリアライザとして使う
h_kishi
 
Hibernate performance tuning
Mikalai Alimenkou
 
Thrift vs Protocol Buffers vs Avro - Biased Comparison
Igor Anishchenko
 
Unique ID generation in distributed systems
Dave Gardner
 
Ad

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

PPTX
Map db
Debmalya Jash
 
PPTX
Jug Lugano - Scale over the limits
Davide Carnevali
 
KEY
Taming NoSQL with Spring Data
Sergi Almar i Graupera
 
PPTX
Map-Interface-and-HashMap-in-Java-A-Deep-Dive.pptx.pptx
iamzynix
 
PDF
Hash map (java platform se 8 )
charan kumar
 
PDF
Hidden pearls for High-Performance-Persistence
Sven Ruppert
 
ODP
Vote NO for MySQL
Ulf Wendel
 
PPT
Wmware NoSQL
Murat Çakal
 
PDF
Lecture notesmap
Vasanti Dutta
 
PDF
Mongodb my
Alexey Gaziev
 
PDF
MongoDB
SPBRUBY
 
PDF
Beware of your Hype Value Stores
Jérémie BORDIER
 
PDF
Guava Overview Part 2 Bucharest JUG #2
Andrei Savu
 
PDF
Spring one2gx2010 spring-nonrelational_data
Roger Xia
 
KEY
TriHUG - Beyond Batch
boorad
 
PDF
Collections forceawakens
RichardWarburton
 
PDF
No sql presentation
Saifuddin Kaijar
 
PDF
Database backed coherence cache
aragozin
 
PPT
How to Stop Worrying and Start Caching in Java
srisatish ambati
 
Jug Lugano - Scale over the limits
Davide Carnevali
 
Taming NoSQL with Spring Data
Sergi Almar i Graupera
 
Map-Interface-and-HashMap-in-Java-A-Deep-Dive.pptx.pptx
iamzynix
 
Hash map (java platform se 8 )
charan kumar
 
Hidden pearls for High-Performance-Persistence
Sven Ruppert
 
Vote NO for MySQL
Ulf Wendel
 
Wmware NoSQL
Murat Çakal
 
Lecture notesmap
Vasanti Dutta
 
Mongodb my
Alexey Gaziev
 
MongoDB
SPBRUBY
 
Beware of your Hype Value Stores
Jérémie BORDIER
 
Guava Overview Part 2 Bucharest JUG #2
Andrei Savu
 
Spring one2gx2010 spring-nonrelational_data
Roger Xia
 
TriHUG - Beyond Batch
boorad
 
Collections forceawakens
RichardWarburton
 
No sql presentation
Saifuddin Kaijar
 
Database backed coherence cache
aragozin
 
How to Stop Worrying and Start Caching in Java
srisatish ambati
 
Ad

More from JavaDayUA (20)

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

Recently uploaded (20)

PDF
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
PDF
Online Queue Management System for Public Service Offices in Nepal [Focused i...
Rishab Acharya
 
PDF
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
PDF
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
PPTX
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
PDF
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
PDF
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
PDF
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
PDF
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
PDF
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
PPTX
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
PPTX
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
PPTX
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
PPTX
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PPTX
Human Resources Information System (HRIS)
Amity University, Patna
 
PDF
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
PPTX
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
PPTX
Transforming Mining & Engineering Operations with Odoo ERP | Streamline Proje...
SatishKumar2651
 
PDF
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
Online Queue Management System for Public Service Offices in Nepal [Focused i...
Rishab Acharya
 
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Human Resources Information System (HRIS)
Amity University, Patna
 
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
Transforming Mining & Engineering Operations with Odoo ERP | Streamline Proje...
SatishKumar2651
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 

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 ● [email protected] ● @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