question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Performance] performance difference between deno_mongo and node.js driver

See original GitHub issue

I’m facing a performance issue between deno_mongo driver and official mongodb driver for Node.js. Here are the versions information of my test:

  • MongoDB server: 4.2.6, sharded database and collection. all the mongos and mongodb processes are located in the same host.
  • deno_mongo driver: 0.28.0
  • mongodb driver for Node.js: 4.2.0
  • deno: 1.16.3
  • Node.js: 12.19.0
  • OS: Ubuntu Desktop 20.04.3

My laptop connects to mongodb server via wired connection and I send a very simple query to get all the 16 documents from a small collection. My connection string is very simple: mongodb://172.16.1.95:27017

Here are the time used:

With deno_mongo driver:

deno: 16 documents returned from mongodb used: 103 ms
deno: 16 documents returned from mongodb used: 99 ms
deno: 16 documents returned from mongodb used: 94 ms
deno: 16 documents returned from mongodb used: 95 ms
deno: 16 documents returned from mongodb used: 96 ms
deno: 16 documents returned from mongodb used: 98 ms
deno: 16 documents returned from mongodb used: 94 ms
deno: 16 documents returned from mongodb used: 96 ms
deno: 16 documents returned from mongodb used: 95 ms
deno: 16 documents returned from mongodb used: 96 ms

With mongodb official driver for Node.js:

node.js: 16 documents returned from mongodb used: 11 ms
node.js: 16 documents returned from mongodb used: 3 ms
node.js: 16 documents returned from mongodb used: 2 ms
node.js: 16 documents returned from mongodb used: 3 ms
node.js: 16 documents returned from mongodb used: 4 ms
node.js: 16 documents returned from mongodb used: 3 ms
node.js: 16 documents returned from mongodb used: 6 ms
node.js: 16 documents returned from mongodb used: 4 ms
node.js: 16 documents returned from mongodb used: 3 ms
node.js: 16 documents returned from mongodb used: 4 ms

I’d like to know why is there such a significant performance difference between deno_mongo driver and official mongodb driver for Node.js. Or I did something wrong?

Here are the source code:

Deno:

import { Document, MongoClient } from "mongo/mod.ts";

const client = new MongoClient();

console.log('connecting to mongodb...');
await client.connect('mongodb://172.16.1.95:27017/');
console.log('mongodb connected');

const db = client.database('mqp');
const col = db.collection<Document>('dataDicts');

for (let i = 0; i < 10; i++) {
    const _ms = Date.now();
    const docs = await col.find({}).toArray();
    console.log(`deno: ${docs.length} documents returned from mongodb used: ${ Date.now() - _ms } ms`);
}

client.close();

Node.js:

const { MongoClient } = require('mongodb');

const url = 'mongodb://172.16.1.95:27017/';
const client = new MongoClient(url);

// Database Name
const dbName = 'mqp';

async function main() {
  // Use connect method to connect to the server
  await client.connect();
  console.log('Connected successfully to server');
  const db = client.db(dbName);
  const collection = db.collection('dataDicts');

  for (let i = 0; i < 10; i++) {
    const _ms = Date.now();
    const docs = await collection.find({}).toArray();
    console.log(`node.js: ${docs.length} documents returned from mongodb used: ${ Date.now() - _ms } ms`);
  }

  return 'done.';
}

main()
  .then(console.log)
  .catch(console.error)
  .finally(() => client.close());

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
MierenManzcommented, Dec 2, 2021

Thanks I’ll look into it 😄

0reactions
jiawei397commented, Dec 5, 2021

@yuqiang-yuan Thank you yeah, there’s work to be done about performance but i try to keep everything in balance. some important features are still missing. so it would be nice if others could help about this issue

Thank you very much for your repair. Last Thursday, I also found the query difference between the Deno and nodejs versions of my project, which is much better than before.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Deno vs Node.js: Performance comparison for API Proxy
In this comparison, we'll find out how the Deno's new HTTP server stands in front of Node's HTTP server when acting as an...
Read more >
Deno vs Node.js: A Must-Have Comparison for 2022
So, to clear all the clouds of confusion, today we will be talking about Deno vs Node.js, Deno vs Node.js performance, and which...
Read more >
MongoDB Native Driver vs Mongoose: Performance ...
Mongoose brings several useful features in Node, but how does it perform compared to the MongoDB native driver? Let's benchmark both using ...
Read more >
Node mongodb native performance - Drivers & ODMs
I noticed that performance goes down badly. For example, I run a simple get query on the same database, same collection having 9...
Read more >
mongo@v0.31.1
MongoDB driver for Deno. ... deno_mongo. deno_mongo is a MongoDB database driver developed for Deno. supports Deno Deploy as well.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found