denodrivers / denodrivers/mongo

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

Open
#304 6 comments 0 reactions 0 assignees View on GitHub
enhancement good first issue
Dominant language
TypeScript
Stars
511
Forks
89
PR merge metrics
No merged PRs in 30d

Description

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:
```typescript
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('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:

```javascript
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());
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.