summaryrefslogtreecommitdiff
path: root/jstests/perf
diff options
context:
space:
mode:
authorJacob Evans <jacob.evans@mongodb.com>2019-11-05 19:45:39 +0000
committerevergreen <evergreen@mongodb.com>2019-11-05 19:45:39 +0000
commit9561ea73bc0004fc1835430f9789546484c1e7e7 (patch)
tree926cce8e3ec8fd37e82d24a450f9166001023aa5 /jstests/perf
parent853bdc4b34d9c3505e2af1f443ad7a99a619adea (diff)
downloadmongo-9561ea73bc0004fc1835430f9789546484c1e7e7.tar.gz
SERVER-43749 Modernize mapReduce tests in core
Diffstat (limited to 'jstests/perf')
-rw-r--r--jstests/perf/mr_bench.js84
-rw-r--r--jstests/perf/v8_mapreduce.js118
2 files changed, 0 insertions, 202 deletions
diff --git a/jstests/perf/mr_bench.js b/jstests/perf/mr_bench.js
deleted file mode 100644
index c141e112163..00000000000
--- a/jstests/perf/mr_bench.js
+++ /dev/null
@@ -1,84 +0,0 @@
-
-t = db.mr_bench;
-t.drop();
-
-function getRandomStr(L) {
- var s = '';
- var randomchar = function() {
- var n = Math.floor(Math.random() * 62);
- if (n < 10)
- return n; // 1-10
- if (n < 36)
- return String.fromCharCode(n + 55); // A-Z
- return String.fromCharCode(n + 61); // a-z
- };
- while (s.length < L)
- s += randomchar();
- return s;
-}
-
-t.ensureIndex({rand: 1}, {unique: true});
-
-largeStr = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
-while (largeStr.length < 512) {
- largeStr += largeStr;
-}
-largeStr = largeStr.substr(512);
-
-for (i = 0; i < 100000; ++i) {
- t.save({rand: getRandomStr(20), same: "the same string", str: largeStr});
-}
-
-emit = printjson;
-count = t.count();
-
-function d(x) {
- printjson(x);
-}
-
-m = function() {
- emit(this.rand, {id: this._id, str: this.str});
-};
-
-m2 = function() {
- emit(this.same, this.rand);
-};
-
-r = function(k, vals) {
- var tmp = {};
- vals.forEach(function(i) {
- if (typeof (i) == 'string') {
- tmp[i] = true;
- } else {
- for (var z in i)
- tmp[z] = true;
- }
- });
-
- return tmp;
-};
-
-// following time limits are passing fine on a laptop with a debug build
-// so should always pass in theory unless something is wrong: GC, too much reducing, etc
-
-// 1st MR just uses random unique keys, with no reduce involved
-// this should be straightforward for perf, but could lead to OOM if settings are bad
-assert.time(function() {
- res = db.runCommand({mapreduce: "mr_bench", map: m, reduce: r, out: "mr_bench_out"});
- d(res);
- assert.eq(count, res.counts.input, "A");
- x = db[res.result];
- assert.eq(count, x.find().count(), "B");
- return 1;
-}, "unique key mr", 15000);
-
-// 2nd MR emits the same key, and a unique value is added as key to same object
-// if object is kept in ram and being reduced, this can be really slow
-assert.time(function() {
- res = db.runCommand({mapreduce: "mr_bench", map: m2, reduce: r, out: "mr_bench_out"});
- d(res);
- assert.eq(count, res.counts.input, "A");
- x = db[res.result];
- assert.eq(1, x.find().count(), "B");
- return 1;
-}, "single key mr", 20000);
diff --git a/jstests/perf/v8_mapreduce.js b/jstests/perf/v8_mapreduce.js
deleted file mode 100644
index 46afcf37082..00000000000
--- a/jstests/perf/v8_mapreduce.js
+++ /dev/null
@@ -1,118 +0,0 @@
-// Testing parallelism of mapReduce in V8
-
-// Our server and client need to be running V8 and the host we are running on needs at least two
-// cores. Update this if you are testing more than three threads in parallel.
-if (/V8/.test(interpreterVersion()) && db.runCommand({buildinfo: 1}).javascriptEngine == "V8" &&
- db.hostInfo().system.numCores >= 2) {
- // function timeSingleThread
- // Description: Gathers data about how long it takes to run a given job
- // Args: job - job to run
- // tid - thread id passed as an argument to the job, default 0
- // Returns: { threadStart : <time job started> , threadEnd : <time job completed> }
- var timeSingleThread = function(job, tid) {
- var tid = tid || 0;
- var threadStart = new Date();
- job(tid);
- return {"threadStart": threadStart, "threadEnd": new Date()};
- };
-
- // function timeMultipleThreads
- // Description: Gathers data about how long it takes to run a given job in multiple threads.
- // Args: job - job to run in each thread
- // nthreads - number of threads to spawn
- // stagger - delay between each thread spawned in milliseconds
- // Returns: Array with one entry for each thread of the form:
- // [ { threadStart : <time elapsed before thread started work> ,
- // threadEnd : <time elapsed before thread completed work> } ,
- // ...
- // ]
- var timeMultipleThreads = function(job, nthreads, stagger) {
- var i = 0;
- var threads = [];
-
- for (i = 0; i < nthreads; ++i) {
- threads[i] = new Thread(timeSingleThread, job, i);
- }
-
- // Our "reference time" that all threads agree on
- var referenceTime = new Date();
-
- for (i = 0; i < nthreads; ++i) {
- if (stagger && i > 0) {
- sleep(stagger);
- }
- threads[i].start();
- }
-
- var threadTimes = [];
- for (i = 0; i < nthreads; ++i) {
- var returnData = threads[i].returnData();
- threadTimes[i] = {};
- threadTimes[i].threadStart = returnData.threadStart - referenceTime;
- threadTimes[i].threadEnd = returnData.threadEnd - referenceTime;
- }
-
- return threadTimes;
- };
-
- // Display and analysis helper functions
-
- var getLastCompletion = function(threadTimes) {
- var lastCompletion = 0;
- for (var i = 0; i < threadTimes.length; i++) {
- lastCompletion = Math.max(lastCompletion, threadTimes[i].threadEnd);
- }
- return lastCompletion;
- };
-
- // Functions we are performance testing
-
- db.v8_parallel_mr_src.drop();
-
- for (j = 0; j < 100; j++)
- for (i = 0; i < 512; i++) {
- db.v8_parallel_mr_src.save({j: j, i: i});
- }
-
- db.getLastError();
-
- var mrWorkFunction = function() {
- function verifyOutput(out) {
- // printjson(out);
- assert.eq(out.counts.input, 51200, "input count is wrong");
- assert.eq(out.counts.emit, 51200, "emit count is wrong");
- assert.gt(out.counts.reduce, 99, "reduce count is wrong");
- assert.eq(out.counts.output, 512, "output count is wrong");
- }
-
- function map() {
- if (this.j % 2 == 0) {
- emit(this.i, this.j * this.j);
- } else {
- emit(this.i, this.j + this.j);
- }
- }
-
- function reduce(key, values) {
- values_halved = values.map(function(value) {
- return value / 2;
- });
- values_halved_sum = Array.sum(values_halved);
- return values_halved_sum;
- }
-
- var out = db.v8_parallel_mr_src.mapReduce(map, reduce, {out: "v8_parallel_mr_out"});
- verifyOutput(out);
- };
-
- var oneMapReduce = getLastCompletion(timeMultipleThreads(mrWorkFunction, 1));
- var twoMapReduce = getLastCompletion(timeMultipleThreads(mrWorkFunction, 2));
- var threeMapReduce = getLastCompletion(timeMultipleThreads(mrWorkFunction, 3));
-
- printjson("One map reduce job: " + oneMapReduce);
- printjson("Two map reduce jobs: " + twoMapReduce);
- printjson("Three map reduce jobs: " + threeMapReduce);
-
- assert(oneMapReduce * 1.75 > twoMapReduce);
- assert(oneMapReduce * 2.5 > threeMapReduce);
-}