Last active
February 2, 2021 00:26
-
-
Save karan9/c5fe36c112a2184ca8eef9f68ce7b9f1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const MongoClient = require("mongodb").MongoClient; | |
const util = require('util') | |
const MONGOURI = "MONGOURL"; | |
const DB = "lever-hire-nurture"; | |
const COLL = "profiles"; | |
const client = new MongoClient(MONGOURI, { useNewUrlParser: true, useUnifiedTopology: true }); | |
client.connect(err => { | |
if (err) { | |
console.error(err); | |
return; | |
} | |
/* Client Collection */ | |
const coll = client.db(DB).collection(COLL); | |
async function main() { | |
const pr = []; | |
for (let i =0; i<5; i++) { | |
pr.push(coll.find({}).explain("executionStats")); | |
} | |
const res = await Promise.all(pr); | |
console.log("Output :"); | |
console.log(util.inspect(res, false, null, true)) | |
} | |
main().catch(console.error) | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const cluster = require('cluster'); | |
const numCPUs = require('os').cpus().length - 2; | |
const MongoClient = require("mongodb").MongoClient; | |
const { LoremIpsum } = require("lorem-ipsum"); | |
const express = require("express"); | |
const NUM_THREADS = numCPUs; | |
const MONGOURI = "MONGOURL"; | |
const DB = "test_db"; | |
const COLL = "test_coll"; | |
const batchSize = 2000; | |
const docLength = 8; | |
const reqsize = 100000 | |
if (cluster.isMaster) { | |
console.log(`Master ${process.pid} is running`); | |
// Fork workers. | |
for (let i = 0; i < NUM_THREADS; i++) { | |
cluster.fork(); | |
} | |
cluster.on('exit', (worker, code, signal) => { | |
console.log(`worker ${worker.process.pid} died`); | |
}); | |
} else { | |
const app = express(); | |
const client = new MongoClient(MONGOURI, { useNewUrlParser: true, useUnifiedTopology: true }); | |
client.connect(err => { | |
if (err) { | |
console.error(err); | |
return; | |
} | |
/* Client Collection */ | |
const coll = client.db(DB).collection(COLL); | |
/* Lorem Ipsum Generator */ | |
/* USAGE - lorem.generateWords */ | |
const lorem = new LoremIpsum({ | |
sentencesPerParagraph: { | |
max: 8, | |
min: 4 | |
}, | |
wordsPerSentence: { | |
max: 16, | |
min: 4 | |
} | |
}); | |
/* Generate Sample Document */ | |
function generateSampleDocument(batchSize, docLength) { | |
const types = ["string", "date"]; | |
const wBatch = []; | |
const doc = { | |
field1: lorem.generateWords(), | |
field2: lorem.generateWords(), | |
field3: lorem.generateWords(), | |
field4: lorem.generateWords(), | |
cdt: new Date(), | |
udt: new Date() | |
} | |
return doc; | |
} | |
async function main() { | |
const promises = []; | |
for (let index = 0; index < reqsize; index++) { | |
promises.push(coll.insertOne(generateSampleDocument())); | |
} | |
const intrval = setInterval(() => { | |
console.log("Inserting ", promises.length, " Documents") | |
}, 1000); | |
const response = await Promise.all(promises); | |
clearInterval(intrval); | |
} | |
main().catch(console.error) | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "poc-tool-node", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"keywords": [], | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"express": "^4.17.1", | |
"lorem-ipsum": "^2.0.3", | |
"mongodb": "^3.6.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment