SlideShare a Scribd company logo
ToroDB
SCALING PostgreSQL
LIKE MongoDB
@NoSQLonSQL
Álvaro Hernández <aht@torodb.com>
ToroDB @NoSQLonSQL
About *8Kdata*
● Research & Development in databases
●
Consulting, Training and Support in PostgreSQL
●
Founders of PostgreSQL España, 5th
largest PUG
in the world (>500 members as of today)
●
About myself: CTO at 8Kdata:
@ahachete
http://linkd.in/1jhvzQ3
www.8kdata.com
ToroDB @NoSQLonSQL
ToroDB in brief
ToroDB @NoSQLonSQL
ToroDB in one slide
●
Document-oriented, JSON, NoSQL db
●
Open source (AGPL)
●
MongoDB compatibility (wire protocol
level)
●
Uses PostgreSQL as a storage backend
ToroDB @NoSQLonSQL
ToroDB storage
●
Data is stored in tables. No blobs
●
JSON documents are split by hierarchy
levels into “subdocuments”, which
contain no nested structures. Each
subdocument level is stored separately
●
Subdocuments are classified by “type”.
Each “type” maps to a different table
ToroDB @NoSQLonSQL
ToroDB storage (II)
●
A “structure” table keeps the
subdocument “schema”
●
Keys in JSON are mapped to attributes,
which retain the original name
●
Tables are created dinamically and
transparently to match the exact types of
the documents
ToroDB @NoSQLonSQL
ToroDB storage internals
{
"name": "ToroDB",
"data": {
"a": 42, "b": "hello world!"
},
"nested": {
"j": 42,
"deeper": {
"a": 21, "b": "hello"
}
}
}
ToroDB @NoSQLonSQL
ToroDB storage internals
The document is split into the following subdocuments:
{ "name": "ToroDB", "data": {}, "nested": {} }
{ "a": 42, "b": "hello world!"}
{ "j": 42, "deeper": {}}
{ "a": 21, "b": "hello"}
ToroDB @NoSQLonSQL
ToroDB storage internals
select * from demo.t_3
┌─────┬───────┬────────────────────────────┬────────┐
│ did │ index │ _id │ name │
├─────┼───────┼────────────────────────────┼────────┤
│ 0 │ ¤ │ x5451a07de7032d23a908576d │ ToroDB │
└─────┴───────┴────────────────────────────┴────────┘
select * from demo.t_1
┌─────┬───────┬────┬──────────────┐
│ did │ index │ a │ b │
├─────┼───────┼────┼──────────────┤
│ 0 │ ¤ │ 42 │ hello world! │
│ 0 │ 1 │ 21 │ hello │
└─────┴───────┴────┴──────────────┘
select * from demo.t_2
┌─────┬───────┬────┐
│ did │ index │ j │
├─────┼───────┼────┤
│ 0 │ ¤ │ 42 │
└─────┴───────┴────┘
ToroDB @NoSQLonSQL
ToroDB storage internals
select * from demo.structures
┌─────┬────────────────────────────────────────────────────────────────────────────┐
│ sid │ _structure │
├─────┼────────────────────────────────────────────────────────────────────────────┤
│ 0 │ {"t": 3, "data": {"t": 1}, "nested": {"t": 2, "deeper": {"i": 1, "t": 1}}} │
└─────┴────────────────────────────────────────────────────────────────────────────┘
select * from demo.root;
┌─────┬─────┐
│ did │ sid │
├─────┼─────┤
│ 0 │ 0 │
└─────┴─────┘
ToroDB @NoSQLonSQL
ToroDB storage and I/O savings
29% - 68% storage required,
compared to Mongo 2.6
ToroDB @NoSQLonSQL
ToroDB: query “by structure”
●
ToroDB is effectively partitioning by
type
●
Structures (schemas, partitioning types)
are cached in ToroDB memory
●
Queries only scan a subset of the data
●
Negative queries are served directly
from memory
ToroDB @NoSQLonSQL
Scaling
ToroDB like MongoDB
ToroDB @NoSQLonSQL
Big Data: NoSQL vs SQL
vs
http://www.networkworld.com/article/2226514/tech-debates/what-s-better-for-your-big-data-application--sql-or-nosql-.html
ToroDB @NoSQLonSQL
Scalability?
ToroDB @NoSQLonSQL
Ways to scale
●
Vertical scalability
➔
Concurrency scalability
➔
Hardware scalability
➔
Query scalability
●
Read scalability (replication)
●
Write scalability (horizontal, sharding)
ToroDB @NoSQLonSQL
Vertical scalability
Concurrency scalability
●
SQL is usually better (e.g. PostgreSQL):
➔
Finer locking
➔
MVCC
➔
better caching
●
NoSQL often needs sharding within the
same host to scale
ToroDB @NoSQLonSQL
Vertical scalability
Hardware scalability
●
Scaling with the number of cores?
●
Process/threading model?
Query scalability
●
Use of indexes? Use of more than one?
●
Table/collection partitioning?
●
ToroDB “by-type” partitioning
ToroDB @NoSQLonSQL
Read scalability: replication
●
Replicate data to slave nodes, available
read-only: scale-out reads
●
Both NoSQL and SQL support it
●
Binary replication usually faster (e.g.
PostgreSQL's Streaming Replication)
●
Not free from undesirable phenomena
ToroDB @NoSQLonSQL
https://aphyr.com/posts/322-call-me-maybe-mongodb-stale-reads
Dirty and stale reads
(“call me maybe”)
ToroDB @NoSQLonSQL
MongoDB write acknowledge
https://aphyr.com/posts/322-call-me-maybe-mongodb-stale-reads
ToroDB @NoSQLonSQL
MongoDB's dirty and stale reads
Dirty reads
A primary in minority accepts a write that
other clients see, but it later steps down,
write is rolled back (fixed in 3.2?)
Stale reads
A primary in minority serves a value that
ought to be current, but a newer value
was written to the other primary in
minority
ToroDB @NoSQLonSQL
Write scalability
(sharding)
●
NoSQL better prepared than SQL
●
But many compromises in data
modeling (schema design): no FKs
●
There are also solutions for SQL:
➔
Shared-disk, limited scalability (RAC)
➔
Sharding (like pg_shard)
➔
PostgreSQL's FDWs
ToroDB @NoSQLonSQL
Read scalability (replication)
in MongoDB and ToroDB
ToroDB @NoSQLonSQL
Replication protocol choice
●
ToroDB is based on PostgreSQL
●
PostgreSQL has either binary streaming
replication (async or sync) or logical
replication
●
MongoDB has logical replication
●
ToroDB uses MongoDB's protocol
ToroDB @NoSQLonSQL
MongoDB's replication protocol
●
Every change is recorded in JSON
documents, idempotent format
(collection: local.oplog.rs)
●
Slaves pull these documents from master
(or other slaves) asynchronously
●
Changes are applied and feedback is
sent upstream
ToroDB @NoSQLonSQL
MongoDB replication implementation
https://github.com/stripe/mosql
ToroDB @NoSQLonSQL
Announcing ToroDB v0.4 (snap)
Supporting MongoDB replication
ToroDB @NoSQLonSQL
ToroDB v0.4
●
ToroDB works as a secondary slave of a
MongoDB master (or slave)
●
Implements the full replication protocol
(not an oplog tailable query)
●
Replicates from Mongo to a PostgreSQL
●
Open source github.com/torodb/torodb
(repl branch, version 0.4-SNAPSHOT)
ToroDB @NoSQLonSQL
Advantages of ToroDB w/ replication
●
Native SQL
●
Query “by type”
●
Better SQL scaling
●
Less concurrency contention
●
Better hardware utilization
●
No need for ETL from Mongo to PG!
ToroDB @NoSQLonSQL
●
NoSQL is trying to get back to SQL
●
ToroDB is SQL native!
●
Insert with Mongo, query with SQL!
●
Powerful PostgreSQL SQL: window
functions, recursive queries, hypothetical
aggregates, lateral joins, CTEs, etc
ToroDB: native SQL
ToroDB @NoSQLonSQL
ToroDB: native SQL
ToroDB @NoSQLonSQL
db.bds15.insert({
id:5, person: {
name: "Alvaro", surname: "Hernandez",
contact: { email: "aht@torodb.com", verified: true }
}
})
db.bds15.insert({
id:6, person: {
name: "Name", surname: "Surname", age: 31,
contact: { email: "name.surname@gmail.com" }
}
})
Introducing ToroDB VIEWs
ToroDB @NoSQLonSQL
torodb$ select * from bds15.person ;
┌─────┬───────────┬────────┬─────┐
│ did │ surname │ name │ age │
├─────┼───────────┼────────┼─────┤
│ 0 │ Hernandez │ Alvaro │ ¤ │
│ 1 │ Surname │ Name │ 31 │
└─────┴───────────┴────────┴─────┘
(2 rows)
torodb$ select * from bds15."person.contact";
┌─────┬──────────┬────────────────────────┐
│ did │ verified │ email │
├─────┼──────────┼────────────────────────┤
│ 0 │ t │ aht@torodb.com │
│ 1 │ ¤ │ name.surname@gmail.com │
└─────┴──────────┴────────────────────────┘
(2 rows)
Introducing ToroDB VIEWs
ToroDB @NoSQLonSQL
VIEWs, ToroDB from any SQL tool
ToroDB @NoSQLonSQL
Enabling real DW
on MongoDB:
ToroDB + Greemplum
ToroDB @NoSQLonSQL
●
GreenPlum was open sourced 6 days
ago
●
ToroDB already runs on GP!
●
Goal: ToroDB v0.4 replicates from a
MongoDB master onto Toro-Greenplum
and run the reporting using distributed
SQL
ToroDB on GP: SQL DW for MongoDB
ToroDB @NoSQLonSQL
SELECT count(
distinct(
"reviewerID"
)
)
FROM reviews;
Queries: which one is easier?
db.reviews.aggregate([
{ $group: { _id:
"reviewerID"}
},
{ $group: {_id: 1,
count: { $sum: 1}}
}
])
ToroDB @NoSQLonSQL
SELECT
"reviewerName",
count(*) as reviews
FROM reviews
GROUP BY
"reviewerName"
ORDER BY reviews
DESC LIMIT 10;
Queries: which one is easier?
db.reviews.aggregate(
[ { $group : { _id :
'$reviewerName',
r : { $sum : 1 } } },
{ $sort : { r : -1 } },
{ $limit : 10 } ],
{allowDiskUse: true}
)
ToroDB @NoSQLonSQL
●
Amazon reviews dataset
Image-based recommendations on styles and substitutes
J. McAuley, C. Targett, J. Shi, A. van den Hengel
SIGIR, 2015
●
AWS c4.xlarge (4vCPU, 8GB RAM)
4KIOPS SSD EBS
●
4x shards, 3x config; 4x segments GP
●
83M records, 65GB plain json
Benchmark
ToroDB @NoSQLonSQL
Disk usage
Mongo 3.0, WT, Snappy
GP columnar, zlib level 9
table size index size total size
0
10000000000
20000000000
30000000000
40000000000
50000000000
60000000000
70000000000
80000000000
Storage requirements
MongoDB vs ToroDB on Greenplum
Mongo
ToroDB on GP
bytes
ToroDB @NoSQLonSQL
Query times
3 different queries
Q3 on MongoDB: aggregate fails
27,95 74,87 0
0
200
400
600
800
1000
1200
969
1007
0
35 13 31
Query duration (s)
MongoDB vs ToroDB on Greenplum
MongoDB
ToroDB on GP
speedup
seconds
ToroDB: scaling PostgreSQL like MongoDB / Álvaro Hernández Tortosa (8Kdata)

More Related Content

PDF
Linux Kernel Extension for Databases / Александр Крижановский (Tempesta Techn...
PDF
Being closer to Cassandra by Oleg Anastasyev. Talk at Cassandra Summit EU 2013
ODP
Introduction to Redis
PDF
WiredTiger In-Memory vs WiredTiger B-Tree
PDF
Add a bit of ACID to Cassandra. Cassandra Summit EU 2014
PDF
Introduction to Redis
PDF
Мастер-класс "Логическая репликация и Avito" / Константин Евтеев, Михаил Тюр...
PPTX
Threads and Node.js
Linux Kernel Extension for Databases / Александр Крижановский (Tempesta Techn...
Being closer to Cassandra by Oleg Anastasyev. Talk at Cassandra Summit EU 2013
Introduction to Redis
WiredTiger In-Memory vs WiredTiger B-Tree
Add a bit of ACID to Cassandra. Cassandra Summit EU 2014
Introduction to Redis
Мастер-класс "Логическая репликация и Avito" / Константин Евтеев, Михаил Тюр...
Threads and Node.js

What's hot (20)

PDF
Distributed systems at ok.ru #rigadevday
PDF
pg / shardman: шардинг в PostgreSQL на основе postgres / fdw, pg / pathman и ...
PDF
Open Source SQL databases enters millions queries per second era
PDF
Новые возможности полнотекстового поиска в PostgreSQL / Олег Бартунов (Postgr...
PDF
Kyotoproducts
PDF
NoSQL 동향
PDF
Redis modules 101
PDF
openTSDB - Metrics for a distributed world
PDF
[Pgday.Seoul 2017] 3. PostgreSQL WAL Buffers, Clog Buffers Deep Dive - 이근오
PDF
Indexierung mit MySQL
PDF
Elastic 101 tutorial - Percona Europe 2018
PDF
Базы данных. HDFS
PDF
How to upgrade to MongoDB 4.0 - Percona Europe 2018
PDF
OpenTSDB 2.0
PDF
MySQL async message subscription platform
PDF
OpenTSDB for monitoring @ Criteo
PDF
PHP at Density and Scale (Lone Star PHP 2014)
PDF
Caching in (DevoxxUK 2013)
PDF
Managing data and operation distribution in MongoDB
PDF
durability, durability, durability
Distributed systems at ok.ru #rigadevday
pg / shardman: шардинг в PostgreSQL на основе postgres / fdw, pg / pathman и ...
Open Source SQL databases enters millions queries per second era
Новые возможности полнотекстового поиска в PostgreSQL / Олег Бартунов (Postgr...
Kyotoproducts
NoSQL 동향
Redis modules 101
openTSDB - Metrics for a distributed world
[Pgday.Seoul 2017] 3. PostgreSQL WAL Buffers, Clog Buffers Deep Dive - 이근오
Indexierung mit MySQL
Elastic 101 tutorial - Percona Europe 2018
Базы данных. HDFS
How to upgrade to MongoDB 4.0 - Percona Europe 2018
OpenTSDB 2.0
MySQL async message subscription platform
OpenTSDB for monitoring @ Criteo
PHP at Density and Scale (Lone Star PHP 2014)
Caching in (DevoxxUK 2013)
Managing data and operation distribution in MongoDB
durability, durability, durability
Ad

Similar to ToroDB: scaling PostgreSQL like MongoDB / Álvaro Hernández Tortosa (8Kdata) (20)

PDF
ToroDB: Scaling PostgreSQL like MongoDB by Álvaro Hernández at Big Data Spain...
PDF
Toro DB- Open-source, MongoDB-compatible database, built on top of PostgreSQL
PDF
Logstage - zero-cost-tructured-logging
PDF
Log stage zero-cost structured logging
PDF
ROS+GAZEBO
PDF
Experiences building a distributed shared log on RADOS - Noah Watkins
PDF
Introduction to Docker (as presented at December 2013 Global Hackathon)
PDF
PGConf APAC 2018 - High performance json postgre-sql vs. mongodb
PPTX
SAP Migration Overview
PPTX
MongoDB 3.2 - a giant leap. What’s new?
PDF
High performance json- postgre sql vs. mongodb
PDF
Quick overview on mongo db
ODP
brief introduction of drbd in SLE12SP2
PDF
Seastore: Next Generation Backing Store for Ceph
PDF
Seastore: Next Generation Backing Store for Ceph
PDF
Neo4j after 1 year in production
PDF
Go debugging and troubleshooting tips - from real life lessons at SignalFx
PDF
Let's Containerize New York with Docker!
PDF
Rails israel 2013
PPTX
SEMLA_logging_infra
ToroDB: Scaling PostgreSQL like MongoDB by Álvaro Hernández at Big Data Spain...
Toro DB- Open-source, MongoDB-compatible database, built on top of PostgreSQL
Logstage - zero-cost-tructured-logging
Log stage zero-cost structured logging
ROS+GAZEBO
Experiences building a distributed shared log on RADOS - Noah Watkins
Introduction to Docker (as presented at December 2013 Global Hackathon)
PGConf APAC 2018 - High performance json postgre-sql vs. mongodb
SAP Migration Overview
MongoDB 3.2 - a giant leap. What’s new?
High performance json- postgre sql vs. mongodb
Quick overview on mongo db
brief introduction of drbd in SLE12SP2
Seastore: Next Generation Backing Store for Ceph
Seastore: Next Generation Backing Store for Ceph
Neo4j after 1 year in production
Go debugging and troubleshooting tips - from real life lessons at SignalFx
Let's Containerize New York with Docker!
Rails israel 2013
SEMLA_logging_infra
Ad

More from Ontico (20)

PDF
One-cloud — система управления дата-центром в Одноклассниках / Олег Анастасье...
PDF
Масштабируя DNS / Артем Гавриченков (Qrator Labs)
PPTX
Создание BigData-платформы для ФГУП Почта России / Андрей Бащенко (Luxoft)
PDF
Готовим тестовое окружение, или сколько тестовых инстансов вам нужно / Алекса...
PDF
Новые технологии репликации данных в PostgreSQL / Александр Алексеев (Postgre...
PDF
PostgreSQL Configuration for Humans / Alvaro Hernandez (OnGres)
PDF
Inexpensive Datamasking for MySQL with ProxySQL — Data Anonymization for Deve...
PDF
Опыт разработки модуля межсетевого экранирования для MySQL / Олег Брославский...
PPTX
ProxySQL Use Case Scenarios / Alkin Tezuysal (Percona)
PPTX
MySQL Replication — Advanced Features / Петр Зайцев (Percona)
PDF
Внутренний open-source. Как разрабатывать мобильное приложение большим количе...
PPTX
Подробно о том, как Causal Consistency реализовано в MongoDB / Михаил Тюленев...
PPTX
Балансировка на скорости проводов. Без ASIC, без ограничений. Решения NFWare ...
PDF
Перехват трафика — мифы и реальность / Евгений Усков (Qrator Labs)
PPT
И тогда наверняка вдруг запляшут облака! / Алексей Сушков (ПЕТЕР-СЕРВИС)
PPTX
Как мы заставили Druid работать в Одноклассниках / Юрий Невиницин (OK.RU)
PPTX
Разгоняем ASP.NET Core / Илья Вербицкий (WebStoating s.r.o.)
PPTX
100500 способов кэширования в Oracle Database или как достичь максимальной ск...
PPTX
Apache Ignite Persistence: зачем Persistence для In-Memory, и как он работает...
PDF
Механизмы мониторинга баз данных: взгляд изнутри / Дмитрий Еманов (Firebird P...
One-cloud — система управления дата-центром в Одноклассниках / Олег Анастасье...
Масштабируя DNS / Артем Гавриченков (Qrator Labs)
Создание BigData-платформы для ФГУП Почта России / Андрей Бащенко (Luxoft)
Готовим тестовое окружение, или сколько тестовых инстансов вам нужно / Алекса...
Новые технологии репликации данных в PostgreSQL / Александр Алексеев (Postgre...
PostgreSQL Configuration for Humans / Alvaro Hernandez (OnGres)
Inexpensive Datamasking for MySQL with ProxySQL — Data Anonymization for Deve...
Опыт разработки модуля межсетевого экранирования для MySQL / Олег Брославский...
ProxySQL Use Case Scenarios / Alkin Tezuysal (Percona)
MySQL Replication — Advanced Features / Петр Зайцев (Percona)
Внутренний open-source. Как разрабатывать мобильное приложение большим количе...
Подробно о том, как Causal Consistency реализовано в MongoDB / Михаил Тюленев...
Балансировка на скорости проводов. Без ASIC, без ограничений. Решения NFWare ...
Перехват трафика — мифы и реальность / Евгений Усков (Qrator Labs)
И тогда наверняка вдруг запляшут облака! / Алексей Сушков (ПЕТЕР-СЕРВИС)
Как мы заставили Druid работать в Одноклассниках / Юрий Невиницин (OK.RU)
Разгоняем ASP.NET Core / Илья Вербицкий (WebStoating s.r.o.)
100500 способов кэширования в Oracle Database или как достичь максимальной ск...
Apache Ignite Persistence: зачем Persistence для In-Memory, и как он работает...
Механизмы мониторинга баз данных: взгляд изнутри / Дмитрий Еманов (Firebird P...

Recently uploaded (20)

PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PPTX
Construction Project Organization Group 2.pptx
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PPT
Mechanical Engineering MATERIALS Selection
PPT
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
PPTX
UNIT 4 Total Quality Management .pptx
PDF
composite construction of structures.pdf
PDF
Digital Logic Computer Design lecture notes
PPTX
Internet of Things (IOT) - A guide to understanding
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PPTX
Geodesy 1.pptx...............................................
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PPTX
Lecture Notes Electrical Wiring System Components
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
UNIT-1 - COAL BASED THERMAL POWER PLANTS
Construction Project Organization Group 2.pptx
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
Operating System & Kernel Study Guide-1 - converted.pdf
Mechanical Engineering MATERIALS Selection
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
UNIT 4 Total Quality Management .pptx
composite construction of structures.pdf
Digital Logic Computer Design lecture notes
Internet of Things (IOT) - A guide to understanding
Model Code of Practice - Construction Work - 21102022 .pdf
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
Geodesy 1.pptx...............................................
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
Lecture Notes Electrical Wiring System Components
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx

ToroDB: scaling PostgreSQL like MongoDB / Álvaro Hernández Tortosa (8Kdata)

  • 2. ToroDB @NoSQLonSQL About *8Kdata* ● Research & Development in databases ● Consulting, Training and Support in PostgreSQL ● Founders of PostgreSQL España, 5th largest PUG in the world (>500 members as of today) ● About myself: CTO at 8Kdata: @ahachete http://linkd.in/1jhvzQ3 www.8kdata.com
  • 4. ToroDB @NoSQLonSQL ToroDB in one slide ● Document-oriented, JSON, NoSQL db ● Open source (AGPL) ● MongoDB compatibility (wire protocol level) ● Uses PostgreSQL as a storage backend
  • 5. ToroDB @NoSQLonSQL ToroDB storage ● Data is stored in tables. No blobs ● JSON documents are split by hierarchy levels into “subdocuments”, which contain no nested structures. Each subdocument level is stored separately ● Subdocuments are classified by “type”. Each “type” maps to a different table
  • 6. ToroDB @NoSQLonSQL ToroDB storage (II) ● A “structure” table keeps the subdocument “schema” ● Keys in JSON are mapped to attributes, which retain the original name ● Tables are created dinamically and transparently to match the exact types of the documents
  • 7. ToroDB @NoSQLonSQL ToroDB storage internals { "name": "ToroDB", "data": { "a": 42, "b": "hello world!" }, "nested": { "j": 42, "deeper": { "a": 21, "b": "hello" } } }
  • 8. ToroDB @NoSQLonSQL ToroDB storage internals The document is split into the following subdocuments: { "name": "ToroDB", "data": {}, "nested": {} } { "a": 42, "b": "hello world!"} { "j": 42, "deeper": {}} { "a": 21, "b": "hello"}
  • 9. ToroDB @NoSQLonSQL ToroDB storage internals select * from demo.t_3 ┌─────┬───────┬────────────────────────────┬────────┐ │ did │ index │ _id │ name │ ├─────┼───────┼────────────────────────────┼────────┤ │ 0 │ ¤ │ x5451a07de7032d23a908576d │ ToroDB │ └─────┴───────┴────────────────────────────┴────────┘ select * from demo.t_1 ┌─────┬───────┬────┬──────────────┐ │ did │ index │ a │ b │ ├─────┼───────┼────┼──────────────┤ │ 0 │ ¤ │ 42 │ hello world! │ │ 0 │ 1 │ 21 │ hello │ └─────┴───────┴────┴──────────────┘ select * from demo.t_2 ┌─────┬───────┬────┐ │ did │ index │ j │ ├─────┼───────┼────┤ │ 0 │ ¤ │ 42 │ └─────┴───────┴────┘
  • 10. ToroDB @NoSQLonSQL ToroDB storage internals select * from demo.structures ┌─────┬────────────────────────────────────────────────────────────────────────────┐ │ sid │ _structure │ ├─────┼────────────────────────────────────────────────────────────────────────────┤ │ 0 │ {"t": 3, "data": {"t": 1}, "nested": {"t": 2, "deeper": {"i": 1, "t": 1}}} │ └─────┴────────────────────────────────────────────────────────────────────────────┘ select * from demo.root; ┌─────┬─────┐ │ did │ sid │ ├─────┼─────┤ │ 0 │ 0 │ └─────┴─────┘
  • 11. ToroDB @NoSQLonSQL ToroDB storage and I/O savings 29% - 68% storage required, compared to Mongo 2.6
  • 12. ToroDB @NoSQLonSQL ToroDB: query “by structure” ● ToroDB is effectively partitioning by type ● Structures (schemas, partitioning types) are cached in ToroDB memory ● Queries only scan a subset of the data ● Negative queries are served directly from memory
  • 14. ToroDB @NoSQLonSQL Big Data: NoSQL vs SQL vs http://www.networkworld.com/article/2226514/tech-debates/what-s-better-for-your-big-data-application--sql-or-nosql-.html
  • 16. ToroDB @NoSQLonSQL Ways to scale ● Vertical scalability ➔ Concurrency scalability ➔ Hardware scalability ➔ Query scalability ● Read scalability (replication) ● Write scalability (horizontal, sharding)
  • 17. ToroDB @NoSQLonSQL Vertical scalability Concurrency scalability ● SQL is usually better (e.g. PostgreSQL): ➔ Finer locking ➔ MVCC ➔ better caching ● NoSQL often needs sharding within the same host to scale
  • 18. ToroDB @NoSQLonSQL Vertical scalability Hardware scalability ● Scaling with the number of cores? ● Process/threading model? Query scalability ● Use of indexes? Use of more than one? ● Table/collection partitioning? ● ToroDB “by-type” partitioning
  • 19. ToroDB @NoSQLonSQL Read scalability: replication ● Replicate data to slave nodes, available read-only: scale-out reads ● Both NoSQL and SQL support it ● Binary replication usually faster (e.g. PostgreSQL's Streaming Replication) ● Not free from undesirable phenomena
  • 21. ToroDB @NoSQLonSQL MongoDB write acknowledge https://aphyr.com/posts/322-call-me-maybe-mongodb-stale-reads
  • 22. ToroDB @NoSQLonSQL MongoDB's dirty and stale reads Dirty reads A primary in minority accepts a write that other clients see, but it later steps down, write is rolled back (fixed in 3.2?) Stale reads A primary in minority serves a value that ought to be current, but a newer value was written to the other primary in minority
  • 23. ToroDB @NoSQLonSQL Write scalability (sharding) ● NoSQL better prepared than SQL ● But many compromises in data modeling (schema design): no FKs ● There are also solutions for SQL: ➔ Shared-disk, limited scalability (RAC) ➔ Sharding (like pg_shard) ➔ PostgreSQL's FDWs
  • 24. ToroDB @NoSQLonSQL Read scalability (replication) in MongoDB and ToroDB
  • 25. ToroDB @NoSQLonSQL Replication protocol choice ● ToroDB is based on PostgreSQL ● PostgreSQL has either binary streaming replication (async or sync) or logical replication ● MongoDB has logical replication ● ToroDB uses MongoDB's protocol
  • 26. ToroDB @NoSQLonSQL MongoDB's replication protocol ● Every change is recorded in JSON documents, idempotent format (collection: local.oplog.rs) ● Slaves pull these documents from master (or other slaves) asynchronously ● Changes are applied and feedback is sent upstream
  • 27. ToroDB @NoSQLonSQL MongoDB replication implementation https://github.com/stripe/mosql
  • 28. ToroDB @NoSQLonSQL Announcing ToroDB v0.4 (snap) Supporting MongoDB replication
  • 29. ToroDB @NoSQLonSQL ToroDB v0.4 ● ToroDB works as a secondary slave of a MongoDB master (or slave) ● Implements the full replication protocol (not an oplog tailable query) ● Replicates from Mongo to a PostgreSQL ● Open source github.com/torodb/torodb (repl branch, version 0.4-SNAPSHOT)
  • 30. ToroDB @NoSQLonSQL Advantages of ToroDB w/ replication ● Native SQL ● Query “by type” ● Better SQL scaling ● Less concurrency contention ● Better hardware utilization ● No need for ETL from Mongo to PG!
  • 31. ToroDB @NoSQLonSQL ● NoSQL is trying to get back to SQL ● ToroDB is SQL native! ● Insert with Mongo, query with SQL! ● Powerful PostgreSQL SQL: window functions, recursive queries, hypothetical aggregates, lateral joins, CTEs, etc ToroDB: native SQL
  • 33. ToroDB @NoSQLonSQL db.bds15.insert({ id:5, person: { name: "Alvaro", surname: "Hernandez", contact: { email: "aht@torodb.com", verified: true } } }) db.bds15.insert({ id:6, person: { name: "Name", surname: "Surname", age: 31, contact: { email: "name.surname@gmail.com" } } }) Introducing ToroDB VIEWs
  • 34. ToroDB @NoSQLonSQL torodb$ select * from bds15.person ; ┌─────┬───────────┬────────┬─────┐ │ did │ surname │ name │ age │ ├─────┼───────────┼────────┼─────┤ │ 0 │ Hernandez │ Alvaro │ ¤ │ │ 1 │ Surname │ Name │ 31 │ └─────┴───────────┴────────┴─────┘ (2 rows) torodb$ select * from bds15."person.contact"; ┌─────┬──────────┬────────────────────────┐ │ did │ verified │ email │ ├─────┼──────────┼────────────────────────┤ │ 0 │ t │ aht@torodb.com │ │ 1 │ ¤ │ name.surname@gmail.com │ └─────┴──────────┴────────────────────────┘ (2 rows) Introducing ToroDB VIEWs
  • 35. ToroDB @NoSQLonSQL VIEWs, ToroDB from any SQL tool
  • 36. ToroDB @NoSQLonSQL Enabling real DW on MongoDB: ToroDB + Greemplum
  • 37. ToroDB @NoSQLonSQL ● GreenPlum was open sourced 6 days ago ● ToroDB already runs on GP! ● Goal: ToroDB v0.4 replicates from a MongoDB master onto Toro-Greenplum and run the reporting using distributed SQL ToroDB on GP: SQL DW for MongoDB
  • 38. ToroDB @NoSQLonSQL SELECT count( distinct( "reviewerID" ) ) FROM reviews; Queries: which one is easier? db.reviews.aggregate([ { $group: { _id: "reviewerID"} }, { $group: {_id: 1, count: { $sum: 1}} } ])
  • 39. ToroDB @NoSQLonSQL SELECT "reviewerName", count(*) as reviews FROM reviews GROUP BY "reviewerName" ORDER BY reviews DESC LIMIT 10; Queries: which one is easier? db.reviews.aggregate( [ { $group : { _id : '$reviewerName', r : { $sum : 1 } } }, { $sort : { r : -1 } }, { $limit : 10 } ], {allowDiskUse: true} )
  • 40. ToroDB @NoSQLonSQL ● Amazon reviews dataset Image-based recommendations on styles and substitutes J. McAuley, C. Targett, J. Shi, A. van den Hengel SIGIR, 2015 ● AWS c4.xlarge (4vCPU, 8GB RAM) 4KIOPS SSD EBS ● 4x shards, 3x config; 4x segments GP ● 83M records, 65GB plain json Benchmark
  • 41. ToroDB @NoSQLonSQL Disk usage Mongo 3.0, WT, Snappy GP columnar, zlib level 9 table size index size total size 0 10000000000 20000000000 30000000000 40000000000 50000000000 60000000000 70000000000 80000000000 Storage requirements MongoDB vs ToroDB on Greenplum Mongo ToroDB on GP bytes
  • 42. ToroDB @NoSQLonSQL Query times 3 different queries Q3 on MongoDB: aggregate fails 27,95 74,87 0 0 200 400 600 800 1000 1200 969 1007 0 35 13 31 Query duration (s) MongoDB vs ToroDB on Greenplum MongoDB ToroDB on GP speedup seconds