123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- 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"
- }
- }
- ]
- }
- ]
- });
|