From 21d72c4a80fe2937d0c4ddd20624b27adbcd989b Mon Sep 17 00:00:00 2001 From: lizi00164331 Date: Mon, 7 Aug 2017 11:39:39 +0800 Subject: Upload the ESR GUI seed code Issue-ID: AAI-68 Change-Id: Ia50ce0570c2fabecd77199d4e8454f56fe587c4e Signed-off-by: lizi00164331 --- .../appserver/node_modules/mongodb/insert_bench.js | 231 +++++++++++++++++++++ 1 file changed, 231 insertions(+) create mode 100644 common/src/main/webapp/usageguide/appserver/node_modules/mongodb/insert_bench.js (limited to 'common/src/main/webapp/usageguide/appserver/node_modules/mongodb/insert_bench.js') diff --git a/common/src/main/webapp/usageguide/appserver/node_modules/mongodb/insert_bench.js b/common/src/main/webapp/usageguide/appserver/node_modules/mongodb/insert_bench.js new file mode 100644 index 0000000..5c4d0b9 --- /dev/null +++ b/common/src/main/webapp/usageguide/appserver/node_modules/mongodb/insert_bench.js @@ -0,0 +1,231 @@ +var MongoClient = require('./').MongoClient, + assert = require('assert'); + +// var memwatch = require('memwatch-next'); +// memwatch.on('leak', function(info) { +// console.log("======== leak") +// }); +// +// memwatch.on('stats', function(stats) { +// console.log("======== stats") +// console.dir(stats) +// }); + +// // Take first snapshot +// var hd = new memwatch.HeapDiff(); + +MongoClient.connect('mongodb://localhost:27017/bench', function(err, db) { + var docs = []; + var total = 1000; + var count = total; + var measurements = []; + + // Insert a bunch of documents + for(var i = 0; i < 100; i++) { + docs.push(JSON.parse(data)); + } + + var col = db.collection('inserts'); + + function execute(col, callback) { + var start = new Date().getTime(); + + col.find({}).limit(100).toArray(function(e, docs) { + measurements.push(new Date().getTime() - start); + assert.equal(null, e); + callback(); + }); + } + + console.log("== insert documents") + col.insert(docs, function(e, r) { + docs = []; + assert.equal(null, e); + + console.log("== start bench") + for(var i = 0; i < total; i++) { + execute(col, function(e) { + count = count - 1; + + if(count == 0) { + // Calculate total execution time for operations + var totalTime = measurements.reduce(function(prev, curr) { + return prev + curr; + }, 0); + + console.log("==========================================="); + console.log("total time: " + totalTime) + + // var diff = hd.end(); + // console.log("==========================================="); + // console.log(JSON.stringify(diff, null, 2)) + + db.close(); + process.exit(0) + } + }); + } + }); +}); + +var data = JSON.stringify({ + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + } + ], + "collection_name": "test", + "database_name": "command-monitoring-tests", + "tests": [ + { + "description": "A successful mixed bulk write", + "operation": { + "name": "bulkWrite", + "arguments": { + "requests": [ + { + "insertOne": { + "document": { + "_id": 4, + "x": 44 + } + } + }, + { + "updateOne": { + "filter": { + "_id": 3 + }, + "update": { + "set": { + "x": 333 + } + } + } + } + ] + } + }, + "expectations": [ + { + "command_started_event": { + "command": { + "insert": "test", + "documents": [ + { + "_id": 4, + "x": 44 + } + ], + "ordered": true + }, + "command_name": "insert", + "database_name": "command-monitoring-tests" + } + }, + { + "command_succeeded_event": { + "reply": { + "ok": 1.0, + "n": 1 + }, + "command_name": "insert" + } + }, + { + "command_started_event": { + "command": { + "update": "test", + "updates": [ + { + "q": { + "_id": 3 + }, + "u": { + "set": { + "x": 333 + } + }, + "upsert": false, + "multi": false + } + ], + "ordered": true + }, + "command_name": "update", + "database_name": "command-monitoring-tests" + } + }, + { + "command_succeeded_event": { + "reply": { + "ok": 1.0, + "n": 1 + }, + "command_name": "update" + } + } + ] + }, + { + "description": "A successful unordered bulk write with an unacknowledged write concern", + "operation": { + "name": "bulkWrite", + "arguments": { + "requests": [ + { + "insertOne": { + "document": { + "_id": 4, + "x": 44 + } + } + } + ], + "ordered": false, + "writeConcern": { + "w": 0 + } + } + }, + "expectations": [ + { + "command_started_event": { + "command": { + "insert": "test", + "documents": [ + { + "_id": 4, + "x": 44 + } + ], + "ordered": false, + "writeConcern": { + "w": 0 + } + }, + "command_name": "insert", + "database_name": "command-monitoring-tests" + } + }, + { + "command_succeeded_event": { + "reply": { + "ok": 1.0 + }, + "command_name": "insert" + } + } + ] + } + ] +}); -- cgit 1.2.3-korg