blob: 609413683e859a2730ef872ac568c2d01bff6d6c (
plain)
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
|
db = db.getSisterDB("concurrency")
db.dropDatabase();
NRECORDS=5*1024*1024 // this needs to be relatively big so that
// the update() will take a while, but it could
// probably be smaller.
print("loading "+NRECORDS+" documents (progress msg every 1024*1024 documents)")
for (i=0; i<(NRECORDS); i++) {
db.conc.insert({x:i})
if ((i%(1024*1024))==0)
print("loaded " + i/(1024*1024) + " mibi-records")
}
print("making an index (this will take a while)")
db.conc.ensureIndex({x:1})
var c1=db.conc.count({x:{$lt:NRECORDS}})
// this is just a flag that the child will toggle when it's done.
db.concflag.update({}, {inprog:true}, true)
updater=startParallelShell("db=db.getSisterDB('concurrency');\
db.conc.update({}, {$inc:{x: "+NRECORDS+"}}, false, true);\
e=db.getLastError();\
print('update error: '+ e);\
db.concflag.update({},{inprog:false});\
assert.eq(e, null, \"update failed\");");
querycount=0;
decrements=0;
misses=0
while (1) {
if (db.concflag.findOne().inprog) {
c2=db.conc.count({x:{$lt:NRECORDS}})
e=db.getLastError()
print(c2)
print(e)
assert.eq(e, null, "some count() failed")
querycount++;
if (c2<c1)
decrements++;
else
misses++;
c1 = c2;
} else
break;
sleep(10);
}
print(querycount + " queries, " + decrements + " decrements, " + misses + " misses");
updater() // wait()
|