Skip to content

ozsynergy/db-benchmark

Repository files navigation

Database Benchmark Project

Goals

The goal of this project is to benchmark five database engines against each other:

  • AlloyDB
  • Elasticsearch
  • MongoDB
  • MySQL
  • PostgreSQL

Each database contains the same schema and dataset, allowing for direct performance comparisons.

The benchmark performs six different query types:

  • Keyword text search
    • find word in string
    • find word at start of string
  • Lookup by identifier (e.g., email address)
  • Lookup by multiple factors (department and status)
  • Aggregation (top 5 courses)
  • Update enrollment (update enrolled_at timestamp)
  • Delete enrollment

Dataset

The databases contain the following tables/collections:

  • Users: id, email, name, created_at
  • Courses: id, title, description, department, instructor_id, created_at
  • Enrollments: id, user_id, course_id, enrolled_at

Sample data generated: 20000 users, 45000 courses, 450000 enrollments.

Install

cd data wget https://huggingface.co/spaces/Kamand/Movie_Recommendation/resolve/main/movies_metadata.csv

Install dependencies (required for the first time)

## In the parent folder
npm install

Usage

Starting a Database Server

Select one database server to benchmark:

npm run db:alloydb  # Starts AlloyDB
npm run db:mongo   # Starts MongoDB
npm run db:mysql   # Starts MySQL
npm run db:postgresql  # Starts PostgreSQL
npm run db:elasticsearch  # Starts Elasticsearch

Seeding the Databases

After starting a database server, seed it with sample data by running the corresponding script. The scripts will wait for the database connection to be established before inserting data.

node alloydb/generate_sample_data.js
node mysql/generate_sample_data.js
node postgresql/generate_sample_data.js
node mongo/generate_sample_data.js
node elasticsearch/generate_sample_data.js

Note: The PostgreSQL and AlloyDB scripts check for existing data and only inserts if the tables are empty.

Running Benchmarks

Execute the benchmark script:

node benchmark.js [--debug] <server type> [request count]
  • --debug: run in debug mode (single request per query with detailed output)
  • <server type>: alloydb, mongo, mysql, postgresql, elasticsearch
  • <request count>: number of requests per test (optional, default 100, ignored in debug mode)

If you would like to see the MongoDB query plan and print it to the screen along with test result, you can add --explain option. Example as below

node benchmark.js mongo --explain 

Alternatively, use the convenience scripts that start the database, seed data, run benchmarks, and stop the database:

npm run benchmark:alloydb
npm run benchmark:mongo
npm run benchmark:mysql
npm run benchmark:postgresql
npm run benchmark:elasticsearch

Cleanup

Stop all database containers:

npm run db:stop

It is recommended to to run only 1 database at a time to prevent biasing the results by giving the databases unequal resources.

Other benchmarking articles

About

Database benchmarking tool

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •