KEMBAR78
MongoDB vs. Postgres Benchmarks | PDF
MONGODB vs POSTGRESQL BENCHMARKS
MONGODB vs POSTGRESQL
BENCHMARKS
Álvaro Hernández
MONGODB vs POSTGRESQL BENCHMARKS
`whoami`
Álvaro Hernández <aht@ongres.com>
@ahachete
● Founder & CEO, OnGres
● 20+ years PostgreSQL user and DBA
● Mostly doing R&D to create new, innovative
software on Postgres
● Frequent speaker at PostgreSQL, database
conferences
● Principal Architect of ToroDB
● Founder and President of the NPO
Fundación PostgreSQL
MONGODB vs POSTGRESQL BENCHMARKS
Introduction
MONGODB vs POSTGRESQL BENCHMARKS
OnGres Ethics Policy
This work was sponsored by EnterpriseDB, and performed by OnGres.
It was conducted according to OnGres Ethics Policy, that observes that:
● All the work is conducted with the maximum degree of professionalism
and independence.
● No technology is favored over another.
● No results are edited or omitted.
● The sponsor of the work does not intervene in the strategy,
implementation or execution of the work.
● Results are verifiable by external, third parties.
MONGODB vs POSTGRESQL BENCHMARKS
Benchmarking is hard
● Bench-marketing is easy --but not trustable.
● Benchmarking is hard.
● Benchmarking databases is harder.
● Benchmarking databases that follow different design models, is
even harder.
● Are MongoDB and PostgreSQL comparable?
● The market demands this: informed decision, performance is key.
MONGODB vs POSTGRESQL BENCHMARKS
Pursuing benchmarking fairness
How to present a fair arena in which the technologies compete in an
apples-to-apples scenario?
● Transparency and reproducibility. Infrastructure-as-Code.
https://gitlab.com/ongresinc/benchplatform/
https://gitlab.com/ongresinc/txbenchmark/
http://benchplatform.ongres.com.s3.amazonaws.com/
● Multiple benchmarks
● Close-to-real workloads
● Production-grade setups
MONGODB vs POSTGRESQL BENCHMARKS
Types of benchmarks
Three main benchmark categories:
● Transactions benchmark
● OLTP
○ In-memory dataset (4GB)
○ Larger, on-disk dataset (2TB)
● OLAP
MONGODB vs POSTGRESQL BENCHMARKS
The contenders
MongoDB 4.0
● Community version used
● Journaling active
● Replication active
(single node)
● No further tuning required
PostgreSQL 11
● Self-managed instance
● Basic production tuning
● Tested w/ and w/o
PgBouncer
MONGODB vs POSTGRESQL BENCHMARKS
Architecture: client-server, running on AWS
Data volume: io1, with number of reserved IOPS depending on the test.
MONGODB vs POSTGRESQL BENCHMARKS
Benchmarks:
Transactions
MONGODB vs POSTGRESQL BENCHMARKS
Previous discussion: isolation levels
MONGODB vs POSTGRESQL BENCHMARKS
Benchmark description
● Custom-developed benchmark.
● Inspired by MongoDB post about MongoDB transactions.
● Simulates air reservation system: check flight schedule, plane
availability, purchase, audit log.
● Tx with query, insertions and upsert.
● Programmed in Java. Official JDBC and MongoDB drivers.
● Open source: https://gitlab.com/ongresinc/benchplatform
MONGODB vs POSTGRESQL BENCHMARKS
Transaction performance
MONGODB vs POSTGRESQL BENCHMARKS
Transaction performance
MONGODB vs POSTGRESQL BENCHMARKS
Transaction retries
MONGODB vs POSTGRESQL BENCHMARKS
PostgreSQL latency (@ SERIALIZABLE)
MONGODB vs POSTGRESQL BENCHMARKS
MongoDB latency
MONGODB vs POSTGRESQL BENCHMARKS
Benchmarks:
OLTP
MONGODB vs POSTGRESQL BENCHMARKS
Benchmark description
● Industry standard Sysbench was used.
● Supports PostgreSQL and MongoDB (via sysbench-mongodb-lua).
● Resembles real-world OLTP workload.
● Different dimensions benchmarked:
○ Dataset size: fit in memory (4GB), on-disk (2TB)
○ Read/write work split: 50/50, 95/5.
○ Filesystems: XFS or ZFS.
○ Different levels of concurrency.
MONGODB vs POSTGRESQL BENCHMARKS
Discussion about PostgreSQL Connection Pooling
● PostgreSQL best practice is to run always behind a connection pool.
● PostgreSQL proved to be highly sensitive to the number of connections,
with degraded performance when overwhelmed.
● A connection pool offers close-to-ideal performance for almost any
workload.
● MongoDB does not require connection pooling:
is included in drivers.
MONGODB vs POSTGRESQL BENCHMARKS
Performance: dataset in memory
MONGODB vs POSTGRESQL BENCHMARKS
PG connection pooling effect (dataset in memory)
MONGODB vs POSTGRESQL BENCHMARKS
Performance: dataset on disk
MONGODB vs POSTGRESQL BENCHMARKS
Benchmarks:
OLAP
MONGODB vs POSTGRESQL BENCHMARKS
Benchmark description
● JSON dataset (GitHub Archive). Native to MongoDB, jsonb in PG.
● 2015 dataset: 212M records (340GB on PG, 206GB on MongoDB).
● Timing of OLAP-style queries that resemble BI natural questions:
○ Repositories ordered by most opened issues.
○ Most frequent git event types, ordered.
○ Top 10 most active actors.
○ Repositories that have more than two comments and a specific
event type, ordered.
MONGODB vs POSTGRESQL BENCHMARKS
Query A in PostgreSQL and MongoDB
MONGODB vs POSTGRESQL BENCHMARKS
Results
MONGODB vs POSTGRESQL BENCHMARKS
QUESTIONS?
Álvaro Hernández
<aht@ongres.com>
@ahachete / www.ongres.com
Thank you

