forked from yahoo/streaming-benchmarks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stream-bench.sh
executable file
·364 lines (342 loc) · 11.1 KB
/
stream-bench.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
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
#!/bin/bash
# Copyright 2015, Yahoo Inc.
# Licensed under the terms of the Apache License 2.0. Please see LICENSE file in the project root for terms.
set -o pipefail
set -o errtrace
set -o nounset
set -o errexit
LEIN=${LEIN:-lein}
MVN=${MVN:-mvn}
GIT=${GIT:-git}
MAKE=${MAKE:-make}
KAFKA_VERSION=${KAFKA_VERSION:-"0.8.2.1"}
REDIS_VERSION=${REDIS_VERSION:-"3.0.5"}
SCALA_BIN_VERSION=${SCALA_BIN_VERSION:-"2.10"}
SCALA_SUB_VERSION=${SCALA_SUB_VERSION:-"4"}
STORM_VERSION=${STORM_VERSION:-"0.10.0"}
FLINK_VERSION=${FLINK_VERSION:-"0.10.1"}
SPARK_VERSION=${SPARK_VERSION:-"1.5.1"}
STORM_DIR="apache-storm-$STORM_VERSION"
REDIS_DIR="redis-$REDIS_VERSION"
KAFKA_DIR="kafka_$SCALA_BIN_VERSION-$KAFKA_VERSION"
FLINK_DIR="flink-$FLINK_VERSION"
SPARK_DIR="spark-$SPARK_VERSION-bin-hadoop2.6"
#Get one of the closet apache mirrors
APACHE_MIRROR=$(curl 'https://www.apache.org/dyn/closer.cgi' | grep -o '<strong>[^<]*</strong>' | sed 's/<[^>]*>//g' | head -1)
ZK_HOST="localhost"
ZK_PORT="2181"
ZK_CONNECTIONS="$ZK_HOST:$ZK_PORT"
TOPIC=${TOPIC:-"ad-events"}
PARTITIONS=${PARTITIONS:-1}
LOAD=${LOAD:-1000}
CONF_FILE=./conf/localConf.yaml
TEST_TIME=${TEST_TIME:-240}
pid_match() {
local VAL=`ps -aef | grep "$1" | grep -v grep | awk '{print $2}'`
echo $VAL
}
start_if_needed() {
local match="$1"
shift
local name="$1"
shift
local sleep_time="$1"
shift
local PID=`pid_match "$match"`
if [[ "$PID" -ne "" ]];
then
echo "$name is already running..."
else
"$@" &
sleep $sleep_time
fi
}
stop_if_needed() {
local match="$1"
local name="$2"
local PID=`pid_match "$match"`
if [[ "$PID" -ne "" ]];
then
kill "$PID"
sleep 1
local CHECK_AGAIN=`pid_match "$match"`
if [[ "$CHECK_AGAIN" -ne "" ]];
then
kill -9 "$CHECK_AGAIN"
fi
else
echo "No $name instance found to stop"
fi
}
fetch_untar_file() {
local FILE="download-cache/$1"
local URL=$2
if [[ -e "$FILE" ]];
then
echo "Using cached File $FILE"
else
mkdir -p download-cache/
WGET=`whereis wget`
CURL=`whereis curl`
if [ -n "$WGET" ];
then
wget -O "$FILE" "$URL"
elif [ -n "$CURL" ];
then
curl -o "$FILE" "$URL"
else
echo "Please install curl or wget to continue.";
exit 1
fi
fi
tar -xzvf "$FILE"
}
create_kafka_topic() {
local count=`$KAFKA_DIR/bin/kafka-topics.sh --describe --zookeeper "$ZK_CONNECTIONS" --topic $TOPIC 2>/dev/null | grep -c $TOPIC`
if [[ "$count" = "0" ]];
then
$KAFKA_DIR/bin/kafka-topics.sh --create --zookeeper "$ZK_CONNECTIONS" --replication-factor 1 --partitions $PARTITIONS --topic $TOPIC
else
echo "Kafka topic $TOPIC already exists"
fi
}
run() {
OPERATION=$1
if [ "SETUP" = "$OPERATION" ];
then
$GIT clean -fd
echo 'kafka.brokers:' > $CONF_FILE
echo ' - "localhost"' >> $CONF_FILE
echo >> $CONF_FILE
echo 'zookeeper.servers:' >> $CONF_FILE
echo ' - "'$ZK_HOST'"' >> $CONF_FILE
echo >> $CONF_FILE
echo 'kafka.port: 9092' >> $CONF_FILE
echo 'zookeeper.port: '$ZK_PORT >> $CONF_FILE
echo 'redis.host: "localhost"' >> $CONF_FILE
echo 'kafka.topic: "'$TOPIC'"' >> $CONF_FILE
echo 'kafka.partitions: '$PARTITIONS >> $CONF_FILE
echo 'process.hosts: 1' >> $CONF_FILE
echo 'process.cores: 4' >> $CONF_FILE
echo 'storm.workers: 1' >> $CONF_FILE
echo 'storm.ackers: 2' >> $CONF_FILE
echo 'spark.batchtime: 2000' >> $CONF_FILE
$MVN clean install -Dspark.version="$SPARK_VERSION" -Dkafka.version="$KAFKA_VERSION" -Dflink.version="$FLINK_VERSION" -Dstorm.version="$STORM_VERSION" -Dscala.binary.version="$SCALA_BIN_VERSION" -Dscala.version="$SCALA_BIN_VERSION.$SCALA_SUB_VERSION"
#Fetch and build Redis
REDIS_FILE="$REDIS_DIR.tar.gz"
fetch_untar_file "$REDIS_FILE" "http://download.redis.io/releases/$REDIS_FILE"
cd $REDIS_DIR
$MAKE
cd ..
#Fetch Kafka
KAFKA_FILE="$KAFKA_DIR.tgz"
fetch_untar_file "$KAFKA_FILE" "$APACHE_MIRROR/kafka/$KAFKA_VERSION/$KAFKA_FILE"
#Fetch Storm
STORM_FILE="$STORM_DIR.tar.gz"
fetch_untar_file "$STORM_FILE" "$APACHE_MIRROR/storm/$STORM_DIR/$STORM_FILE"
#Fetch Flink
FLINK_FILE="$FLINK_DIR-bin-hadoop27-scala_${SCALA_BIN_VERSION}.tgz"
fetch_untar_file "$FLINK_FILE" "$APACHE_MIRROR/flink/flink-$FLINK_VERSION/$FLINK_FILE"
#Fetch Spark
SPARK_FILE="$SPARK_DIR.tgz"
fetch_untar_file "$SPARK_FILE" "$APACHE_MIRROR/spark/spark-$SPARK_VERSION/$SPARK_FILE"
elif [ "START_ZK" = "$OPERATION" ];
then
start_if_needed dev_zookeeper ZooKeeper 10 "$STORM_DIR/bin/storm" dev-zookeeper
elif [ "STOP_ZK" = "$OPERATION" ];
then
stop_if_needed dev_zookeeper ZooKeeper
rm -rf /tmp/dev-storm-zookeeper
elif [ "START_REDIS" = "$OPERATION" ];
then
start_if_needed redis-server Redis 1 "$REDIS_DIR/src/redis-server"
cd data
$LEIN run -n --configPath ../conf/benchmarkConf.yaml
cd ..
elif [ "STOP_REDIS" = "$OPERATION" ];
then
stop_if_needed redis-server Redis
rm -f dump.rdb
elif [ "START_STORM" = "$OPERATION" ];
then
start_if_needed daemon.name=nimbus "Storm Nimbus" 3 "$STORM_DIR/bin/storm" nimbus
start_if_needed daemon.name=supervisor "Storm Supervisor" 3 "$STORM_DIR/bin/storm" supervisor
start_if_needed daemon.name=ui "Storm UI" 3 "$STORM_DIR/bin/storm" ui
start_if_needed daemon.name=logviewer "Storm LogViewer" 3 "$STORM_DIR/bin/storm" logviewer
sleep 20
elif [ "STOP_STORM" = "$OPERATION" ];
then
stop_if_needed daemon.name=nimbus "Storm Nimbus"
stop_if_needed daemon.name=supervisor "Storm Supervisor"
stop_if_needed daemon.name=ui "Storm UI"
stop_if_needed daemon.name=logviewer "Storm LogViewer"
elif [ "START_KAFKA" = "$OPERATION" ];
then
start_if_needed kafka\.Kafka Kafka 10 "$KAFKA_DIR/bin/kafka-server-start.sh" "$KAFKA_DIR/config/server.properties"
create_kafka_topic
elif [ "STOP_KAFKA" = "$OPERATION" ];
then
stop_if_needed kafka\.Kafka Kafka
rm -rf /tmp/kafka-logs/
elif [ "START_FLINK" = "$OPERATION" ];
then
start_if_needed org.apache.flink.runtime.jobmanager.JobManager Flink 1 $FLINK_DIR/bin/start-local.sh
elif [ "STOP_FLINK" = "$OPERATION" ];
then
$FLINK_DIR/bin/stop-local.sh
elif [ "START_SPARK" = "$OPERATION" ];
then
start_if_needed org.apache.spark.deploy.master.Master SparkMaster 5 $SPARK_DIR/sbin/start-master.sh -h localhost -p 7077
start_if_needed org.apache.spark.deploy.worker.Worker SparkSlave 5 $SPARK_DIR/sbin/start-slave.sh spark://localhost:7077
elif [ "STOP_SPARK" = "$OPERATION" ];
then
stop_if_needed org.apache.spark.deploy.master.Master SparkMaster
stop_if_needed org.apache.spark.deploy.worker.Worker SparkSlave
sleep 3
elif [ "START_LOAD" = "$OPERATION" ];
then
cd data
start_if_needed leiningen.core.main "Load Generation" 1 $LEIN run -r -t $LOAD --configPath ../$CONF_FILE
cd ..
elif [ "STOP_LOAD" = "$OPERATION" ];
then
stop_if_needed leiningen.core.main "Load Generation"
cd data
$LEIN run -g --configPath ../$CONF_FILE || true
cd ..
elif [ "START_STORM_TOPOLOGY" = "$OPERATION" ];
then
"$STORM_DIR/bin/storm" jar ./storm-benchmarks/target/storm-benchmarks-0.1.0.jar storm.benchmark.AdvertisingTopology test-topo -conf $CONF_FILE
sleep 15
elif [ "STOP_STORM_TOPOLOGY" = "$OPERATION" ];
then
"$STORM_DIR/bin/storm" kill -w 0 test-topo || true
sleep 10
elif [ "START_SPARK_PROCESSING" = "$OPERATION" ];
then
"$SPARK_DIR/bin/spark-submit" --master spark://localhost:7077 --class spark.benchmark.KafkaRedisAdvertisingStream ./spark-benchmarks/target/spark-benchmarks-0.1.0.jar "$CONF_FILE" &
sleep 5
elif [ "STOP_SPARK_PROCESSING" = "$OPERATION" ];
then
stop_if_needed spark.benchmark.KafkaRedisAdvertisingStream "Spark Client Process"
elif [ "START_FLINK_PROCESSING" = "$OPERATION" ];
then
"$FLINK_DIR/bin/flink" run ./flink-benchmarks/target/flink-benchmarks-0.1.0.jar --confPath $CONF_FILE &
sleep 3
elif [ "STOP_FLINK_PROCESSING" = "$OPERATION" ];
then
FLINK_ID=`"$FLINK_DIR/bin/flink" list | grep 'Flink Streaming Job' | awk '{print $4}'; true`
if [ "$FLINK_ID" == "" ];
then
echo "Could not find streaming job to kill"
else
"$FLINK_DIR/bin/flink" cancel $FLINK_ID
sleep 3
fi
elif [ "STORM_TEST" = "$OPERATION" ];
then
run "START_ZK"
run "START_REDIS"
run "START_KAFKA"
run "START_STORM"
run "START_STORM_TOPOLOGY"
run "START_LOAD"
sleep $TEST_TIME
run "STOP_LOAD"
run "STOP_STORM_TOPOLOGY"
run "STOP_STORM"
run "STOP_KAFKA"
run "STOP_REDIS"
run "STOP_ZK"
elif [ "FLINK_TEST" = "$OPERATION" ];
then
run "START_ZK"
run "START_REDIS"
run "START_KAFKA"
run "START_FLINK"
run "START_FLINK_PROCESSING"
run "START_LOAD"
sleep $TEST_TIME
run "STOP_LOAD"
run "STOP_FLINK_PROCESSING"
run "STOP_FLINK"
run "STOP_KAFKA"
run "STOP_REDIS"
run "STOP_ZK"
elif [ "SPARK_TEST" = "$OPERATION" ];
then
run "START_ZK"
run "START_REDIS"
run "START_KAFKA"
run "START_SPARK"
run "START_SPARK_PROCESSING"
run "START_LOAD"
sleep $TEST_TIME
run "STOP_LOAD"
run "STOP_SPARK_PROCESSING"
run "STOP_SPARK"
run "STOP_KAFKA"
run "STOP_REDIS"
run "STOP_ZK"
elif [ "STOP_ALL" = "$OPERATION" ];
then
run "STOP_LOAD"
run "STOP_SPARK_PROCESSING"
run "STOP_SPARK"
run "STOP_FLINK_PROCESSING"
run "STOP_FLINK"
run "STOP_STORM_TOPOLOGY"
run "STOP_STORM"
run "STOP_KAFKA"
run "STOP_REDIS"
run "STOP_ZK"
else
if [ "HELP" != "$OPERATION" ];
then
echo "UNKOWN OPERATION '$OPERATION'"
echo
fi
echo "Supported Operations:"
echo "SETUP: download and setup dependencies for running a single node test"
echo "START_ZK: run a single node ZooKeeper instance on local host in the background"
echo "STOP_ZK: kill the ZooKeeper instance"
echo "START_REDIS: run a redis instance in the background"
echo "STOP_REDIS: kill the redis instance"
echo "START_KAFKA: run kafka in the background"
echo "STOP_KAFKA: kill kafka"
echo "START_LOAD: run kafka load generation"
echo "STOP_LOAD: kill kafka load generation"
echo "START_STORM: run storm daemons in the background"
echo "STOP_STORM: kill the storm daemons"
echo "START_FLINK: run flink processes"
echo "STOP_FLINK: kill flink processes"
echo "START_SPARK: run spark processes"
echo "STOP_SPARK: kill spark processes"
echo
echo "START_STORM_TOPOLOGY: run the storm test topology"
echo "STOP_STORM_TOPOLOGY: kill the storm test topology"
echo "START_FLINK_PROCESSING: run the flink test processing"
echo "STOP_FLINK_PROCESSSING: kill the flink test processing"
echo "START_SPARK_PROCESSING: run the spark test processing"
echo "STOP_SPARK_PROCESSSING: kill the spark test processing"
echo
echo "STORM_TEST: run storm test (assumes SETUP is done)"
echo "FLINK_TEST: run flink test (assumes SETUP is done)"
echo "SPARK_TEST: run spark test (assumes SETUP is done)"
echo "STOP_ALL: stop everything"
echo
echo "HELP: print out this message"
echo
exit 1
fi
}
if [ $# -lt 1 ];
then
run "HELP"
else
while [ $# -gt 0 ];
do
run "$1"
shift
done
fi