-
Notifications
You must be signed in to change notification settings - Fork 0
/
run-test.sh
executable file
·305 lines (242 loc) · 7.25 KB
/
run-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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
usage () {
echo "Usage: $0 [-p] [-m] [-c] [-d] [-e] server_name test_run_name"
echo " -p - Use perf for profiling"
echo " -m - Put datadir on /dev/shm"
echo " -c - Assume sysbench uses 4 tables and move them to different CFs."
echo " -d - Same but use 2 CFs"
echo " -e - Remove the secondary index"
}
###
### Parse options
###
while getopts ":pmcde" opt; do
case ${opt} in
p ) USE_PERF=1
;;
m ) USE_RAMDISK=1
;;
c ) USE_4_CFS=1
;;
d ) USE_2_CFS=1
;;
e ) DROP_SECONDARY_INDEX=1
;;
\? )
usage;
exit 1
;;
esac
done
shift $((OPTIND -1))
SERVERNAME=$1
RUN_NAME=$2
if [[ $USE_4_CFS && $USE_2_CFS ]] ; then
echo "Use either -c (USE_4_CFS) or -d (USE_2_CFS)"
exit 1
fi
if [ "x${SERVERNAME}y" = "xy" ] ; then
usage;
exit 1
fi
if [ "x${RUN_NAME}y" = "xy" ] ; then
usage;
exit 1
fi
I_S="information_schema"
SERVER_DIR=mysql-5.6-$SERVERNAME
if [ ! -d $SERVER_DIR ]; then
SERVER_DIR=mysql-8.0-$SERVERNAME
USING_MYSQL8=1
I_S="performance_schema"
if [ ! -d $SERVER_DIR ]; then
SERVER_DIR=mysql-$SERVERNAME
if [ ! -d $SERVER_DIR ]; then
echo "Bad server name $SERVERNAME."
exit 1
fi
fi
fi
if [[ $USING_MYSQL8 ]]; then
MYSQL_CLIENT=$SERVER_DIR/build/bin/mysql
MYSQLD_BINARY=$SERVER_DIR/build/bin/mysqld
else
MYSQL_CLIENT=$SERVER_DIR/client/mysql
MYSQLD_BINARY=$SERVER_DIR/sql/mysqld
fi
if [ ! -f $MYSQL_CLIENT ]; then
echo "Cannot find $MYSQL_CLIENT"
exit 1;
fi
if [ ! -f $MYSQLD_BINARY ]; then
echo "Cannot find $MYSQLD_BINARY"
exit 1;
fi
RESULT_DIR=results/$RUN_NAME
if [ -d $RESULT_DIR ]; then
echo "Result directory for $RUN_NAME already exists"
exit 1
fi
echo "Starting test "$RUN_NAME" with $SERVER_DIR"
if [[ $USE_PERF ]] ; then
echo " Collecting perf profile"
fi
if [[ $USE_RAMDISK ]] ; then
echo " Using /dev/shm for data dir"
fi
if [[ $USE_4_CFS ]] ; then
echo " Data is in 4 tables"
fi
if [[ $USE_2_CFS ]] ; then
echo " Data is in 2 tables"
fi
#############################################################################
### Start the server
killall -9 mysqld
sleep 5
DATA_DIR=data-fbmysql-$SERVERNAME
rm -rf $DATA_DIR
initialize_mysql8_datadir() {
$MYSQLD_BINARY --defaults-file=./my-fbmysql-${SERVERNAME}.cnf --initialize-insecure
}
if [[ $USE_RAMDISK ]] ; then
rm -rf /dev/shm/$DATA_DIR
rm -rf /dev/shm/data-fbmysql-*
if [[ $USING_MYSQL8 ]] ; then
# intialize
mkdir /dev/shm/$DATA_DIR
ln -s /dev/shm/$DATA_DIR $DATA_DIR
initialize_mysql8_datadir
else
cp -r ${DATA_DIR}.clean /dev/shm/$DATA_DIR
ln -s /dev/shm/$DATA_DIR $DATA_DIR
fi
else
if [[ $USING_MYSQL8 ]] ; then
mkdir $DATA_DIR
initialize_mysql8_datadir
else
cp -r ${DATA_DIR}.clean $DATA_DIR
fi
fi
#exit 0;
MYSQL_CMD="$MYSQL_CLIENT --defaults-file=./my-fbmysql-${SERVERNAME}.cnf -uroot"
server_attempts=0
while true ; do
$MYSQLD_BINARY --defaults-file=./my-fbmysql-${SERVERNAME}.cnf &
sleep 5
client_attempts=0
while true ; do
$MYSQL_CMD -e "drop database if exists sbtest"
$MYSQL_CMD -e "create database sbtest"
if [ $? -eq 0 ]; then
break
fi
sleep 1
client_attempts=$((client_attempts + 1))
if [ $client_attempts -ge 10 ]; then
break;
fi
done
MYSQLD_PID=`ps -C mysqld --no-header | awk '{print $1}'`
if [[ "a${MYSQLD_PID}b" != "ab" ]] ; then
break
fi
server_attempts=$((server_attempts + 1))
if [ $server_attempts -ge 4 ]; then
echo "Failed to launch mysqld"
exit 1
fi
done
#############################################################################
### Prepare the benchmark
RESULT_DIR=results/$RUN_NAME
mkdir -p $RESULT_DIR
SYSBENCH_ARGS=" --db-driver=mysql --mysql-host=127.0.0.1 --mysql-user=root \
--mysql-storage-engine=rocksdb \
--time=60 \
/usr/share/sysbench/oltp_write_only.lua"
if [[ $USE_4_CFS ]] ; then
SYSBENCH_ARGS="$SYSBENCH_ARGS --tables=4 --table-size=250000"
elif [[ $USE_2_CFS ]] ; then
SYSBENCH_ARGS="$SYSBENCH_ARGS --tables=2 --table-size=500000"
else
SYSBENCH_ARGS="$SYSBENCH_ARGS --table-size=1000000"
fi
## /usr/share/sysbench/oltp_write_only.lua --table-size=250000 --tables=4"
SYSBENCH_TEST="oltp_write_only.lua"
(cd $SERVER_DIR && git log -1 ) > $RESULT_DIR/server-cset.txt
(cd $SERVER_DIR/rocksdb && git log -1 ) > $RESULT_DIR/rocksdb-cset.txt
cat > $RESULT_DIR/info.txt <<END
SERVERNAME=$SERVERNAME
SYSBENCH_TEST=$SYSBENCH_TEST
SERVER_DIR=$SERVER_DIR
SYSBENCH_ARGS=$SYSBENCH_ARGS
END
sleep 3
sysbench $SYSBENCH_ARGS prepare | tee $RESULT_DIR/sysbench-prepare.txt
if [[ $USE_4_CFS ]] ; then
echo "Splitting 4 tables into different CFs"
$MYSQL_CMD < make-4-cfs.sql
fi
if [[ $USE_2_CFS ]] ; then
echo "Splitting 2 tables into different CFs"
$MYSQL_CMD < make-2-cfs.sql
fi
if [[ $DROP_SECONDARY_INDEX ]]; then
if [[ $USE_4_CFS ]]; then
echo "Dropping the secondary indexes"
for i in `seq 1 4` ; do
echo "alter table sbtest.sbtest$i drop key k_1" | $MYSQL_CMD
echo "show create table sbtest.sbtest$i" | $MYSQL_CMD
done
fi
if [[ $USE_2_CFS ]]; then
echo "DROP_SECONDARY_INDEX and USE_2_CFS are not supported"
exit 1
fi
echo "Dropping the secondary index"
echo "alter table sbtest.sbtest1 drop key k_1" | $MYSQL_CMD
echo "show create table sbtest.sbtest1" | $MYSQL_CMD
fi
sleep 3
$MYSQL_CMD -e "show variables like 'rocksdb%'" > $RESULT_DIR/variables-rocksdb.txt
$MYSQL_CMD -e "show variables" > $RESULT_DIR/variables-all.txt
$MYSQL_CMD -e "select * from $I_S.global_status where variable_name like 'ROCKSDB%'" > $RESULT_DIR/status-before-test.txt
sleep 3
#############################################################################
### Start the profiler
if [[ $USE_PERF ]] ; then
# Start perf
sudo sh -c "echo -1 >> /proc/sys/kernel/perf_event_paranoid"
#sudo perf record -F 99 -p $MYSQLD_PID -g sleep 60 &
sudo perf record -F 99 -a -g sleep 60 &
fi
#############################################################################
### Run the benchmark
RUNS="1 5 10 20 40 60 80 100"
if [[ $USE_PERF ]] ; then
RUNS="100"
fi
for threads in $RUNS ; do
#echo "THREADS $threads $storage_engine"
$MYSQL_CMD -e "drop table if exists sbtest.rocksdb_vars;"
$MYSQL_CMD -e "create table sbtest.rocksdb_vars as select * from $I_S.global_status where variable_name like 'ROCKSDB%'"
$MYSQL_CMD -e "drop table if exists sbtest.rocksdb_perf_context_global;"
$MYSQL_CMD -e "create table sbtest.rocksdb_perf_context_global as select * from information_schema.rocksdb_perf_context_global \
where 1"
SYSBENCH_ALL_ARGS="$SYSBENCH_ARGS --threads=$threads"
OUTFILE="${RESULT_DIR}/sysbench-run-${threads}.txt"
sysbench $SYSBENCH_ALL_ARGS run | tee $OUTFILE
$MYSQL_CMD -e \
"select A.VARIABLE_NAME, B.VARIABLE_VALUE - A.VARIABLE_VALUE \
from $I_S.global_status B, sbtest.rocksdb_vars A \
where B.VARIABLE_NAME=A.VARIABLE_NAME AND B.VARIABLE_VALUE - A.VARIABLE_VALUE >0" > $RESULT_DIR/status-after-test-$threads.txt
$MYSQL_CMD -e \
"select A.STAT_TYPE, FORMAT(B.VALUE - A.VALUE,0) \
from information_schema.rocksdb_perf_context_global B, sbtest.rocksdb_perf_context_global A \
where B.STAT_TYPE=A.STAT_TYPE AND B.VALUE - A.VALUE >0" > $RESULT_DIR/perf_context-after-test-$threads.txt
done
if [[ $USE_PERF ]] ; then
CUR_USER=`id -un`
sudo chown $CUR_USER perf.*
fi