MongoDB vs. Postgres Benchmarks

  • 1.
    MONGODB vs POSTGRESQLBENCHMARKS MONGODB vs POSTGRESQL BENCHMARKS Álvaro Hernández
  • 2.
    MONGODB vs POSTGRESQLBENCHMARKS `whoami` Álvaro Hernández <aht@ongres.com> @ahachete ● Founder & CEO, OnGres ● 20+ years PostgreSQL user and DBA ● Mostly doing R&D to create new, innovative software on Postgres ● Frequent speaker at PostgreSQL, database conferences ● Principal Architect of ToroDB ● Founder and President of the NPO Fundación PostgreSQL
  • 3.
    MONGODB vs POSTGRESQLBENCHMARKS Introduction
  • 4.
    MONGODB vs POSTGRESQLBENCHMARKS OnGres Ethics Policy This work was sponsored by EnterpriseDB, and performed by OnGres. It was conducted according to OnGres Ethics Policy, that observes that: ● All the work is conducted with the maximum degree of professionalism and independence. ● No technology is favored over another. ● No results are edited or omitted. ● The sponsor of the work does not intervene in the strategy, implementation or execution of the work. ● Results are verifiable by external, third parties.
  • 5.
    MONGODB vs POSTGRESQLBENCHMARKS Benchmarking is hard ● Bench-marketing is easy --but not trustable. ● Benchmarking is hard. ● Benchmarking databases is harder. ● Benchmarking databases that follow different design models, is even harder. ● Are MongoDB and PostgreSQL comparable? ● The market demands this: informed decision, performance is key.
  • 6.
    MONGODB vs POSTGRESQLBENCHMARKS Pursuing benchmarking fairness How to present a fair arena in which the technologies compete in an apples-to-apples scenario? ● Transparency and reproducibility. Infrastructure-as-Code. https://gitlab.com/ongresinc/benchplatform/ https://gitlab.com/ongresinc/txbenchmark/ http://benchplatform.ongres.com.s3.amazonaws.com/ ● Multiple benchmarks ● Close-to-real workloads ● Production-grade setups
  • 7.
    MONGODB vs POSTGRESQLBENCHMARKS Types of benchmarks Three main benchmark categories: ● Transactions benchmark ● OLTP ○ In-memory dataset (4GB) ○ Larger, on-disk dataset (2TB) ● OLAP
  • 8.
    MONGODB vs POSTGRESQLBENCHMARKS The contenders MongoDB 4.0 ● Community version used ● Journaling active ● Replication active (single node) ● No further tuning required PostgreSQL 11 ● Self-managed instance ● Basic production tuning ● Tested w/ and w/o PgBouncer
  • 9.
    MONGODB vs POSTGRESQLBENCHMARKS Architecture: client-server, running on AWS Data volume: io1, with number of reserved IOPS depending on the test.
  • 10.
    MONGODB vs POSTGRESQLBENCHMARKS Benchmarks: Transactions
  • 11.
    MONGODB vs POSTGRESQLBENCHMARKS Previous discussion: isolation levels
  • 12.
    MONGODB vs POSTGRESQLBENCHMARKS Benchmark description ● Custom-developed benchmark. ● Inspired by MongoDB post about MongoDB transactions. ● Simulates air reservation system: check flight schedule, plane availability, purchase, audit log. ● Tx with query, insertions and upsert. ● Programmed in Java. Official JDBC and MongoDB drivers. ● Open source: https://gitlab.com/ongresinc/benchplatform
  • 13.
    MONGODB vs POSTGRESQLBENCHMARKS Transaction performance
  • 14.
    MONGODB vs POSTGRESQLBENCHMARKS Transaction performance
  • 15.
    MONGODB vs POSTGRESQLBENCHMARKS Transaction retries
  • 16.
    MONGODB vs POSTGRESQLBENCHMARKS PostgreSQL latency (@ SERIALIZABLE)
  • 17.
    MONGODB vs POSTGRESQLBENCHMARKS MongoDB latency
  • 18.
    MONGODB vs POSTGRESQLBENCHMARKS Benchmarks: OLTP
  • 19.
    MONGODB vs POSTGRESQLBENCHMARKS Benchmark description ● Industry standard Sysbench was used. ● Supports PostgreSQL and MongoDB (via sysbench-mongodb-lua). ● Resembles real-world OLTP workload. ● Different dimensions benchmarked: ○ Dataset size: fit in memory (4GB), on-disk (2TB) ○ Read/write work split: 50/50, 95/5. ○ Filesystems: XFS or ZFS. ○ Different levels of concurrency.
  • 20.
    MONGODB vs POSTGRESQLBENCHMARKS Discussion about PostgreSQL Connection Pooling ● PostgreSQL best practice is to run always behind a connection pool. ● PostgreSQL proved to be highly sensitive to the number of connections, with degraded performance when overwhelmed. ● A connection pool offers close-to-ideal performance for almost any workload. ● MongoDB does not require connection pooling: is included in drivers.
  • 21.
    MONGODB vs POSTGRESQLBENCHMARKS Performance: dataset in memory
  • 22.
    MONGODB vs POSTGRESQLBENCHMARKS PG connection pooling effect (dataset in memory)
  • 23.
    MONGODB vs POSTGRESQLBENCHMARKS Performance: dataset on disk
  • 24.
    MONGODB vs POSTGRESQLBENCHMARKS Benchmarks: OLAP
  • 25.
    MONGODB vs POSTGRESQLBENCHMARKS Benchmark description ● JSON dataset (GitHub Archive). Native to MongoDB, jsonb in PG. ● 2015 dataset: 212M records (340GB on PG, 206GB on MongoDB). ● Timing of OLAP-style queries that resemble BI natural questions: ○ Repositories ordered by most opened issues. ○ Most frequent git event types, ordered. ○ Top 10 most active actors. ○ Repositories that have more than two comments and a specific event type, ordered.
  • 26.
    MONGODB vs POSTGRESQLBENCHMARKS Query A in PostgreSQL and MongoDB
  • 27.
    MONGODB vs POSTGRESQLBENCHMARKS Results
  • 28.
    MONGODB vs POSTGRESQLBENCHMARKS QUESTIONS? Álvaro Hernández <aht@ongres.com> @ahachete / www.ongres.com Thank you