1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
// mongotop_stress.js; ensure that running mongotop, even when the server is
// under heavy load, works as expected
var testName = 'mongotop_stress';
load('jstests/top/util/mongotop_common.js');
(function() {
jsTest.log('Testing mongotop\'s performance under load');
var runTests = function(topology, passthrough) {
jsTest.log('Using ' + passthrough.name + ' passthrough');
var t = topology.init(passthrough);
var conn = t.connection();
db = conn.getDB('foo'); // eslint-disable-line no-native-reassign
// concurrently insert documents into thousands of collections
var stressShell = '\nprint(\'starting read/write stress test\'); \n' +
' if (\'' + passthrough.name + '\' === \'auth\')' +
' db.getSiblingDB(\'admin\').auth(\'' + authUser + '\',\'' + authPassword + '\'); ' +
' var dbName = (Math.random() + 1).toString(36).substring(7); ' +
' var clName = (Math.random() + 1).toString(36).substring(7); ' +
' for (var i = 0; i < 10000; ++i) { ' +
' db.getSiblingDB(dbName).getCollection(clName).find({ x: i }).forEach(); \n' +
' sleep(1); \n' +
' db.getSiblingDB(dbName).getCollection(clName).insert({ x: i }); \n' +
' sleep(1);\n' +
' }\n';
var shells = [];
for (var i = 0; i < 10; ++i) {
shells.push(startParallelShell(stressShell));
}
// wait a bit for the stress to kick in
sleep(5000);
jsTest.log('Current operation(s)');
printjson(db.currentOp());
// ensure tool runs without error
clearRawMongoProgramOutput();
assert.eq(runMongoProgram.apply(this, ['mongotop', '--port', conn.port, '--json', '--rowcount', 1].concat(passthrough.args)), 0, 'failed 1');
t.stop();
// Wait for all the shells to finish per SERVER-25777.
shells.forEach(function(join) {
join();
});
};
// run with plain and auth passthroughs
passthroughs.forEach(function(passthrough) {
runTests(standaloneTopology, passthrough);
runTests(replicaSetTopology, passthrough);
});
}());
|