-
Notifications
You must be signed in to change notification settings - Fork 1
/
run.py
549 lines (430 loc) · 21 KB
/
run.py
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
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
"""
This module handle the configuration of the instances and the execution of the benchmark on the cluster
"""
import json
import multiprocessing
import time
from concurrent.futures import ThreadPoolExecutor
import boto3
import log
import metrics
import plot
from config import UPDATE_SPARK_DOCKER, DELETE_HDFS, SPARK_HOME, KILL_JAVA, SYNC_TIME, \
KEY_PAIR_PATH, \
UPDATE_SPARK, \
DISABLE_HT, ENABLE_EXTERNAL_SHUFFLE, OFF_HEAP, OFF_HEAP_BYTES, K, T_SAMPLE, TI, CORE_QUANTUM, \
CORE_MIN, CPU_PERIOD, HDFS, \
CORE_VM, UPDATE_SPARK_MASTER, DEADLINE, MAX_EXECUTOR, ALPHA, OVER_SCALE, LOCALITY_WAIT, \
LOCALITY_WAIT_NODE, CPU_TASK, \
LOCALITY_WAIT_PROCESS, LOCALITY_WAIT_RACK, INPUT_RECORD, NUM_TASK, BENCH_NUM_TRIALS, \
SCALE_FACTOR, RAM_EXEC, \
RAM_DRIVER, BENCHMARK_PERF, BENCH_LINES, HDFS_MASTER, DATA_AMI, REGION, HADOOP_CONF, \
CONFIG_DICT, CREDENTIAL_PROFILE, \
CLUSTER_ID, SPARK_2_HOME, BENCHMARK_BENCH, BENCH_CONF, LOG_LEVEL
from util.cmdshell import sshclient_from_instance
from util.utils import timing, between
def common_setup(ssh_client):
"""
Common setup of the instance of the cluster with ssh_client is connected
:param ssh_client: the ssh client to launch command on the instance
:return: nothing
"""
ssh_client.run("export GOMAXPROCS=`nproc`")
if UPDATE_SPARK_DOCKER:
print(" Updating Spark Docker Image...")
ssh_client.run("docker pull elfolink/spark:2.0")
if DELETE_HDFS:
ssh_client.run("sudo umount /mnt")
ssh_client.run(
"sudo mkfs.ext4 -E nodiscard /dev/xvdb && sudo mount -o discard /dev/xvdb /mnt")
ssh_client.run("test -d /mnt/tmp || sudo mkdir -m 1777 /mnt/tmp")
ssh_client.run("sudo mount --bind /mnt/tmp /tmp")
ssh_client.run('ssh-keygen -f "/home/ubuntu/.ssh/known_hosts" -R localhost')
print(" Stop Spark Slave/Master")
ssh_client.run('export SPARK_HOME="{s}" && {s}sbin/stop-slave.sh'.format(s=SPARK_HOME))
ssh_client.run('export SPARK_HOME="{s}" && {s}sbin/stop-master.sh'.format(s=SPARK_HOME))
print(" Set Log Level")
ssh_client.run(
"sed -i '19s/.*/log4j.rootCategory={}, console /' {}conf/log4j.properties".format(LOG_LEVEL,
SPARK_HOME))
if KILL_JAVA:
print(" Killing Java")
ssh_client.run('sudo killall java && sudo killall java && sudo killall java')
print(" Kill SAR CPU Logger")
ssh_client.run("screen -ls | grep Detached | cut -d. -f1 | awk '{print $1}' | xargs -r kill")
if SYNC_TIME:
print(" SYNC TIME")
ssh_client.run("sudo ntpdate -s time.nist.gov")
print(" Removing Stopped Docker")
ssh_client.run("docker ps -a | awk '{print $1}' | xargs --no-run-if-empty docker rm")
@timing
def setup_slave(instance, master_dns):
"""
:param instance:
:param master_dns:
:return:
"""
ssh_client = sshclient_from_instance(instance, KEY_PAIR_PATH, user_name='ubuntu')
print("Setup Slave: " + instance.public_dns_name)
common_setup(ssh_client)
if UPDATE_SPARK:
print(" Updating Spark...")
ssh_client.run(
"""cd /usr/local/spark && git pull && build/mvn clean && build/mvn -T 1C -Phive -Pnetlib-lgpl -Pyarn -Phadoop-2.7 -Dhadoop.version=2.7.2 -Dscala-2.11 -DskipTests -Dmaven.test.skip=true package""")
# CLEAN UP EXECUTORS APP LOGS
ssh_client.run("rm -r " + SPARK_HOME + "work/*")
if DISABLE_HT:
# DISABLE HT
ssh_client.put_file("./disable-ht-v2.sh", "./disable-ht-v2.sh")
ssh_client.run("chmod +x disable-ht-v2.sh")
status, stdout, stderr = ssh_client.run('sudo ./disable-ht-v2.sh')
print(" Disabled HyperThreading {}".format(status))
ssh_client.run(
"sed -i '47s/.*/spark.shuffle.service.enabled {0}/' {1}conf/spark-defaults.conf".format(
ENABLE_EXTERNAL_SHUFFLE, SPARK_HOME))
# ssh_client.run('echo "spark.local.dir /mnt/hdfs" >> '+ SPARK_HOME + 'conf/spark-defaults.conf')
ssh_client.run(
"sed -i '31s/.*/spark.memory.offHeap.enabled {0}/' {1}conf/spark-defaults.conf".format(
OFF_HEAP, SPARK_HOME))
ssh_client.run(
"sed -i '32s/.*/spark.memory.offHeap.size {0}/' {1}conf/spark-defaults.conf".format(
OFF_HEAP_BYTES, SPARK_HOME))
ssh_client.run("sed -i '42s/.*/spark.control.k {0}/' {1}conf/spark-defaults.conf".format(
K, SPARK_HOME))
# SAMPLING RATE LINE 43
ssh_client.run("sed -i '43s/.*/spark.control.tsample {0}/' {1}conf/spark-defaults.conf".format(
T_SAMPLE, SPARK_HOME))
ssh_client.run("sed -i '44s/.*/spark.control.ti {0}/' {1}conf/spark-defaults.conf".format(
TI, SPARK_HOME))
ssh_client.run("sed -i '45s{.*{spark.control.corequantum " + str(
CORE_QUANTUM) + "{' " + SPARK_HOME + "conf/spark-defaults.conf")
ssh_client.run("sed -i '50s{.*{spark.control.coremin " + str(
CORE_MIN) + "{' " + SPARK_HOME + "conf/spark-defaults.conf")
ssh_client.run("sed -i '50s{.*{spark.control.cpuperiod " + str(
CPU_PERIOD) + "{' " + SPARK_HOME + "conf/spark-defaults.conf")
if HDFS == 0:
print(" Starting Spark Slave")
ssh_client.run(
'export SPARK_HOME="{s}" && {s}sbin/start-slave.sh {0}:7077 -h {1} --port 9999 -c {2}'.format(
master_dns, instance.public_dns_name, CORE_VM, s=SPARK_HOME))
# REAL CPU LOG
log_cpu_command = 'screen -d -m -S "{0}" bash -c "sar -u 1 > sar-{1}.log"'.format(
instance.private_ip_address, instance.private_ip_address)
print(" Start SAR CPU Logging")
ssh_client.run(log_cpu_command)
@timing
def setup_master(instance):
"""
:param instance:
:return:
"""
ssh_client = sshclient_from_instance(instance, KEY_PAIR_PATH, user_name='ubuntu')
print("Setup Master: " + instance.public_dns_name)
common_setup(ssh_client)
if UPDATE_SPARK_MASTER:
print(" Updating Spark...")
ssh_client.run(
"""cd /usr/local/spark && git pull && build/mvn clean && build/mvn -T 1C -Phive -Pnetlib-lgpl -Pyarn -Phadoop-2.7 -Dhadoop.version=2.7.2 -Dscala-2.11 -DskipTests -Dmaven.test.skip=true package""")
print(" Remove Logs")
ssh_client.run("rm " + SPARK_HOME + "spark-events/*")
# TODO Check number of lines in spark-defaults.conf
# SHUFFLE SERVICE EXTERNAL
ssh_client.run(
"sed -i '31s/.*/spark.shuffle.service.enabled {0}/' {1}conf/spark-defaults.conf".format(
ENABLE_EXTERNAL_SHUFFLE, SPARK_HOME))
# OFF HEAP
ssh_client.run(
"sed -i '32s{.*{spark.memory.offHeap.enabled " + str(
OFF_HEAP) + "{' " + SPARK_HOME + "conf/spark-defaults.conf")
ssh_client.run(
"sed -i '33s{.*{spark.memory.offHeap.size " + str(
OFF_HEAP_BYTES) + "{' " + SPARK_HOME + "conf/spark-defaults.conf")
print(" Changing Benchmark settings")
# DEADLINE LINE 35
ssh_client.run("sed -i '35s{.*{spark.control.deadline " + str(
DEADLINE) + "{' " + SPARK_HOME + "conf/spark-defaults.conf")
# MAX EXECUTOR LINE 39
ssh_client.run("sed -i '39s{.*{spark.control.maxexecutor " + str(
MAX_EXECUTOR) + "{' " + SPARK_HOME + "conf/spark-defaults.conf")
# CORE FOR VM LINE 40
ssh_client.run("sed -i '40s{.*{spark.control.coreforvm " + str(
CORE_VM) + "{' " + SPARK_HOME + "conf/spark-defaults.conf")
# ALPHA LINE 36
ssh_client.run("sed -i '36s{.*{spark.control.alpha " + str(
ALPHA) + "{' " + SPARK_HOME + "conf/spark-defaults.conf")
# OVERSCALE LINE 38
ssh_client.run("sed -i '38s{.*{spark.control.overscale " + str(
OVER_SCALE) + "{' " + SPARK_HOME + "conf/spark-defaults.conf")
# CHANGE ALSO IN MASTER FOR THE LOGS
ssh_client.run(
"sed -i '43s{.*{spark.control.tsample " + str(
T_SAMPLE) + "{' " + SPARK_HOME + "conf/spark-defaults.conf")
ssh_client.run("sed -i '42s{.*{spark.control.k " + str(
K) + "{' " + SPARK_HOME + "conf/spark-defaults.conf")
ssh_client.run("sed -i '44s{.*{spark.control.ti " + str(
TI) + "{' " + SPARK_HOME + "conf/spark-defaults.conf")
ssh_client.run("sed -i '45s{.*{spark.control.corequantum " + str(
CORE_QUANTUM) + "{' " + SPARK_HOME + "conf/spark-defaults.conf")
ssh_client.run(
"sed -i '46s{.*{spark.locality.wait " + str(
LOCALITY_WAIT) + "{' " + SPARK_HOME + "conf/spark-defaults.conf")
ssh_client.run(
"sed -i '51s{.*{spark.locality.wait.node " + str(
LOCALITY_WAIT_NODE) + "{' " + SPARK_HOME + "conf/spark-defaults.conf")
ssh_client.run(
"sed -i '52s{.*{spark.locality.wait.process " + str(
LOCALITY_WAIT_PROCESS) + "{' " + SPARK_HOME + "conf/spark-defaults.conf")
ssh_client.run(
"sed -i '53s{.*{spark.locality.wait.rack " + str(
LOCALITY_WAIT_RACK) + "{' " + SPARK_HOME + "conf/spark-defaults.conf")
ssh_client.run(
"sed -i '47s{.*{spark.task.cpus " + str(
CPU_TASK) + "{' " + SPARK_HOME + "conf/spark-defaults.conf")
ssh_client.run(
"sed -i '48s{.*{spark.control.nominalrate 0.0{' " + SPARK_HOME + "conf/spark-defaults.conf")
ssh_client.run(
"sed -i '49s{.*{spark.control.nominalratedata 0.0{' " + SPARK_HOME + "conf/spark-defaults.conf")
ssh_client.run("sed -i '50s{.*{spark.control.coremin " + str(
CORE_MIN) + "{' " + SPARK_HOME + "conf/spark-defaults.conf")
ssh_client.run(
"sed -i '54s{.*{spark.control.inputrecord " + str(
INPUT_RECORD) + "{' " + SPARK_HOME + "conf/spark-defaults.conf")
ssh_client.run(
"sed -i '55s{.*{spark.control.numtask " + str(
NUM_TASK) + "{' " + SPARK_HOME + "conf/spark-defaults.conf")
ssh_client.run("""sed -i '3s{.*{master=""" + instance.public_dns_name +
"""{' ./spark-bench/conf/env.sh""")
ssh_client.run("""sed -i '63s{.*{NUM_TRIALS=""" + str(BENCH_NUM_TRIALS) +
"""{' ./spark-bench/conf/env.sh""")
# CHANGE MASTER ADDRESS IN BENCHMARK
ssh_client.run("""sed -i '31s{.*{SPARK_CLUSTER_URL = "spark://""" + instance.public_dns_name +
""":7077"{' ./spark-perf/config/config.py""")
# CHANGE SCALE FACTOR LINE 127
ssh_client.run(
"sed -i '127s{.*{SCALE_FACTOR = " + str(SCALE_FACTOR) + "{' ./spark-perf/config/config.py")
# NO PROMPT
ssh_client.run("sed -i '103s{.*{PROMPT_FOR_DELETES = False{' ./spark-perf/config/config.py")
# CHANGE RAM EXEC
ssh_client.run(
"""sed -i '147s{.*{JavaOptionSet("spark.executor.memory", [""" + RAM_EXEC + """]),{' ./spark-perf/config/config.py""")
ssh_client.run(
"""sed -i '55s{.*{SPARK_EXECUTOR_MEMORY=""" + RAM_EXEC + """{' ./spark-bench/conf/env.sh""")
# CHANGE RAM DRIVER
ssh_client.run(
"sed -i '26s{.*{spark.driver.memory " + RAM_DRIVER + "{' " + SPARK_HOME + "conf/spark-defaults.conf")
print(" Enabling/Disabling Benchmark")
# ENABLE BENCHMARK
for bench in BENCHMARK_PERF:
for line_number in BENCH_LINES[bench]:
sed_command_line = "sed -i '" + line_number + " s/[#]//g' ./spark-perf/config/config.py"
ssh_client.run(sed_command_line)
# DISABLE BENCHMARK
for bench in BENCH_LINES:
if bench not in BENCHMARK_PERF:
for line_number in BENCH_LINES[bench]:
ssh_client.run("sed -i '" + line_number + " s/^/#/' ./spark-perf/config/config.py")
# ENABLE HDFS
# if HDFS:
print(" Enabling HDFS in benchmarks")
ssh_client.run("sed -i '180s%memory%hdfs%g' ./spark-perf/config/config.py")
ssh_client.run(
"""sed -i '50s%.*%HDFS_URL = "hdfs://{0}:9000/test/"%' ./spark-perf/config/config.py""".format(
instance.public_dns_name))
if HDFS_MASTER != "":
ssh_client.run(
"""sed -i '50s%.*%HDFS_URL = "hdfs://{0}:9000/test/"%' ./spark-perf/config/config.py""".format(
HDFS_MASTER))
ssh_client.run(
"""sed -i '10s%.*%HDFS_URL="hdfs://{0}:9000"%' ./spark-bench/conf/env.sh""".format(
HDFS_MASTER))
ssh_client.run(
"""sed -i '14s%.*%DATA_HDFS="hdfs://{0}:9000/SparkBench"%' ./spark-bench/conf/env.sh""".format(
HDFS_MASTER))
# START MASTER
if HDFS == 0:
print(" Starting Spark Master")
ssh_client.run(
'export SPARK_HOME="{d}" && {d}sbin/start-master.sh -h {0}'.format(
instance.public_dns_name, d=SPARK_HOME))
return instance.public_dns_name, instance
@timing
def setup_hdfs_ssd(instance):
"""
:param instance:
:return:
"""
ssh_client = sshclient_from_instance(instance, KEY_PAIR_PATH, user_name='ubuntu')
status, out, err = ssh_client.run(
"""test -d /mnt/hdfs/namenode || sudo mkdir --parents /mnt/hdfs/namenode &&
sudo mkdir --parents /mnt/hdfs/datanode""")
if status != 0:
print(out, err)
ssh_client.run("sudo chown ubuntu:hadoop /mnt/hdfs && sudo chown ubuntu:hadoop /mnt/hdfs/*")
if DELETE_HDFS or HDFS_MASTER == "":
ssh_client.run("rm /mnt/hdfs/datanode/current/VERSION")
def rsync_folder(ssh_client, slave):
"""
:param ssh_client:
:param slave:
:return:
"""
ssh_client.run(
"eval `ssh-agent -s` && ssh-add " + DATA_AMI[REGION][
"keypair"] + ".pem && rsync -a " + HADOOP_CONF + " ubuntu@" + slave + ":" + HADOOP_CONF)
if DELETE_HDFS:
ssh_client.run("rm /mnt/hdfs/datanode/current/VERSION")
@timing
def setup_hdfs_config(master_instance, slaves):
"""
:param master_instance:
:param slaves:
:return:
"""
ssh_client = sshclient_from_instance(master_instance, KEY_PAIR_PATH, user_name='ubuntu')
if HDFS_MASTER == "":
master_dns = master_instance.public_dns_name
else:
master_dns = HDFS_MASTER
# Setup Config HDFS
ssh_client.run(
"sed -i '19s%.*%<configuration> <property> <name>fs.default.name</name> <value>hdfs://" + master_dns + ":9000</value> </property>%g' " + HADOOP_CONF + "core-site.xml")
# 19 <configuration> <property> <name>fs.default.name</name> <value>hdfs://ec2-54-70-105-139.us-west-2.compute.amazonaws.com:9000</value> </property>
ssh_client.run(
"sed -i '38s%.*%<value>" + master_dns + ":50070</value>%g' " + HADOOP_CONF + "hdfs-site.xml")
ssh_client.run(
"sed -i '43s%.*%<value>" + master_dns + ":50090</value>%g' " + HADOOP_CONF + "hdfs-site.xml")
ssh_client.run(
"sed -i '48s%.*%<value>" + master_dns + ":9000</value>%g' " + HADOOP_CONF + "hdfs-site.xml")
# 38 <value>ec2-54-70-105-139.us-west-2.compute.amazonaws.com:50070</value>
# 43 <value>ec2-54-70-105-139.us-west-2.compute.amazonaws.com:50090</value>
# 48 <value>ec2-54-70-105-139.us-west-2.compute.amazonaws.com:9000</value>
ssh_client.run(
"sed -i 's%/var/lib/hadoop/hdfs/namenode%/mnt/hdfs/namenode%g' " + HADOOP_CONF + "hdfs-site.xml")
ssh_client.run(
"sed -i 's%/var/lib/hadoop/hdfs/datanode%/mnt/hdfs/datanode%g' " + HADOOP_CONF + "hdfs-site.xml")
print(slaves)
ssh_client.run("echo -e '" + "\n".join(slaves) + "' > " + HADOOP_CONF + "slaves")
ssh_client.run(
"echo 'Host *\n UserKnownHostsFile /dev/null\n StrictHostKeyChecking no' > ~/.ssh/config")
# Rsync Config
with ThreadPoolExecutor(multiprocessing.cpu_count()) as executor:
for slave in slaves:
executor.submit(rsync_folder, ssh_client, slave)
# Start HDFS
if DELETE_HDFS or HDFS_MASTER == "":
ssh_client.run(
"eval `ssh-agent -s` && ssh-add " + DATA_AMI[REGION][
"keypair"] + ".pem && /usr/local/lib/hadoop-2.7.2/sbin/stop-dfs.sh")
ssh_client.run("rm /mnt/hdfs/datanode/current/VERSION")
ssh_client.run("echo 'N' | /usr/local/lib/hadoop-2.7.2/bin/hdfs namenode -format")
status, out, err = ssh_client.run(
"eval `ssh-agent -s` && ssh-add " + DATA_AMI[REGION][
"keypair"] + ".pem && /usr/local/lib/hadoop-2.7.2/sbin/start-dfs.sh && /usr/local/lib/hadoop-2.7.2/bin/hdfs dfsadmin -safemode leave")
if status != 0:
print(out, err)
print(" Started HDFS")
if DELETE_HDFS:
print(" Cleaned HDFS")
if len(BENCHMARK_PERF) > 0:
status, out, err = ssh_client.run(
"/usr/local/lib/hadoop-2.7.2/bin/hadoop fs -rm -R /test/spark-perf-kv-data")
print(status, out, err)
def write_config(output_folder):
"""
:param output_folder:
:return:
"""
with open(output_folder + "/config.json", "w") as config_out:
json.dump(CONFIG_DICT, config_out, sort_keys=True, indent=4)
def check_slave_connected_master(ssh_client):
"""
:param ssh_client:
:return:
"""
pass
@timing
def run_benchmark():
"""
:return:
"""
session = boto3.Session(profile_name=CREDENTIAL_PROFILE)
ec2 = session.resource('ec2', region_name=REGION)
instances = ec2.instances.filter(
Filters=[{'Name': 'instance-state-name', 'Values': ['running']},
{'Name': 'tag:ClusterId', 'Values': [CLUSTER_ID]}])
instance_list = list(instances)
print("Instance Found: " + str(len(instance_list)))
if len(list(instances)) == 0:
print("No instances running")
exit(1)
master_dns, master_instance = setup_master(instance_list[0])
if SPARK_HOME == SPARK_2_HOME:
print("Check Effectively Executor Running")
end_index = min(len(instance_list), MAX_EXECUTOR + 1)
with ThreadPoolExecutor(8) as executor:
for i in instance_list[1:end_index]:
if i.public_dns_name != master_dns:
executor.submit(setup_slave, i, master_dns)
with ThreadPoolExecutor(8) as executor:
for i in instance_list[end_index:]:
if i.public_dns_name != master_dns:
ssh_client = sshclient_from_instance(i, KEY_PAIR_PATH, user_name='ubuntu')
executor.submit(common_setup, ssh_client)
if HDFS or HDFS_MASTER == master_dns:
print("\nStarting Setup of HDFS cluster")
# Format instance store SSD for hdfs usage
with ThreadPoolExecutor(multiprocessing.cpu_count()) as executor:
for i in instances:
executor.submit(setup_hdfs_ssd, i)
slaves = [i.public_dns_name for i in instance_list[:end_index]]
slaves.remove(master_dns)
setup_hdfs_config(master_instance, slaves)
time.sleep(15)
print("MASTER: " + master_dns)
ssh_client = sshclient_from_instance(master_instance, KEY_PAIR_PATH, user_name='ubuntu')
# CHECK IF KEY IN MASTER
status = ssh_client.run('[ ! -e %s ]; echo $?' % (DATA_AMI[REGION]["keypair"] + ".pem"))
if not int(status[1].decode('utf8').replace("\n", "")):
ssh_client.put_file(KEY_PAIR_PATH, "/home/ubuntu/" + DATA_AMI[REGION]["keypair"] + ".pem")
ssh_client.run("chmod 400 "+ "/home/ubuntu/" + DATA_AMI[REGION]["keypair"] + ".pem")
# LANCIARE BENCHMARK
if HDFS == 0:
if len(BENCHMARK_PERF) > 0:
print("Running Benchmark " + str(BENCHMARK_PERF))
runstatus, runout, runerr = ssh_client.run(
'export SPARK_HOME="' + SPARK_HOME + '" && ./spark-perf/bin/run')
# FIND APP LOG FOLDER
print("Finding log folder")
app_log = between(runout, b"2>> ", b".err").decode(encoding='UTF-8')
logfolder = "./" + "/".join(app_log.split("/")[:-1])
print(logfolder)
output_folder = logfolder
for bench in BENCHMARK_BENCH:
ssh_client.run('rm -r ./spark-bench/num/*')
for config in BENCH_CONF[bench]:
if config != "NumTrials":
ssh_client.run(
"sed -i '{0}s/.*/{1}={2}/' ./spark-bench/{3}/conf/env.sh""".format(
BENCH_CONF[bench][config][0], config, BENCH_CONF[bench][config][1],
bench))
if DELETE_HDFS:
print("Generating Data Benchmark " + bench)
ssh_client.run(
'eval `ssh-agent -s` && ssh-add ' + DATA_AMI[REGION][
"keypair"] + '.pem && export SPARK_HOME="' + SPARK_HOME + '" && ./spark-bench/' + bench + '/bin/gen_data.sh')
check_slave_connected_master(ssh_client)
print("Running Benchmark " + bench)
ssh_client.run(
'eval `ssh-agent -s` && ssh-add ' + DATA_AMI[REGION][
"keypair"] + '.pem && export SPARK_HOME="' + SPARK_HOME + '" && ./spark-bench/' + bench + '/bin/run.sh')
logfolder = "./spark-bench/num"
output_folder = "./spark-bench/num/"
# DOWNLOAD LOGS
output_folder = log.download(logfolder, [i for i in instance_list[:end_index]], master_dns,
output_folder, CONFIG_DICT)
write_config(output_folder)
# PLOT LOGS
plot.plot(output_folder + "/")
# COMPUTE METRICS
metrics.compute_metrics(output_folder + "/")
print("\nCHECK VALUE OF SCALE FACTOR AND PREV SCALE FACTOR FOR HDFS CASE")