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
57
58
59
60
61
62
63
64
65
66
|
/**
* This test artificially throttles a replica set by limiting the tickets handed out. It first
* performs a calibrating run that sees how many inserts per second a one node replica set can
* handle. Non-batch inserts should acquire one lock per insert. The test then sets the ticket
* generation to a fraction of this discovered calibration value. A following benchrun validates the
* new insert rate falls within some (generous) range.
*
* @tags: [
* requires_replication,
* requires_flow_control,
* requires_majority_read_concern,
* ]
*/
(function() {
"use strict";
const replTest = new ReplSetTest({nodes: 1});
replTest.startSet();
replTest.initiate();
const primary = replTest.getPrimary();
assert.commandWorked(primary.adminCommand({
configureFailPoint: "flowControlTicketOverride",
mode: "alwaysOn",
data: {"numTickets": 1000 * 1000 * 1000}
}));
// Sleep 2 seconds for the failpoint to take effect.
sleep(2000);
let result = benchRun({
host: primary.host,
seconds: 5,
parallel: 5,
ops: [{op: "insert", ns: "foo.bar", doc: {field: "value"}}]
});
jsTestLog({CalibratingRun: result});
let insertRate = result["insert"];
let throttledRate = insertRate / 2;
assert.commandWorked(primary.adminCommand({
configureFailPoint: "flowControlTicketOverride",
mode: "alwaysOn",
data: {"numTickets": NumberInt(throttledRate)}
}));
// Sleep 2 seconds for the failpoint to take effect.
sleep(2000);
result = benchRun({
host: primary.host,
seconds: 5,
parallel: 5,
ops: [{op: "insert", ns: "foo.bar", doc: {field: "value"}}]
});
jsTestLog({ThrottledRun: result, ThrottedRate: throttledRate});
let maxAllowedRate = 1.5 * throttledRate;
let minAllowedRate = 0.5 * throttledRate;
assert.gt(result["insert"], minAllowedRate);
assert.lt(result["insert"], maxAllowedRate);
// Cautiously unset to avoid any interaction with shutdown.
assert.commandWorked(
primary.adminCommand({configureFailPoint: "flowControlTicketOverride", mode: "off"}));
replTest.stopSet();
})();
|