PERFORMANCE BENCHMARK
POSTGRESQL / MONGODB
25/46
// OLTP BENCHMARK
Benchmark description
The goal of this benchmark is to compare both databases under an OLTP (Online
Transaction Processing) scenario. In OLTP, a high number of operations, though small
in nature (typically single-row queries supported by an index, or single-row change
operations) are typically performed by a potentially large number of concurrent users. It
is, arguably, the most sought-after use case for MongoDB and one of the most commonly
used ones for PostgreSQL too.
To perform this benchmark the well-known sysbench tool was used. Sysbench is a
scriptable multi-threaded benchmark tool based on LuaJIT, extensible via LUA scripts.
It was originally developed to perform system benchmarks, and included support for
MySQL initially. It now has native PostgreSQL, and there is a sysbench-mongodb-lua
script that wraps and makes it work under MongoDB. It could be argued that the quality
of the Lua driver for both systems may differ. However, the benchmark runs were reliable
and consistent, and hence this benchmark, one of the few that are relevant in terms of
the data model and that support both databases
7
, was used.
Benchmarks conducted with this tool do not exploit transaction capabilities in MongoDB.
They also do not perform complex queries that would arguably work better on relational
schemas. Sysbench creates a schema with an user-dened number of tables/collections
(created with the sbtest* prex). It also creates the correspondent indexes on their ID
columns. The document or row structure has an id, k (integer), c (slightly bigger text),
pad (text). Note that this test do not use transactions in MongoDB (and consequently run
effectively) under READ UNCOMMITTED isolation, whereas PostgreSQL runs under its
default isolation level, READ COMMITTED.
Several different tests have been performed, comprising several different dimensions
to analyze:
• Dataset size (small dataset, 2-4GB, tting in memory, called “FIT”; and larger dataset,
around 2TB, obviously not tting in memory, called “XL”).
7 Future work may involve writing one OLTP benchmark from scratch that would support both
databases. It could be based on a real use-case (like the Social Data Reference Architecture, a
MongoDB application used for performance regression testing), but exploiting the real capabi-
lities of each database, as if the program was designed specically for each of the databases. It
would be a fair benchmark in the sense that the same operations and data are used, but possi-
bly internal representation and data modeling changes, being adapted to the best patterns and
capabilities of each database.