-
Notifications
You must be signed in to change notification settings - Fork 6
/
document_lock_test.sh
73 lines (48 loc) · 1.37 KB
/
document_lock_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} $@ 2>&1 > mongod.log &
sleep 3
}
# main
THREADS=8
INCS=1000
echo "Starting clean server..."
killall -q mongod
sleep 1
reset_server "$@"
# reset
echo "Reseting inctest collection to 0..."
./mongo --quiet --eval 'db.inctest.insert({ _id: 1, x: 0});' 2>&1 > /dev/null
# spawn threads
echo "Spawning ${THREADS} threads to increcment document ${INCS} times..."
pidArray=()
for ((t=0; t<${THREADS}; t++)); do
./mongo --quiet --eval "for(i=0; i<${INCS}; i++){db.inctest.update({_id:1},{\$inc:{x:1}});}" 2>&1 > /dev/null &
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 ""
# reporting increment (should equal threads * incs)
echo "Comparing..."
total=$(./mongo --quiet --eval "db.inctest.findOne({_id:1}).x")
if [ ${total:-0} -eq $(( ${THREADS} * ${INCS} )) ]; then
echo "Success! ${total} in database is equal to ${THREADS} * ${INCS}"
else
echo "Failed! ${total} in database is NOT equal to ${THREADS} * ${INCS}"
fi
# kill server
killall -q mongod
sleep 1