-
Notifications
You must be signed in to change notification settings - Fork 6
/
document_concurrent_update_test.sh
executable file
·73 lines (48 loc) · 1.43 KB
/
document_concurrent_update_test.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
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
#!/bin/bash
basedir=$(cd $(dirname "$0"); pwd)
function reset_server {
cd $basedir
rm -rf data
mkdir data
lse=""
if ! [[ "$*" == *"storageEngine"* ]]; then
lse=" --storageEngine=PerconaFT"
fi
./mongod --dbpath=./data ${lse} $@ > mongod.log 2>&1 &
sleep 3
}
# main
OIDS=4
THREADS=64
INCS=1024
echo "Starting clean server..."
killall -q mongod
sleep 1
reset_server "$@"
# 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"
# kill server
killall -q mongod
sleep 1