Save 37% off PRO during our Black Friday Sale! »

MongoDB vs PostgreSQL Performance

E084eb5b13255d30b3800d7afb251147?s=47 OnGres
June 26, 2019

MongoDB vs PostgreSQL Performance

Benchmarking is hard. Benchmarking databases, harder. Benchmarking databases that follow different approaches (relational vs document) is even harder.

But the market demands these kinds of benchmarks. Despite the different data models that MongoDB and PostgreSQL expose, many organizations face the challenge of picking either technology. And performance is arguably the main deciding factor.

Join this talk to discover the numbers! After $30K spent on public cloud and months of testing, there are many different scenarios to analyze. Benchmarks on three distinct categories have been performed: OLTP, OLAP and comparing MongoDB 4.0 transaction performance with PostgreSQL's.

E084eb5b13255d30b3800d7afb251147?s=128

OnGres

June 26, 2019
Tweet

Transcript

  1. MONGODB vs POSTGRESQL BENCHMARKS MONGODB vs POSTGRESQL BENCHMARKS Álvaro Hernández

  2. 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
  3. MONGODB vs POSTGRESQL BENCHMARKS Introduction

  4. 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.
  5. 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.
  6. 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
  7. MONGODB vs POSTGRESQL BENCHMARKS Types of benchmarks Three main benchmark

    categories: • Transactions benchmark • OLTP ◦ In-memory dataset (4GB) ◦ Larger, on-disk dataset (2TB) • OLAP
  8. 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
  9. MONGODB vs POSTGRESQL BENCHMARKS Architecture: client-server, running on AWS Data

    volume: io1, with number of reserved IOPS depending on the test.
  10. MONGODB vs POSTGRESQL BENCHMARKS Benchmarks: Transactions

  11. MONGODB vs POSTGRESQL BENCHMARKS Previous discussion: isolation levels

  12. 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
  13. MONGODB vs POSTGRESQL BENCHMARKS Transaction performance

  14. MONGODB vs POSTGRESQL BENCHMARKS Transaction performance

  15. MONGODB vs POSTGRESQL BENCHMARKS Transaction retries

  16. MONGODB vs POSTGRESQL BENCHMARKS PostgreSQL latency (@ SERIALIZABLE)

  17. MONGODB vs POSTGRESQL BENCHMARKS MongoDB latency

  18. MONGODB vs POSTGRESQL BENCHMARKS Benchmarks: OLTP

  19. 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.
  20. 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.
  21. MONGODB vs POSTGRESQL BENCHMARKS Performance: dataset in memory

  22. MONGODB vs POSTGRESQL BENCHMARKS PG connection pooling effect (dataset in

    memory)
  23. MONGODB vs POSTGRESQL BENCHMARKS Performance: dataset on disk

  24. MONGODB vs POSTGRESQL BENCHMARKS Benchmarks: OLAP

  25. 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.
  26. MONGODB vs POSTGRESQL BENCHMARKS Query A in PostgreSQL and MongoDB

  27. MONGODB vs POSTGRESQL BENCHMARKS Results

  28. MONGODB vs POSTGRESQL BENCHMARKS QUESTIONS? Álvaro Hernández <aht@ongres.com> @ahachete /

    www.ongres.com Thank you