Skip to content

This repository has a comparison between searching the database using and not using streams

Notifications You must be signed in to change notification settings

italoservio/mongoose_query_stream

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📥 MongoDB Queries

This repository has a comparison between searching the database using and not using streams

🎯 Results

With 100.000 registers

container script cpu mem delay (s)
mongo paginated ± 49% ± 37% 16.481s
node paginated ± 50% ± 16.8% 16.481s
mongo stream ± 5% ± 37% 3.497s
node stream ± 50% ± 15.5% 3.497s

Hardware: i5 11400F (6 cores, 12 threads) 16GBs of RAM

💡 How it works

Using existent data

I've added a mongo.zip file inside mongo folder in the root of the project. Just extract the content in mongo folder and run the scripts.

Running Without Docker Compose

First step is run your MongoDB locally.

Is necessary to change the domain to localhost in src/database/conn.mjs

docker run -d \
  --name mongodb \
  -v $PWD/mongo:/data/db \
  -e MONGO_INITDB_ROOT_USERNAME=root \
  -e MONGO_INITDB_ROOT_PASSWORD=root \
  -p 27017:27017 \
  mongo

If failed to connect to the database, add the user to the database which we will use in the mongo shell

use example_db

db.createUser(
  {
    user: "root",
    pwd: "root",
    roles: [
       {role: "readWrite", db: "example_db"}
    ]
  }
)

The second step is add test mass in your database

# Each execution adds 50.000 new users
npm run populate

The last step is run the queries and compare the execution time

# Paginated query
npm run paginated

# Stream query
npm run stream

Running With Docker Compose

Build the image

docker build -t node-example .

Run containers

docker compose up -d --build

Enter in "node-example" container

docker exec -it node-example bash

Go to application and run the execution commands

cd /app

# Paginated query
npm run paginated

# Stream query
npm run stream

About

This repository has a comparison between searching the database using and not using streams

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published