-
Notifications
You must be signed in to change notification settings - Fork 12
/
Rakefile
220 lines (176 loc) · 5.79 KB
/
Rakefile
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
require 'rake'
require 'shellwords'
HOSTNAME = `hostname`.strip()
USER = ENV['USER']
HOST_PORT = (`python2.7 python/config.py snapw.config master`).strip().split(':')
HOST = HOST_PORT[0]
PORT = HOST_PORT[1]
SLEEPTIME = 10
LFS = "/lfs/local/0/${USER}"
HOST_N = 17
################################
def sh2(cmd)
begin
sh cmd
rescue
end
end
def task_dsh(cmd)
if HOST.include? "ild"
for i in 1..2
puts "=" * 60
sh2 "ssh ild#{i} \"#{cmd}\""
end
elsif HOST.include? "iln" or HOST.include? "10.79.15.11"
for i in 1..HOST_N
puts "=" * 60
ii = "%.2i" % i
sh2 "ssh iln#{ii} \"#{cmd}\""
end
end
end
def task_dsh2(cmd)
if HOST.include? "ild"
sh2 "seq -f '%1g' 1 2 | parallel ssh ild{} \"#{cmd}\""
elsif HOST.include? "iln" or HOST.include? "10.79.15.11"
sh2 "seq -f '%02g' 1 #{HOST_N} | parallel ssh iln{} \"#{cmd}\""
end
end
def task_start(host, port)
sh "curl -i http://#{host}:#{port}/start"
end
def task_stop(host, port)
sh "curl -i http://#{host}:#{port}/stop"
end
task :setup do
# NOTE: Assumptions: This script will put stuff in parent directory.
Dir.chdir("../") do
sh "git clone git@github.com:snap-stanford/snap.git" unless File.exists?("snap")
sh "cd snap/; git pull; git checkout master;"
# NOTE: (1) snap-python requires snap to compie (2) we also need swig
sh "git clone git@github.com:snap-stanford/snap-python.git" unless File.exists?("snap-python")
sh "cd snap-python/; git pull; git checkout master; cd dev/swig-sw/; make clean; make;"
# Install the lazy module so broker works
sh "cd snapworld/broker; npm install lazy;"
end
end
task :yperf, [:master_log] do |t, args|
unless File.exists?("yperf")
Dir.chdir("../") do
sh "git clone git@github.com:snap-stanford/yperf.git" unless File.exists?("yperf")
#TODO cd and pull?
end
end
if args[:master_log].nil?
puts 'You must specify the path of master log, for instance rake yperf[../folder/master.log]'
else
sh "python/yperf_input.py %s | ../yperf/gen_report.py" % [args[:master_log]]
end
end
def pre_deploy_cleanup()
sh "fs flushvolume -path ." # flush AFS cache
cleanup = "rm -rf #{LFS}/supervisors/*; rm -rf #{LFS}/snapshot-*; rm -rf #{LFS}/master.log"
task_dsh(cleanup)
end
def task_deploy()
config_filepath = "snapw.config"
# Create `bin` directory, which is a staging directory to run
stage_dir = "bin/"
sh "mkdir -p #{stage_dir}"
sh "cp -f -p -r python/* #{stage_dir}"
sh "cp app/libbfs/* app/cppbfs/* app/bfs64/* #{stage_dir}"
sh "cp app/pybfs/* #{stage_dir}"
sh "cp -p ../snap-python/dev/swig-sw/_snap.so ../snap-python/dev/swig-sw/snap.py #{stage_dir}"
# override config File
sh "cp #{config_filepath} #{stage_dir}"
Dir.chdir("bin/") do
sh "mkdir -p #{LFS}"
sh "time python2.7 master.py 2>&1 | tee #{LFS}/master.log"
end
end
desc "Run C++ BFS (not Python BFS)"
task :deploy do
pre_deploy_cleanup()
task_deploy()
end
task :start do
task_start(HOST, PORT)
end
task :stop do
task_stop(HOST, PORT)
end
task :test do
begin
pre_deploy_cleanup()
sh "sleep #{SLEEPTIME} && rake start &"
task_deploy()
rescue
sh2 "rake stop"
end
sh2 "rake cleanup"
# sh "rm -rf bin/"
sh2 "rake dshgrep[\"WARNING|ERROR|CRITICAL|traceback\"]"
sh2 "rake show_output"
end
task :cleanup do
sh "ps x | egrep 'python|node' | grep -v grep | grep -v emacs | grep -v vim | awk '{print $1}'| xargs -r kill -SIGKILL"
killcmd_sup = Shellwords.escape("ps x | egrep 'python|node' | egrep -v 'vim|emacs|egrep' | awk '{print \\$1}' | xargs -r kill -SIGKILL")
task_dsh2(killcmd_sup)
end
task :show_output do
task_dsh2(Shellwords.escape("find #{LFS}/supervisors/ -iname 'log-swfinish*' | xargs -r cat"))
end
# Example: $ rake dsh["pkill python"]
task :dsh, :cmd do |t, args|
cmd = args.cmd
task_dsh(cmd)
end
task :check do
task_dsh("ps aux | grep python | grep ${USER} | grep -v grep")
end
task :dshgrep, :txt do |t, args|
txt = args.txt
task_dsh("egrep -I -i --include='*.log' -r '#{txt}' #{LFS}")
end
task :agglogs do
task_dsh("rm -rf /tmp/agglogs_#{USER}/; mkdir -p /tmp/agglogs_#{USER}/")
cmd = "find #{LFS}/supervisors/ -name '*.log' | parallel python ~/hanworks/snapworld/misc/parselog.py"
task_dsh(cmd)
sh2 "rm -rf #{LFS}/all_logs"
sh2 "mkdir -p #{LFS}/all_logs"
task_dsh("scp /tmp/agglogs_#{USER}/\*.log #{HOSTNAME}:#{LFS}/all_logs/")
sh2 "cp -f #{LFS}/master.log #{LFS}/all_logs"
sh2 "cat #{LFS}/all_logs/* | sort > #{LFS}/aggregated.log"
end
task :dulogs do
task_dsh("find #{LFS}/supervisors/ -iname '*.log' -print0 | du -h --files0-from - -c -s | tail -1")
end
task :dutotal do
task_dsh("find /lfs/local/0/${USER}/supervisors/ -type f -not -iname '*.log' -print0 | du -h --files0-from - -c -s | tail -1 | awk '{print $1}'")
end
################################
# To generate random datafile:
# dd if=/dev/urandom of=$HOME/largefile.dat bs=1048576 count=200
task :benchmark0 do
cmd = "pkill python"
sh2 "seq -f '%02g' 1 19 | parallel ssh iln{} \"#{cmd}\""
end
task :benchmark1 do
sh2 "rake benchmark0"
sh2 "rm -rf #{LFS}/fake_test"
sh2 "mkdir -p #{LFS}/fake_test"
Dir.chdir("misc/") do
sh2 "python fake_super.py -p 1337"
end
end
task :benchmark2 do
cmd = "seq 8 | parallel python ~/hanworks/snapworld/misc/fake_worker.py -hp iln01.stanford.edu:1337 -f ~/file200.dat"
# 17 - 2 + 1 = 16 supr machines
sh2 "seq -f '%02g' 2 17 | parallel ssh iln{} \"#{cmd}\""
end
task :genhosts do
puts `seq -f "iln%02g.stanford.edu:9200" -s "," 2 17`
end
task :catbrokerlogs do
task_dsh("cat #{LFS}/**/broker.log")
end