-
Notifications
You must be signed in to change notification settings - Fork 3
/
run.py
1322 lines (1125 loc) · 72.2 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
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""
This module handles 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
from ast import literal_eval
import log
from spark_log_profiling import processing
import metrics
import plot
import pickle
import os
import shutil
#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, BETA, 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, HADOOP_HOME,\
# SPARK_2_HOME, BENCHMARK_BENCH, BENCH_CONF, LOG_LEVEL, CORE_ALLOCATION, DEADLINE_ALLOCATION,\
# UPDATE_SPARK_BENCH, UPDATE_SPARK_PERF, SPARK_PERF_FOLDER, NUM_INSTANCE, STAGE_ALLOCATION, HEURISTIC, VAR_PAR_MAP, \
# PROCESS_ON_SERVER, INSTALL_PYTHON3, AZ_PUB_KEY_PATH, RUN, PREV_SCALE_FACTOR
#from config import PRIVATE_KEY_PATH, PRIVATE_KEY_NAME, TEMPORARY_STORAGE, PROVIDER, INSTANCE_TYPE, PRICE
#import config as c
#from configure import config_instance
from configure import config_instance as c
from util.utils import timing, between, get_cfg, write_cfg, open_cfg, make_sure_path_exists
from util.ssh_client import sshclient_from_node, sshclient_from_ip
from pathlib import Path
import socket #vboxvm
import pprint
pp = pprint.PrettyPrinter(indent=4)
# Modifiche fatte
# - uso di PRIVATE_KEY_PATH anzichè KEY_PAIR_PATH
# - uso di PRIVATE_KEY_NAME anzichè DATA_AMI[REGION]["keypair"]+".pem"
# - uso di TEMPORARY_STORAGE anzichè "/dev/xvdb"
# - uso di ssh_sshclient_from_node per ottenere un client ssh basato su ParamikoSSHClient
# - uso di ip privati in azure, altrimenti fallisce il binding sulle porte di hadoop
def get_ip(node):
if c.PROVIDER == "AWS_SPOT":
return node.extra['dns_name']
if c.PROVIDER == "AZURE":
return node.private_ips[0]
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
"""
with open_cfg() as cfg:
delete_hdfs = cfg.getboolean('main', 'delete_hdfs')
# preliminary steps required due to differences between azure and aws
if c.PROVIDER == "AZURE":
# todo only if first run
if c.NUM_INSTANCE > 0:
print("In common_setup, NUM_INSTANCE=" + str(c.NUM_INSTANCE))
# add ssh key that matches the public one used during creation
if not "id_rsa" in ssh_client.listdir("/home/ubuntu/.ssh/"):
ssh_client.put(localpath=c.PRIVATE_KEY_PATH, remotepath="/home/ubuntu/.ssh/id_rsa")
ssh_client.run("chmod 400 /home/ubuntu/.ssh/id_rsa")
# ssh_client.run("sudo groupadd supergroup")
ssh_client.run("sudo usermod -aG supergroup $USER")
ssh_client.run("sudo usermod -aG supergroup root")
# join docker group
ssh_client.run("sudo usermod -aG docker $USER")
# ssh_client.run("mkdir /usr/local/spark/spark-events")
# ssh_client.run("sudo chmod -R 777 /mnt")
# to refresh groups
ssh_client.close()
ssh_client.connect()
# restore environmental variables lost when creating the image
ssh_client.run("echo 'export JAVA_HOME=/usr/lib/jvm/java-8-oracle' >> $HOME/.bashrc")
ssh_client.run("echo 'export HADOOP_INSTALL=/usr/local/lib/hadoop-2.7.2' >> $HOME/.bashrc")
ssh_client.run("echo 'export PATH=$PATH:$HADOOP_INSTALL/bin' >> $HOME/.bashrc")
ssh_client.run("echo 'export PATH=$PATH:$HADOOP_INSTALL/sbin' >> $HOME/.bashrc")
ssh_client.run("echo 'export HADOOP_MAPRED_HOME=$HADOOP_INSTALL' >> $HOME/.bashrc")
ssh_client.run("echo 'export HADOOP_COMMON_HOME=$HADOOP_INSTALL' >> $HOME/.bashrc")
ssh_client.run("echo 'export HADOOP_HDFS_HOME=$HADOOP_INSTALL' >> $HOME/.bashrc")
ssh_client.run("echo 'export HADOOP_HOME=$HADOOP_INSTALL' >> $HOME/.bashrc")
ssh_client.run("echo 'export YARN_HOME=$HADOOP_INSTALL' >> $HOME/.bashrc")
ssh_client.run("echo 'export HADOOP_COMMON_LIB_NATIVE_DIR=$HADOOP_INSTALL/lib/native/' >> $HOME/.bashrc")
ssh_client.run("echo 'export HADOOP_OPTS=\"-Djava.library.path=$HADOOP_INSTALL/lib/native\"' >> $HOME/.bashrc")
ssh_client.run(
"echo 'export LD_LIBRARY_PATH=$HADOOP_INSTALL/lib/native:$LD_LIBRARY_PATH' >> $HOME/.bashrc") # to fix "unable to load native hadoop lib" in spark
ssh_client.run("source $HOME/.bashrc")
# # PageRank
# ssh_client.run("rm /usr/local/spark/conf/Spark_PageRank_Application.json")
# ssh_client.put(localpath="C:\\workspace\\spark-log-profiling\\output_json\\Spark_PageRank_Application_20170523133037.json",
# remotepath="/usr/local/spark/conf/Spark_PageRank_Application.json")
#
#
# # DecisionTree
# ssh_client.run("rm /usr/local/spark/conf/DecisionTree_classification_Example.json")
# ssh_client.put(
# localpath="C:\\workspace\\spark-log-profiling\\output_json\\DecisionTree_classification_Example_20170523134646.json",
# remotepath="/usr/local/spark/conf/DecisionTree_classification_Example.json")
#
# # Kmeans
# ssh_client.run("rm /usr/local/spark/conf/Spark_KMeans_Example.json")
# ssh_client.put(localpath="C:\\workspace\\spark-log-profiling\\output_json\\Spark_KMeans_Example_20170509081738.json",
# remotepath="/usr/local/spark/conf/Spark_KMeans_Example.json")
#
# # SVM
# ssh_client.run("rm /usr/local/spark/conf/SVM_Classifier_Example.json")
# ssh_client.put(localpath="C:\\workspace\\spark-log-profiling\\output_json\\SVM_Classifier_Example_20170509105715.json",
# remotepath="/usr/local/spark/conf/SVM_Classifier_Example.json")
#
# # Agg by key
# ssh_client.run("rm /usr/local/spark/conf/TestRunner__aggregate-by-key.json")
# ssh_client.put(
# localpath="C:\\workspace\\spark-log-profiling\\output_json\\TestRunner__aggregate-by-key_20170511110351.json",
# remotepath="/usr/local/spark/conf/TestRunner__aggregate-by-key.json")
#
# # Agg by key int
# ssh_client.run("rm /usr/local/spark/conf/TestRunner__aggregate-by-key-int.json")
# ssh_client.put(
# localpath="C:\\workspace\\spark-log-profiling\\output_json\\TestRunner__aggregate-by-key-int_20170511112110.json",
# remotepath="/usr/local/spark/conf/TestRunner__aggregate-by-key-int.json")
#
# # Agg by key naive
# ssh_client.run("rm /usr/local/spark/conf/TestRunner__aggregate-by-key-naive.json")
# ssh_client.put(
# localpath="C:\\workspace\\spark-log-profiling\\output_json\\TestRunner__aggregate-by-key-naive_20170511114259.json",
# remotepath="/usr/local/spark/conf/TestRunner__aggregate-by-key-naive.json")
#
# # Sort by key
# ssh_client.run("rm /usr/local/spark/conf/TestRunner__sort-by-key.json")
# ssh_client.put(
# localpath="C:\\workspace\\spark-log-profiling\\output_json\\TestRunner__sort-by-key_20170511131321.json",
# remotepath="/usr/local/spark/conf/TestRunner__sort-by-key.json")
#
# # Sort by key int
# ssh_client.run("rm /usr/local/spark/conf/TestRunner__sort-by-key-int.json")
# ssh_client.put(
# localpath="C:\\workspace\\spark-log-profiling\\output_json\\TestRunner__sort-by-key-int_20170511133334.json",
# remotepath="/usr/local/spark/conf/TestRunner__sort-by-key-int.json")
#
# # Count
# ssh_client.run("rm /usr/local/spark/conf/TestRunner__count.json")
# ssh_client.put(
# localpath="C:\\workspace\\spark-log-profiling\\output_json\\TestRunner__count_20170511135036.json",
# remotepath="/usr/local/spark/conf/TestRunner__count.json")
#
# # Count with filtr
# ssh_client.run("rm /usr/local/spark/conf/TestRunner__count-with-filter.json")
# ssh_client.put(
# localpath="C:\\workspace\\spark-log-profiling\\output_json\\TestRunner__count-with-filter_20170511140627.json",
# remotepath="/usr/local/spark/conf/TestRunner__count-with-filter.json")
if c.PROVIDER == "AWS_SPOT":
ssh_client.run("echo 'export JAVA_HOME=/usr/lib/jvm/java-8-oracle' >> $HOME/.bashrc")
ssh_client.run("echo 'export HADOOP_INSTALL=/usr/local/lib/hadoop-2.7.2' >> $HOME/.bashrc")
ssh_client.run("echo 'export PATH=$PATH:$HADOOP_INSTALL/bin' >> $HOME/.bashrc")
ssh_client.run("echo 'export PATH=$PATH:$HADOOP_INSTALL/sbin' >> $HOME/.bashrc")
ssh_client.run("echo 'export HADOOP_MAPRED_HOME=$HADOOP_INSTALL' >> $HOME/.bashrc")
ssh_client.run("echo 'export HADOOP_COMMON_HOME=$HADOOP_INSTALL' >> $HOME/.bashrc")
ssh_client.run("echo 'export HADOOP_HDFS_HOME=$HADOOP_INSTALL' >> $HOME/.bashrc")
ssh_client.run("echo 'export HADOOP_HOME=$HADOOP_INSTALL' >> $HOME/.bashrc")
ssh_client.run("echo 'export YARN_HOME=$HADOOP_INSTALL' >> $HOME/.bashrc")
ssh_client.run("echo 'export HADOOP_COMMON_LIB_NATIVE_DIR=$HADOOP_INSTALL/lib/native' >> $HOME/.bashrc")
ssh_client.run("echo 'export HADOOP_OPTS=\"-Djava.library.path=$HADOOP_INSTALL/lib/native\"' >> $HOME/.bashrc")
ssh_client.run(
"echo 'export LD_LIBRARY_PATH=$HADOOP_INSTALL/lib/native:$LD_LIBRARY_PATH' >> $HOME/.bashrc") # to fix "unable to load native hadoop lib" in spark
ssh_client.run("source $HOME/.bashrc")
ssh_client.run("export GOMAXPROCS=`nproc`")
if c.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 " + c.TEMPORARY_STORAGE + " && sudo mount -o discard " + c.TEMPORARY_STORAGE + " /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=c.SPARK_HOME))
ssh_client.run('export SPARK_HOME="{s}" && {s}sbin/stop-master.sh'.format(s=c.SPARK_HOME))
ssh_client.run('export SPARK_HOME="{s}" && sudo {s}sbin/stop-slave.sh'.format(s=c.SPARK_HOME))
print(" Set Log Level")
ssh_client.run(
"sed -i '19s/.*/log4j.rootCategory={}, console /' {}conf/log4j.properties".format(c.LOG_LEVEL,
c.SPARK_HOME))
if c.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 c.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(node, master_ip, count):
"""
:param node:
:param master_ip:
:return:
"""
cfg = get_cfg()
current_cluster = cfg['main']['current_cluster']
ssh_client = sshclient_from_node(node, ssh_key_file=c.PRIVATE_KEY_PATH, user_name='ubuntu')
print("Setup Slave: PublicIp=" + node.public_ips[0] + " PrivateIp=" + node.private_ips[0])
slave_ip = get_ip(node)
#cfg[current_cluster]['slave'+count+'_ip'] = slave_ip
#write_cfg(cfg)
common_setup(ssh_client)
if c.UPDATE_SPARK:
print(" Updating Spark...")
stdout, stderr, status = ssh_client.run(
"""cd /usr/local/spark && git pull && git checkout """ + c.GIT_BRANCH)
print(stdout + stderr)
# CLEAN UP EXECUTORS APP LOGS
ssh_client.run("sudo rm -r " + c.SPARK_HOME + "work/*")
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""")
'''
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 " + c.SPARK_HOME + "work/*")
ssh_client.run("sudo rm -r " + c.SPARK_HOME + "work/*")
if c.DISABLE_HT:
# DISABLE HT
ssh_client.put(localpath="./disable-ht-v2.sh", remotepath="$HOME/disable-ht-v2.sh")
ssh_client.run("chmod +x $HOME/disable-ht-v2.sh")
stdout, stderr, status = ssh_client.run('sudo $HOME/disable-ht-v2.sh')
print(" Disabled HyperThreading {}".format(status))
if current_cluster == 'spark':
# check that line numbers to be substituted are present in file spark-defaults.conf and if not, add 11 empty comment lines
stdout, stderr, status = ssh_client.run(
"if [ $(wc -l /usr/local/spark/conf/spark-defaults.conf | awk '{ print $1 }') -lt 60 ]; \
then echo -e '#\n#\n#\n#\n#\n#\n#\n#\n#\n#\n#\n' >> /usr/local/spark/conf/spark-defaults.conf; fi")
# Modificato questo
stdout, stderr, status = ssh_client.run(
"sed -i '31s/.*/spark.shuffle.service.enabled {0}/' {1}conf/spark-defaults.conf".format(
c.ENABLE_EXTERNAL_SHUFFLE, c.SPARK_HOME))
print("setup_slave, spark-defaults.conf 31: " + stdout + stderr)
# ssh_client.run('echo "spark.local.dir /mnt/hdfs" >> '+ c.SPARK_HOME + 'conf/spark-defaults.conf')
stdout, stderr, status = ssh_client.run(
"sed -i '32s/.*/spark.memory.offHeap.enabled {0}/' {1}conf/spark-defaults.conf".format(
c.OFF_HEAP, c.SPARK_HOME))
print("setup_slave, spark-defaults.conf 32: " + stdout + stderr)
stdout, stderr, status = ssh_client.run(
"sed -i '33s/.*/spark.memory.offHeap.size {0}/' {1}conf/spark-defaults.conf".format(
c.OFF_HEAP_BYTES, c.SPARK_HOME))
print("setup_slave, spark-defaults.conf 33: " + stdout + stderr)
stdout, stderr, status = ssh_client.run("sed -i '42s/.*/spark.control.k {0}/' {1}conf/spark-defaults.conf".format(
c.K , c.SPARK_HOME))
print("setup_slave, spark-defaults.conf 42: " + stdout + stderr)
# SAMPLING RATE LINE 43
stdout, stderr, status = ssh_client.run("sed -i '43s/.*/spark.control.tsample {0}/' {1}conf/spark-defaults.conf".format(
c.T_SAMPLE, c.SPARK_HOME))
print("setup_slave, spark-defaults.conf 43: " + stdout + stderr)
try:
stdout, stderr, status = ssh_client.run("sed -i '44s/.*/spark.control.ti {0}/' {1}conf/spark-defaults.conf".format(
c.TI, c.SPARK_HOME))
print("setup_slave, spark-defaults.conf 44: " + stdout + stderr)
stdout, stderr, status = ssh_client.run("sed -i '45s{.*{spark.control.corequantum " + str(
c.CORE_QUANTUM) + "{' " + c.SPARK_HOME + "conf/spark-defaults.conf")
print("setup_slave, spark-defaults.conf 45: " + stdout + stderr)
stdout, stderr, status = ssh_client.run("sed -i '50s{.*{spark.control.coremin " + str(
c.CORE_MIN) + "{' " + c.SPARK_HOME + "conf/spark-defaults.conf")
print("setup_slave, spark-defaults.conf 50 c.CORE_MIN: " + stdout + stderr)
stdout, stderr, status = ssh_client.run("sed -i '41s{.*{spark.control.cpuperiod " + str(
c.CPU_PERIOD) + "{' " + c.SPARK_HOME + "conf/spark-defaults.conf")
print("setup_slave, spark-defaults.conf 41: ", stdout + stderr)
except Exception as exc:
print("ERROREEE", exc)
if current_cluster == 'spark':
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(
'export SPARK_HOME="{s}" && sudo {s}sbin/start-slave.sh {0}:7077 -h {1} --port 9999 -c {2}'.format(
master_ip, slave_ip, c.CORE_VM, s=c.SPARK_HOME))
# REAL CPU LOG
log_cpu_command = 'screen -d -m -S "{0}" bash -c "sar -u 1 > sar-{1}.log"'.format(
slave_ip, slave_ip)
print(" Start SAR CPU Logging")
ssh_client.run(log_cpu_command)
@timing
def setup_master(node, slaves_ip, hdfs_master):
"""
:param node:
:return:
"""
ssh_client = sshclient_from_node(node, ssh_key_file=c.PRIVATE_KEY_PATH, user_name='ubuntu') #vboxvm_removed
#master_public_ip = socket.gethostbyname("XSPARKWORK0") #vboxvm
#ssh_client = sshclient_from_ip(master_public_ip, c.PRIVATE_KEY_PATH, user_name='ubuntu') #vboxvm
stdout, stderr, status = ssh_client.run("hostname && pwd") #vboxvm
print(stdout) #vboxvm
with open_cfg(mode='w') as cfg:
current_cluster = cfg['main']['current_cluster']
benchmark = c.CONFIG_DICT['Benchmark']['Name']
#benchmark = cfg['main']['benchmark'] if 'main' in cfg and 'benchmark' in cfg['main'] else \
# cfg['experiment']['benchmarkname'] if 'experiment' in cfg and 'benchmarkname' in cfg['experiment'] else ''
cfg[current_cluster] = {}
# TODO check if needed
# input_record = cfg['pagerank']['num_v'] if 'pagerank' in cfg and 'num_v' in cfg['pagerank'] else c.INPUT_RECORD
# print("input_record: {}".format(input_record))
print("Setup Master: BENCH_CONF=" + str(c.BENCH_CONF[benchmark]))
#master_private_ip = master_public_ip #vboxvm
#print("Setup Master: PublicIp=" + master_public_ip + " PrivateIp=" + master_private_ip) #vboxvm
print("Setup Master: PublicIp=" + node.public_ips[0] + " PrivateIp=" + node.private_ips[0]) #vboxvm_removed
master_private_ip = get_ip(node) #vboxvm_removed
master_public_ip = node.public_ips[0] #vboxvm_removed
# save private master_ip to cfg file
print('saving master ip')
cfg[current_cluster]['master_private_ip'] = master_private_ip
cfg[current_cluster]['master_public_ip'] = master_public_ip
common_setup(ssh_client) #vboxvm_removed
# update spark-bench and spark-perf
ssh_client.run("sudo mv /usr/local/spark-perf/ /home/ubuntu/")
ssh_client.run("sudo mv /usr/local/spark-bench/ /home/ubuntu/")
ssh_client.run("sudo mv /usr/local/wikixmlj/ /home/ubuntu/")
files = ssh_client.listdir("/home/ubuntu/")
# download or update
if c.UPDATE_SPARK_PERF:
if "wikixmlj" in files:
ssh_client.run("""cd $HOME/wikixmlj && git status | grep "up-to-date" || eval `git pull && mvn package install`""")
ssh_client.run("cd $HOME")
else:
ssh_client.run("git clone https://github.com/synhershko/wikixmlj.git wikixmlj")
ssh_client.run(
"cd $HOME/wikixmlj && mvn package install -Dmaven.test.skip=true && cd $HOME") # install wikixmlj
if "spark-perf" in files:
ssh_client.run("""cd $HOME/spark-perf && git status | grep "up-to-date" || eval `git pull && cp $HOME/spark-perf/config/config.py.template $HOME/spark-perf/config/config.py`""")
ssh_client.run("cd $HOME")
else:
ssh_client.run("git clone https://github.com/databricks/spark-perf.git spark-perf")
ssh_client.run(
"cp $HOME/spark-perf/config/config.py.template $HOME/spark-perf/config/config.py")
elif c.SKEW_TEST:
print("Removing default sparf-perf")
stdout, stderr, status = ssh_client.run("sudo rm -r ./spark-perf")
print(stdout, stderr)
print("Cloning master branch from https://github.com/gioenn/spark-perf.git")
stdout, stderr, status = ssh_client.run("git clone -b master --single-branch https://github.com/gioenn/spark-perf.git")
#print("Cloning master branch from https://github.com/DavideB/spark-perf.git")
#stdout, stderr, status = ssh_client.run("git clone -b master --single-branch https://github.com/DavideB/spark-perf.git")
#stdout, stderr, status = ssh_client.run("git clone -b log_skew --single-branch https://github.com/DavideB/spark-perf.git")
print(stdout, stderr)
'''
stdout, stderr, status = ssh_client.run(
"cp $HOME/spark-perf/config/config.py.template $HOME/spark-perf/config/config.py")
print(stdout, stderr)
stdout, stderr, status = ssh_client.run(
"cd $HOME/spark-perf/config && sed -i '134,137d' config.py")
print(stdout, stderr)
'''
if c.UPDATE_SPARK_BENCH:
if "spark-bench" in files:
ssh_client.run("""cd $HOME/spark-bench && git status | grep "up-to-date" || eval `git pull && sed -i '7s{.*{mvn package -P spark2.0{' $HOME/spark-bench/bin/build-all.sh && $HOME/spark-bench/bin/build-all.sh && cp $HOME/spark-bench/conf/env.sh.template $HOME/spark-bench/conf/env.sh`""")
ssh_client.run("cd $HOME")
else:
ssh_client.run("git clone https://github.com/gioenn/spark-bench.git spark-bench")
ssh_client.run("$HOME/spark-bench/bin/build-all.sh") # build spark-bench
ssh_client.run("cp $HOME/spark-bench/conf/env.sh.template $HOME/spark-bench/conf/env.sh") # copy spark-bench config
# ssh_client.run("cd $HOME/wikixmlj && mvn package install -Dmaven.test.skip=true && cd $HOME") # install wikixmlj
# ssh_client.run("sed -i '7s{.*{mvn package -P spark2.0{' $HOME/spark-bench/bin/build-all.sh")
# ssh_client.run("$HOME/spark-bench/bin/build-all.sh") # build spark-bench
# ssh_client.run("cp $HOME/spark-bench/conf/env.sh.template $HOME/spark-bench/conf/env.sh") # copy spark-bench config
# ssh_client.run(
# "cp $HOME/spark-perf/config/config.py.template $HOME/spark-perf/config/config.py") # copy spark-perf config
# copia chiave privata
if not c.PRIVATE_KEY_NAME in files:
ssh_client.put(localpath=c.PRIVATE_KEY_PATH, remotepath="/home/ubuntu/" + c.PRIVATE_KEY_NAME)
ssh_client.run("chmod 400 " + "$HOME/" + c.PRIVATE_KEY_NAME)
if c.UPDATE_SPARK_MASTER:
print(" Updating Spark...")
stdout, stderr, status = ssh_client.run(
"""cd /usr/local/spark && git pull && git checkout """ + c.GIT_BRANCH)
print(stdout + stderr)
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""")
'''
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 " + c.SPARK_HOME + "spark-events/*")
ssh_client.run("sudo rm " + c.SPARK_HOME + "spark-events/*")
# TODO Check number of lines in spark-defaults.conf
# check that line numbers to be substituted are present in file spark-defaults.conf and if not, add 11 empty comment lines
stdout, stderr, status = ssh_client.run(
"if [ $(wc -l /usr/local/spark/conf/spark-defaults.conf | awk '{ print $1 }') -le 60 ]; \
then echo -e '#\n#\n#\n#\n#\n#\n#\n#\n#\n#\n#\n' >> /usr/local/spark/conf/spark-defaults.conf; fi")
# SHUFFLE SERVICE EXTERNAL
stdout, stderr, status = ssh_client.run(
"sed -i '31s/.*/spark.shuffle.service.enabled {0}/' {1}conf/spark-defaults.conf".format(
c.ENABLE_EXTERNAL_SHUFFLE, c.SPARK_HOME))
print("setup_master, spark-defaults.conf 31: " + stdout + stderr)
if current_cluster == 'spark':
'''
#if benchmark == 'sort_by_key':
if benchmark == 'scala-sort-by-key':
c.BENCH_CONF['scala-sort-by-key']['ScaleFactor'] = literal_eval(cfg['sort_by_key']['scale_factor'])[1]
print('setting ScaleFactor as {}'.format(c.BENCH_CONF['scala-sort-by-key']['ScaleFactor']))
c.BENCH_CONF['scala-sort-by-key']['num-partitions'] = cfg['sort_by_key']['num_partitions']
print('setting num-partitions as {}'.format(c.BENCH_CONF['scala-sort-by-key']['num-partitions']))
c.SCALE_FACTOR = c.BENCH_CONF[c.BENCHMARK_PERF[0]]["ScaleFactor"]
c.INPUT_RECORD = 200 * 1000 * 1000 * c.SCALE_FACTOR
c.NUM_TASK = c.SCALE_FACTOR
'''
# OFF HEAP
stdout, stderr, status = ssh_client.run(
"sed -i '32s{.*{spark.memory.offHeap.enabled " + str(
c.OFF_HEAP) + "{' " + c.SPARK_HOME + "conf/spark-defaults.conf")
print("setup_master, spark-defaults.conf 32: " + stdout + stderr)
stdout, stderr, status = ssh_client.run(
"sed -i '33s{.*{spark.memory.offHeap.size " + str(
c.OFF_HEAP_BYTES) + "{' " + c.SPARK_HOME + "conf/spark-defaults.conf")
print("setup_master, spark-defaults.conf 33: " + stdout + stderr)
print(" Changing Benchmark settings")
# DEADLINE LINE 35
stdout, stderr, status = ssh_client.run("sed -i '35s{.*{spark.control.deadline " + str(
c.DEADLINE) + "{' " + c.SPARK_HOME + "conf/spark-defaults.conf")
print("setup_master, spark-defaults.conf 35: " + stdout + stderr)
#print("MAX_EXECUTOR in setup_master: " + str(c.MAX_EXECUTOR))
# MAX EXECUTOR LINE 39
stdout, stderr, status = ssh_client.run("sed -i '39s{.*{spark.control.maxexecutor " + str(
c.MAX_EXECUTOR) + "{' " + c.SPARK_HOME + "conf/spark-defaults.conf")
print("setup_master, spark-defaults.conf 39: " + stdout + stderr)
# CORE FOR VM LINE 40
stdout, stderr, status = ssh_client.run("sed -i '40s{.*{spark.control.coreforvm " + str(
c.CORE_VM) + "{' " + c.SPARK_HOME + "conf/spark-defaults.conf")
print("setup_master, spark-defaults.conf 40: " + stdout + stderr)
# ALPHA LINE 36
stdout, stderr, status = ssh_client.run("sed -i '36s{.*{spark.control.alpha " + str(
c.ALPHA) + "{' " + c.SPARK_HOME + "conf/spark-defaults.conf")
print("setup_master, spark-defaults.conf 40: " + stdout + stderr)
# BETA line 37
stdout, stderr, status = ssh_client.run("sed -i '37s{.*{spark.control.beta " + str(
c.BETA) + "{' " + c.SPARK_HOME + "conf/spark-defaults.conf")
print("setup_master, spark-defaults.conf 37: " + stdout + stderr)
# OVERSCALE LINE 38
stdout, stderr, status = ssh_client.run("sed -i '38s{.*{spark.control.overscale " + str(
c.OVER_SCALE) + "{' " + c.SPARK_HOME + "conf/spark-defaults.conf")
print("setup_master, spark-defaults.conf 38: " + stdout + stderr)
# HEURISTIC TYPE LINE 56
stdout, stderr, status = ssh_client.run("sed -i '56s{.*{spark.control.heuristic " + str(
c.HEURISTIC.value) + "{' " + c.SPARK_HOME + "conf/spark-defaults.conf")
print("setup_master, spark-defaults.conf 56 c.SPARK_HOME str(c.HEURISTIC.value): " + c.SPARK_HOME + str(c.HEURISTIC.value) + stdout + stderr)
# CORE_ALLOCATION
if c.CORE_ALLOCATION != None and c.DEADLINE_ALLOCATION != None and c.STAGE_ALLOCATION != None:
stdout, stderr, status = ssh_client.run("sed -i '57s{.*{spark.control.stage " + str(c.STAGE_ALLOCATION) + "{' "+c.SPARK_HOME+"conf/spark-defaults.conf")
print("setup_master, spark-defaults.conf 56 str(c.STAGE_ALLOCATION): " + str(c.STAGE_ALLOCATION) + stdout + stderr)
stdout, stderr, status = ssh_client.run("sed -i '58s{.*{spark.control.stagecores "+ str(c.CORE_ALLOCATION) +"{' "+c.SPARK_HOME + "conf/spark-defaults.conf")
print("setup_master, spark-defaults.conf 58 str(c.CORE_ALLOCATION): " + str(c.CORE_ALLOCATION) + stdout + stderr)
stdout, stderr, status = ssh_client.run("sed -i '59s{.*{spark.control.stagedeadlines " + str(
c.DEADLINE_ALLOCATION) + "{' " + c.SPARK_HOME + "conf/spark-defaults.conf")
print("setup_master, spark-defaults.conf 59 str(c.DEADLINE_ALLOCATION): " + str(c.DEADLINE_ALLOCATION) + stdout + stderr)
else:
stdout, stderr, status = ssh_client.run("sed -i '57s{.*{#stage{' " + c.SPARK_HOME + "conf/spark-defaults.conf")
print("setup_master, spark-defaults.conf 57 c.SPARK_HOME: " + c.SPARK_HOME + stdout + stderr)
stdout, stderr, status = ssh_client.run("sed -i '58s{.*{#stagecores{' "+c.SPARK_HOME + "conf/spark-defaults.conf")
print("setup_master, spark-defaults.conf 58 c.SPARK_HOME: " + c.SPARK_HOME + stdout + stderr)
stdout, stderr, status = ssh_client.run("sed -i '59s{.*{#stagedeadlines{' " + c.SPARK_HOME + "conf/spark-defaults.conf")
print("setup_master, spark-defaults.conf 59 c.SPARK_HOME: " + c.SPARK_HOME + stdout + stderr)
# CHANGE ALSO IN MASTER FOR THE LOGS
stdout, stderr, status = ssh_client.run(
"sed -i '43s{.*{spark.control.tsample " + str(
c.T_SAMPLE) + "{' " + c.SPARK_HOME + "conf/spark-defaults.conf")
print("setup_master, spark-defaults.conf 43: " + stdout + stderr)
stdout, stderr, status = ssh_client.run("sed -i '42s{.*{spark.control.k " + str(
c.K ) + "{' " + c.SPARK_HOME + "conf/spark-defaults.conf")
print("setup_master, spark-defaults.conf 42: " + stdout + stderr)
stdout, stderr, status = ssh_client.run("sed -i '44s{.*{spark.control.ti " + str(
c.TI) + "{' " + c.SPARK_HOME + "conf/spark-defaults.conf")
print("setup_master, spark-defaults.conf 44: " + stdout + stderr)
stdout, stderr, status = ssh_client.run("sed -i '45s{.*{spark.control.corequantum " + str(
c.CORE_QUANTUM) + "{' " + c.SPARK_HOME + "conf/spark-defaults.conf")
print("setup_master, spark-defaults.conf 45: " + stdout + stderr)
stdout, stderr, status = ssh_client.run(
"sed -i '46s{.*{spark.locality.wait " + str(
c.LOCALITY_WAIT) + "{' " + c.SPARK_HOME + "conf/spark-defaults.conf")
print("setup_master, spark-defaults.conf 46: " + stdout + stderr)
stdout, stderr, status = ssh_client.run(
"sed -i '51s{.*{spark.locality.wait.node " + str(
c.LOCALITY_WAIT_NODE) + "{' " + c.SPARK_HOME + "conf/spark-defaults.conf")
print("setup_master, spark-defaults.conf 51 str(c.LOCALITY_WAIT_NODE): " + str(c.LOCALITY_WAIT_NODE) + stdout + stderr)
stdout, stderr, status = ssh_client.run(
"sed -i '52s{.*{spark.locality.wait.process " + str(
c.LOCALITY_WAIT_PROCESS) + "{' " + c.SPARK_HOME + "conf/spark-defaults.conf")
print("setup_master, spark-defaults.conf 52: str(c.LOCALITY_WAIT_PROCESS)" + str(c.LOCALITY_WAIT_PROCESS) + stdout + stderr)
stdout, stderr, status = ssh_client.run(
"sed -i '53s{.*{spark.locality.wait.rack " + str(
c.LOCALITY_WAIT_RACK) + "{' " + c.SPARK_HOME + "conf/spark-defaults.conf")
print("setup_master, spark-defaults.conf 53: str(c.LOCALITY_WAIT_RACK)" + str(c.LOCALITY_WAIT_RACK) + stdout + stderr)
stdout, stderr, status = ssh_client.run(
"sed -i '47s{.*{spark.task.cpus " + str(
c.CPU_TASK) + "{' " + c.SPARK_HOME + "conf/spark-defaults.conf")
print("setup_master, spark-defaults.conf 47: " + stdout + stderr)
stdout, stderr, status = ssh_client.run(
"sed -i '48s{.*{spark.control.nominalrate 0.0{' " + c.SPARK_HOME + "conf/spark-defaults.conf")
print("setup_master, spark-defaults.conf 48: " + stdout + stderr)
stdout, stderr, status = ssh_client.run(
"sed -i '49s{.*{spark.control.nominalratedata 0.0{' " + c.SPARK_HOME + "conf/spark-defaults.conf")
print("setup_master, spark-defaults.conf 49: " + stdout + stderr)
stdout, stderr, status = ssh_client.run("sed -i '50s{.*{spark.control.coremin " + str(
c.CORE_MIN) + "{' " + c.SPARK_HOME + "conf/spark-defaults.conf")
print("setup_master, spark-defaults.conf 50: " + stdout + stderr)
stdout, stderr, status = ssh_client.run(
"sed -i '54s{.*{spark.control.inputrecord " + str(
c.INPUT_RECORD) + "{' " + c.SPARK_HOME + "conf/spark-defaults.conf")
print("setup_master, spark-defaults.conf 54: " + stdout + stderr)
stdout, stderr, status = ssh_client.run(
"sed -i '55s{.*{spark.control.numtask " + str(
c.NUM_TASK) + "{' " + c.SPARK_HOME + "conf/spark-defaults.conf")
print("setup_master, spark-defaults.conf 55: " + stdout + stderr)
stdout, stderr, status = ssh_client.run("""sed -i '3s{.*{master=""" + master_private_ip +
"""{' ./spark-bench/conf/env.sh""")
print("setup_master, ./spark-bench/conf/env.sh 3: " + stdout + stderr)
stdout, stderr, status = ssh_client.run("""sed -i '63s{.*{NUM_TRIALS=""" + str(c.BENCH_NUM_TRIALS) +
"""{' ./spark-bench/conf/env.sh""")
print("setup_master, ./spark-bench/conf/env.sh 63: " + stdout + stderr)
# CHANGE SPARK HOME DIR
stdout, stderr, status = ssh_client.run("sed -i '21s{.*{SPARK_HOME_DIR = \"" + c.SPARK_HOME + "\"{' ./spark-perf/config/config.py")
#print("setup_master, ./spark-perf/config/config.py 21: " + stdout + stderr)
# CHANGE MASTER ADDRESS IN BENCHMARK
stdout, stderr, status = ssh_client.run("""sed -i '30s{.*{SPARK_CLUSTER_URL = "spark://""" + master_private_ip +
""":7077"{' ./spark-perf/config/config.py""")
#print("setup_master, ./spark-perf/config/config.py 30: " + stdout + stderr)
# CHANGE SCALE FACTOR LINE 127
stdout, stderr, status = ssh_client.run(
"sed -i '127s{.*{SCALE_FACTOR = " + str(c.SCALE_FACTOR) + "{' ./spark-perf/config/config.py")
# CHANGE IGNORE_TRIALS LINE 134
stdout, stderr, status = ssh_client.run(
"sed -i '134s{.*{IGNORED_TRIALS = " + str(c.IGNORED_TRIALS) + "{' ./spark-perf/config/config.py")
# NO PROMPT
stdout, stderr, status = ssh_client.run("sed -i '103s{.*{PROMPT_FOR_DELETES = False{' ./spark-perf/config/config.py")
if len(c.BENCHMARK_PERF) > 0: # and c.SPARK_PERF_FOLDER == "spark-perf-gioenn":
if c.SKEW_TEST:
print(" Setting up skewed test")
ssh_client.run("""sed -i '169s{.*{ OptionSet("skew", [""" + str(
c.BENCH_CONF[c.BENCHMARK_PERF[0]]["skew"]) + """]),{' ./""" + c.SPARK_PERF_FOLDER + "/config/config.py")
else:
# Restore "no-skew test" line content
ssh_client.run("""sed -i '169s{.*{# The number of input partitions.{' ./""" + c.SPARK_PERF_FOLDER + "/config/config.py")
# ssh_client.run("""sed -i '164s{.*{OptionSet("skew", [""" + str(
# c.BENCH_CONF[c.BENCHMARK_PERF[0]]["skew"]) + """]){' ./""" + c.SPARK_PERF_FOLDER + "/config/config.py")
print(" Setting up num_trials")
ssh_client.run("""sed -i '160s{.*{ OptionSet("num-trials", [1]),{' ./""" + c.SPARK_PERF_FOLDER + "/config/config.py")
print(" Setting up unique-keys, num-partitions and reduce-tasks")
ssh_client.run("""sed -i '185s{.*{OptionSet("unique-keys",[""" + str(c.BENCH_CONF[c.BENCHMARK_PERF[0]][
"unique-keys"]) + """], False),{' ./""" + c.SPARK_PERF_FOLDER + "/config/config.py")
ssh_client.run("""sed -i '170s{.*{OptionSet("num-partitions", [""" + str(c.BENCH_CONF[c.BENCHMARK_PERF[0]][
"num-partitions"]) + """], can_scale=False),{' ./""" + c.SPARK_PERF_FOLDER + "/config/config.py")
ssh_client.run("""sed -i '172s{.*{OptionSet("reduce-tasks", [""" + str(c.BENCH_CONF[c.BENCHMARK_PERF[0]][
"reduce-tasks"]) + """], can_scale=False),{' ./""" + c.SPARK_PERF_FOLDER + "/config/config.py")
# CHANGE RAM EXEC
stdout, stderr, status = ssh_client.run(
"""sed -i '146s{.*{ JavaOptionSet("spark.executor.memory", [""" + c.RAM_EXEC + """]),{' ./spark-perf/config/config.py""")
stdout, stderr, status = ssh_client.run(
"""sed -i '55s{.*{SPARK_EXECUTOR_MEMORY=""" + c.RAM_EXEC + """{' ./spark-bench/conf/env.sh""")
# CHANGE RAM DRIVER
stdout, stderr, status = ssh_client.run(
"sed -i '26s{.*{spark.driver.memory " + c.RAM_DRIVER + "{' " + c.SPARK_HOME + "conf/spark-defaults.conf")
stdout, stderr, status = ssh_client.run(
"sed -i '154s{.*{SPARK_DRIVER_MEMORY = \""+c.RAM_DRIVER+"\"{' ./spark-perf/config/config.py")
print(" Enabling/Disabling Benchmark")
# ENABLE BENCHMARK
for bench in c.BENCHMARK_PERF:
for line_number in c.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 c.BENCH_LINES:
if bench not in c.BENCHMARK_PERF:
for line_number in c.BENCH_LINES[bench]:
ssh_client.run("sed -i '" + line_number + " s/^/#/' ./spark-perf/config/config.py")
# ENABLE HDFS
# if c.HDFS:
print(" Enabling HDFS in benchmarks")
stdout, stderr, status = ssh_client.run("sed -i '179s%memory%hdfs%g' ./spark-perf/config/config.py")
#if hdfs_master != "":
stdout, stderr, status = ssh_client.run(
"""sed -i '50s%.*%HDFS_URL = "hdfs://{0}:9000/test/"%' ./spark-perf/config/config.py""".format(
hdfs_master))
stdout, stderr, status = ssh_client.run(
"""sed -i '10s%.*%HDFS_URL="hdfs://{0}:9000"%' ./spark-bench/conf/env.sh""".format(
hdfs_master))
stdout, stderr, status = ssh_client.run(
"""sed -i '14s%.*%DATA_HDFS="hdfs://{0}:9000/SparkBench"%' ./spark-bench/conf/env.sh""".format(
hdfs_master))
# TODO: additional settings for spark-bench
# ssh_client.run("""sed -i '8s/.*//' ./spark-bench/conf/env.sh""")
stdout, stderr, status = ssh_client.run("""sed -i '8s{.*{[ -z "$HADOOP_HOME" ] \&\& export HADOOP_HOME="""+c.HADOOP_HOME+"""{' ./spark-bench/conf/env.sh""")
# slaves = slaves_ip[0]
# for slave in slaves_ip[1:]:
# slaves = slaves + ", " + slave
stdout, stderr, status = ssh_client.run(
"""sed -i '5s%.*%MC_LIST=()%' ./spark-bench/conf/env.sh""")
stdout, stderr, status = ssh_client.run(
"""sed -i '19s%.*%SPARK_VERSION=2.0%' ./spark-bench/conf/env.sh""")
# ssh_client.run("""sed -i '20s/.*//' ./spark-bench/conf/env.sh""")
stdout, stderr, status = ssh_client.run("""sed -i '20s{.*{[ -z "$SPARK_HOME" ] \&\& export SPARK_HOME="""+c.SPARK_HOME+"""{' ./spark-bench/conf/env.sh""")
# START MASTER and HISTORY SERVER
if current_cluster == 'spark':
print(" Starting Spark Master")
ssh_client.run(
'export SPARK_HOME="{d}" && {d}sbin/start-master.sh -h {0}'.format(
master_private_ip, d=c.SPARK_HOME))
print(" Starting Spark History Server")
ssh_client.run(
'export SPARK_HOME="{d}" && {d}sbin/start-history-server.sh'.format(d=c.SPARK_HOME))
# SETUP CSPARKWORK MASTER FOR PROCESSING LOGS ON SERVER
# To be changed: generalize private and public key paths references (currently the Azure ones)
with open_cfg() as cfg:
tool_on_master = cfg.getboolean('main', 'tool_on_master')
if current_cluster == 'spark' and c.PROCESS_ON_SERVER: #vboxvm
if not tool_on_master:
if c.INSTALL_PYTHON3 == 1:
stdout, stderr, status = ssh_client.run("sudo apt-get update && sudo apt-get install -y python3-pip && " +
"sudo apt-get build-dep -y matplotlib && "+
"sudo apt-get install -y build-essential libssl-dev libffi-dev python-dev python3-dev && "+
#"sudo apt-get install pkg-config" + #vboxvm? (double-check)
#"sudo apt-get install libfreetype6-dev" + #vboxvm? (double-check)
"sudo pip3 install --upgrade setuptools")
"""Install python3 on cSpark master"""
print("Installing Python3 on cspark master:\n" + stdout)
stdout, stderr, status = ssh_client.run("sudo rm -r /home/ubuntu/xSpark-bench")
#stdout, stderr, status = ssh_client.run("git clone -b exp-2018 --single-branch " +
# "https://github.com/DavideB/xSpark-bench.git /home/ubuntu/xSpark-bench")
stdout, stderr, status = ssh_client.run("git clone -b exp-2018 --single-branch " +
"https://github.com/gioenn/xSpark-bench.git /home/ubuntu/xSpark-bench")
"""Clone xSpark-benchmark on cspark master"""
print("Cloning xSpark-benchmark tool on cspark master:\n" + stdout)
if not "id_rsa" in ssh_client.listdir("/home/ubuntu/"):
ssh_client.put(localpath=c.PRIVATE_KEY_PATH, remotepath="/home/ubuntu/id_rsa")
ssh_client.run("chmod 400 /home/ubuntu/id_rsa")
"""upload private key to home directory"""
if not "id_rsa.pub" in ssh_client.listdir("/home/ubuntu/"):
ssh_client.put(localpath=c.AZ_PUB_KEY_PATH, remotepath="/home/ubuntu/id_rsa.pub")
ssh_client.run("chmod 400 /home/ubuntu/id_rsa.pub")
"""upload public key to home directory"""
#ssh_client.run("sudo rm /home/ubuntu/xSpark-bench/credentials.py")
#ssh_client.put(localpath="credentials.py", remotepath="/home/ubuntu/xSpark-bench/credentials.py")
"""upload credentials.py"""
#ssh_client.run("sudo rm /home/ubuntu/xSpark-bench/config.py")
#ssh_client.put(localpath="config.py", remotepath="/home/ubuntu/xSpark-bench/config.py")
"""upLoad config.py"""
ssh_client.run("sudo rm /home/ubuntu/xSpark-bench/configure.py")
ssh_client.put(localpath="configure.py", remotepath="/home/ubuntu/xSpark-bench/configure.py")
"""upLoad configure.py"""
credentials_file = Path("credentials.json")
if credentials_file.exists():
credentials = json.load(open("credentials.json"))
try:
credentials["AzPubKeyPath"] = "/home/ubuntu/" + credentials["AzPubKeyPath"].split("/")[-1]
credentials["AzPrvKeyPath"] = "/home/ubuntu/" + credentials["AzPrvKeyPath"].split("/")[-1]
credentials["KeyPairPath"] = "/home/ubuntu/" + credentials["KeyPairPath"].split("/")[-1]
except KeyError:
print("key error in file credentials.json\n")
with open("credentials_on_server.json", "w") as outfile:
json.dump(credentials, outfile, indent=4, sort_keys=True)
ssh_client.run("sudo rm /home/ubuntu/xSpark-bench/credentials.json")
ssh_client.put(localpath="credentials_on_server.json", remotepath="/home/ubuntu/xSpark-bench/credentials.json")
"""upLoad credentials.json"""
credentials_on_server_file = Path("credentials_on_server.json")
if credentials_on_server_file.exists():
os.remove("credentials_on_server.json")
ssh_client.run("sudo rm /home/ubuntu/setup.json")
ssh_client.put(localpath="setup.json", remotepath="/home/ubuntu/xSpark-bench/setup.json")
"""upLoad setup.json"""
ssh_client.run("sudo rm /home/ubuntu/control.json")
ssh_client.put(localpath="control.json", remotepath="/home/ubuntu/xSpark-bench/control.json")
"""upLoad control.json"""
#ssh_client.run("sudo rm /home/ubuntu/experiment.json")
#ssh_client.put(localpath="experiment.json", remotepath="/home/ubuntu/xSpark-bench/experiment.json")
"""upLoad experiment.json"""
# update cfg_clusters.ini before uploading it to master
with open_cfg(mode='w') as cfg:
cfg['main']['tool_on_master'] = 'true'
write_cfg(cfg)
#tool_on_master = True
#ssh_client.run("sudo rm /home/ubuntu/cfg_clusters.ini")
#ssh_client.put(localpath="cfg_clusters.ini", remotepath="/home/ubuntu/xSpark-bench/cfg_clusters.ini")
#"""upLoad cfg_clusters.ini"""
'''
stdout, stderr, status = ssh_client.run("""sed -i -r 's{^KEY_PAIR_PATH( *= *["'"'"'].*["'"'"']) *\+ *{KEY_PAIR_PATH = \"/home/ubuntu/\" + {' /home/ubuntu/xSpark-bench/config.py""")
stdout, stderr, status = ssh_client.run("""sed -i -r 's{^AZ_PRV_KEY_PATH( *= *["'"'"'].*["'"'"']) *\+ *{AZ_PRV_KEY_PATH = \"/home/ubuntu/\" + {' /home/ubuntu/xSpark-bench/credentials.py""")
stdout, stderr, status = ssh_client.run("""sed -i -r 's{^AZ_PUB_KEY_PATH( *= *["'"'"'].*["'"'"']) *\+ *{AZ_PUB_KEY_PATH = \"/home/ubuntu/\" + {' /home/ubuntu/xSpark-bench/credentials.py""")
stdout, stderr, status = ssh_client.run("cat /home/ubuntu/xSpark-bench/credentials.py | grep -e ^AZ_PRV_KEY_PATH -e ^AZ_PUB_KEY_PATH")
print("Re-defining private and public key paths in credentials.py\n" + stdout)
stdout, stderr, status = ssh_client.run("cat /home/ubuntu/xSpark-bench/config.py | grep -e ^KEY_PAIR_PATH")
print("Re-defining private and public key paths in config.py\n" + stdout)
"""Re-define private and public key paths"""
'''
stdout, stderr, status = ssh_client.run("cd /home/ubuntu/xSpark-bench && " +
"sudo pip3 install -r requirements.txt")
"""Install xSpark-benchmark tool requirements"""
print("Installing xSpark-benchmark tool requirements\n" + stdout)
ssh_client.run("sudo rm /home/ubuntu/xSpark-bench/cfg_clusters.ini")
ssh_client.put(localpath="cfg_clusters.ini", remotepath="/home/ubuntu/xSpark-bench/cfg_clusters.ini")
"""upLoad cfg_clusters.ini"""
return master_private_ip, node
@timing
def setup_hdfs_ssd(node, hdfs_master):
"""
:param node:
:return:
"""
with open_cfg() as cfg:
delete_hdfs = cfg.getboolean('main', 'delete_hdfs')
ssh_client = sshclient_from_node(node, ssh_key_file=c.PRIVATE_KEY_PATH, user_name='ubuntu')
out, err, status = 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)
# if c.PROVIDER == "AWS_SPOT":
# ssh_client.run("sudo chown ubuntu:hadoop /mnt/hdfs && sudo chown ubuntu:hadoop /mnt/hdfs/*")
# elif c.PROVIDER == "AZURE":
ssh_client.run("sudo chown ubuntu:ubuntu /mnt/hdfs && sudo chown ubuntu:ubuntu /mnt/hdfs/*")
if delete_hdfs or hdfs_master == "":
# ssh_client.run("rm /mnt/hdfs/datanode/current/VERSION")
ssh_client.run("sudo rm /mnt/hdfs/datanode/current/VERSION")
def rsync_folder(ssh_client, slave):
"""
:param ssh_client:
:param slave:
:return:
"""
with open_cfg() as cfg:
delete_hdfs = cfg.getboolean('main', 'delete_hdfs')
ssh_client.run(
"eval `ssh-agent -s` && ssh-add " + "$HOME/" + c.PRIVATE_KEY_NAME + " && rsync -a " + c.HADOOP_CONF + " ubuntu@" + slave + ":" + c.HADOOP_CONF)
if delete_hdfs:
# ssh_client.run("rm /mnt/hdfs/datanode/current/VERSION")
ssh_client.run("sudo rm /mnt/hdfs/datanode/current/VERSION")
@timing
def setup_hdfs_config(master_node, slaves, hdfs_master):
"""
:param master_node:
:param slaves:
:return:
"""
with open_cfg() as cfg:
delete_hdfs = cfg.getboolean('main', 'delete_hdfs')
ssh_client = sshclient_from_node(master_node, ssh_key_file=c.PRIVATE_KEY_PATH, user_name='ubuntu')
if hdfs_master == "":
master_ip = get_ip(master_node)
else:
master_ip = hdfs_master
# Setup Config HDFS
ssh_client.run(
"sed -i '19s%.*%<configuration> <property> <name>fs.default.name</name> <value>hdfs://" + master_ip + ":9000</value> </property>%g' " + c.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_ip + ":50070</value>%g' " + c.HADOOP_CONF + "hdfs-site.xml")
ssh_client.run(
"sed -i '43s%.*%<value>" + master_ip + ":50090</value>%g' " + c.HADOOP_CONF + "hdfs-site.xml")
ssh_client.run(
"sed -i '48s%.*%<value>" + master_ip + ":9000</value>%g' " + c.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' " + c.HADOOP_CONF + "hdfs-site.xml")
ssh_client.run(
"sed -i 's%/var/lib/hadoop/hdfs/datanode%/mnt/hdfs/datanode%g' " + c.HADOOP_CONF + "hdfs-site.xml")
print(slaves)
ssh_client.run("echo -e '" + "\n".join(slaves) + "' > " + c.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 " + "$HOME/" + c.PRIVATE_KEY_NAME + " && /usr/local/lib/hadoop-2.7.2/sbin/stop-dfs.sh")
# ssh_client.run("rm /mnt/hdfs/datanode/current/VERSION")
ssh_client.run("sudo rm /mnt/hdfs/datanode/current/VERSION")
ssh_client.run("echo 'N' | /usr/local/lib/hadoop-2.7.2/bin/hdfs namenode -format")
out, err, status = ssh_client.run(
"eval `ssh-agent -s` && ssh-add " + "$HOME/" + c.PRIVATE_KEY_NAME + " && /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(c.BENCHMARK_PERF) > 0:
out, err, status = ssh_client.run(
"/usr/local/lib/hadoop-2.7.2/bin/hadoop fs -rm -R /test/spark-perf-kv-data")
print(out, err, status)
def write_config(output_folder):
"""
:param output_folder:
:return:
"""
with open(output_folder + "/config.json", "w") as config_out:
json.dump(c.CONFIG_DICT, config_out, sort_keys=True, indent=4)
def check_slave_connected_master(ssh_client):
"""
:param ssh_client:
:return:
"""
pass
def upload_profile_to_master(nodes, profile_fname, localfilepath):
"""
:param nodes, profile_fname, localfilepath:
:return:
"""
ssh_client = sshclient_from_node(nodes[0], ssh_key_file=c.PRIVATE_KEY_PATH, user_name='ubuntu') #vboxvm_removed
#master_public_ip = socket.gethostbyname("XSPARKWORK0") #vboxvm
#ssh_client = sshclient_from_ip(master_public_ip, c.PRIVATE_KEY_PATH, user_name='ubuntu') #vboxvm
print("Uploading benchmark profile: " + profile_fname + "\n")
if not profile_fname in ssh_client.listdir(c.C_SPARK_HOME + "conf/"):
ssh_client.put(localpath=localfilepath, remotepath=c.C_SPARK_HOME + "conf/" + profile_fname)
ssh_client.run("chmod 664 " + c.C_SPARK_HOME + "conf/" + profile_fname)
ssh_client.run("sudo chown ubuntu:ubuntu " + c.C_SPARK_HOME + "conf/" + profile_fname)
print("Benchmark profile successfully uploaded\n")
"""upload profile to spark conf directory"""
else:
print("Not uploaded: a benchmark profile with the same name already exists\n")
@timing
def run_benchmark(nodes):
"""
:return:
"""
if len(nodes) == 0:
print("No instances running")
exit(1)
profile = False
profile_fname = ""
profile_option = False
benchmark = ""
with open_cfg(mode='w') as cfg:
current_cluster = cfg['main']['current_cluster']