-
Notifications
You must be signed in to change notification settings - Fork 6
/
time_tree_conflict.sh
executable file
·45 lines (30 loc) · 1.09 KB
/
time_tree_conflict.sh
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
#!/bin/bash
basedir=$(cd $(dirname "$0"); pwd)
# main
OIDS=128
THREADS=128
INCS=8192
# reset
echo "Reset updtest"
rm mongo_*.out
./mongo --quiet --eval "db.updtest.drop();for(i=0; i<${OIDS}; i++){db.updtest.insert({_id:i,updated:0});}" > /dev/null 2>&1
# spawn threads
echo "Spawning ${THREADS} threads to increcment ids ${INCS} times..."
pidArray=()
for ((t=0; t<${THREADS}; t++)); do
./mongo --quiet --eval "for(i=0;i<${INCS};i++){oid=Random.randInt(${OIDS});upd=db.updtest.findOne({_id:oid}).updated;printjson(db.updtest.update({_id:oid,updated:upd},{updated:upd+1}));}" > mongo_${t}.out 2>&1 &
pidArray+=($!)
done
# wait for processes to end
echo -n "Waiting for jobs to complete"
for p in "${pidArray[@]}"; do
wait $p
echo -n '.'
done
echo ""
# results
dbincs=$(./mongo --quiet --eval 'print(db.updtest.aggregate([{$group:{_id:null,total:{$sum:"$updated"}}}]).next().total)')
recincs=$(grep '{ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 }' mongo_*.out | wc -l)
echo "dbincs=${dbincs}"
echo "recincs=${recincs}"
[ "${dbincs}" == "${recincs}" ] && echo "SUCCESS" || echo "FAILED"