-
Notifications
You must be signed in to change notification settings - Fork 74
/
Copy pathjitter.js
executable file
·94 lines (76 loc) · 1.97 KB
/
jitter.js
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/* jitter.js
This file is a simple test of latency to the database server.
Run it on the same box (localhost) to verify the speed of the database process.
Run it remotely to check end to end latency including network effects.
Note: the shell is javascript and could be slow. Keep that in mind. There may also
be garbage collections by the shell. If the shell has been running for a very
long time and you see slow times, a quick restart is recommended just to confirm
that the server is slow and not the shell.
Usage:
mongo <usualparms> jitter.js
Set the coll and query variables below.
*/
// choose a collection:
var coll = "foo";
// choose a query:
var query = { x : 1 };
var t = db[coll];
function time(f) {
var s = new Date();
f();
return new Date()-s;
}
var basecase = {};
var querycase = {};
function reset(x) {
x.max = 0;
x.n = 0;
x.t = 0;
x.min = 100000;
x.slow = 0;
}
function say(res) {
print(Date() + ' ' + res.min + ' / ' + Math.round(100*res.t/res.n)/100 + ' / ' + res.max + ' / ' + res.slow);
}
function test(query, result) {
var ms = time( function() { t.findOne(query) } );
if( ms < result.min ) result.min = ms;
if( ms > result.max ) result.max = ms;
if( ms > 2 ) result.slow++;
result.n++;
result.t += ms;
}
print();
print("collection: " + coll);
print("count: " + t.count());
print("query:");
printjson(query);
print("indexes:");
printjson( t.getIndexes() );
print("explain:");
printjson( t.find(query).limit(1).explain() );
var N = 200;
print("N : " + N);
print();
print(Date() + ' min / avg / max / n>2ms');
print();
while( 1 ) {
reset(basecase);
reset(querycase);
try {
for( var i = 0; i < N; i++ ) {
test({}, basecase);
test(query, querycase);
sleep(10);
}
say(basecase); say(querycase);
print();
}
catch(e) {
print();
print(Date() + " exception during query: " + e);
print();
sleep(5000);
}
sleep(100);
}