-
Notifications
You must be signed in to change notification settings - Fork 23
/
hub.js
executable file
·149 lines (120 loc) · 5.9 KB
/
hub.js
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
// hub script for dispatching simulation tasks to lots of servers
console.log("THIS IS NOT STABLE")
process.exit(1)
var async = require('async')
var sys = require('sys')
var exec = require('child_process').exec;
// todo just in case
var escapeshell = function(cmd) {
return '"'+cmd+'"';
};
function runRemoteCommand(host, cmd, out, cb, pr) {
var r = Math.floor(Math.random() * 100000000)
var f;
if (out)
f = "ssh -o \"StrictHostKeyChecking no\" ubuntu@" + host + " " + escapeshell(cmd) + " > " + (out+"-"+r)
else
f = "ssh -o \"StrictHostKeyChecking no\" ubuntu@" + host + " " + escapeshell(cmd);
exec(f, function(err, stdout, stderr) {
if (err)
console.log(err)
if (typeof pr != "undefined")
process.stderr.write(stdout.replace(/\s+$/, ""))
cb(null, null)
})
}
/////////////////////////////////////////////////////////////
hosts = [
["ec2-23-20-147-173.compute-1.amazonaws.com", 8],
["ec2-54-205-85-161.compute-1.amazonaws.com", 8],
["ec2-54-204-121-80.compute-1.amazonaws.com", 8],
["ec2-54-227-3-199.compute-1.amazonaws.com", 8],
["ec2-54-205-28-168.compute-1.amazonaws.com", 8],
["ec2-54-204-252-104.compute-1.amazonaws.com", 8],
["ec2-54-221-142-38.compute-1.amazonaws.com", 8],
["ec2-54-196-176-198.compute-1.amazonaws.com", 8],
["ec2-54-196-157-128.compute-1.amazonaws.com", 8],
["ec2-54-242-127-177.compute-1.amazonaws.com", 8],
["ec2-54-227-221-158.compute-1.amazonaws.com", 8],
["ec2-54-196-48-111.compute-1.amazonaws.com", 8],
["ec2-67-202-55-118.compute-1.amazonaws.com", 8],
["ec2-54-204-73-120.compute-1.amazonaws.com", 8],
["ec2-23-20-85-175.compute-1.amazonaws.com", 8],
["ec2-54-196-173-2.compute-1.amazonaws.com", 8],
["ec2-54-211-248-182.compute-1.amazonaws.com", 8],
["ec2-54-196-136-116.compute-1.amazonaws.com", 8],
["ec2-54-234-230-115.compute-1.amazonaws.com", 8]
]
tasks = []
for (var i=0;i<50;i++) {
// every percent less than 50 but > 20
for (var t=0;t<3;t++) {
// 3 trials of each
tasks.push(["cd ebfull.github.io && node sim.js " + (i/100).toFixed(2) + " normal", "/home/ubuntu/sim-"+i+"-normal-"+t])
tasks.push(["cd ebfull.github.io && node sim.js " + (i/100).toFixed(2) + " sybil", "/home/ubuntu/sim"+i+"-sybil-"+t])
tasks.push(["cd ebfull.github.io && node sim.js " + (i/100).toFixed(2) + " selfish", "/home/ubuntu/sim"+i+"-selfish-"+t])
tasks.push(["cd ebfull.github.io && node sim.js " + (i/100).toFixed(2) + " both", "/home/ubuntu/sim"+i+"-both-"+t])
}
}
/////////////////////////////////////////////////////////////
function doStuff() {
var workers = async.queue(function(arg, cb) {
var server = arg.server;
var q = async.queue(function(nope, doneWithTasks) {
var task;
async.whilst(function() {return task = tasks.shift();}, function(taskDone) {
console.log("dispatch (" + server[0] + "): " + task[0])
runRemoteCommand(server[0], task[0], task[1], function() {
console.log("completed (" + server[0] + "): " + task[0])
taskDone()
});
}, doneWithTasks);
}, server[1])
q.drain = function() {
host[3] = true;
cb();
}
for (var i=0;i<server[1];i++) {
q.push("nope")
}
}, hosts.length)
workers.drain = function() {
process.exit(1)
}
hosts.forEach(function(host) {
workers.push({server:host})
})
setInterval(function() {
// get stats for our workers
process.stderr.write("-----------------------\n")
hosts.forEach(function(host) {
if (typeof host[3] == "undefined") {
runRemoteCommand(host[0], "uptime", false, function() {
process.stderr.write(" (" + host[0] + ", concurrency=" + host[1] + ")\n")
}, true)
} else {
process.stderr.write("DONE (" + host[0] + ", concurrency=" + host[1] + ")\n")
}
})
}, 60 * 1000)
}
/////////////////////////////////////////////////////////////
var provision = async.queue(function(host, cb) {
console.log("(" + host + ") provisioning")
runRemoteCommand(host, "echo -e '\\nMaxSessions 1000\\nMaxStartups 1000\\n' | sudo tee -a /etc/ssh/sshd_config; sudo service ssh restart", false, function() {
runRemoteCommand(host, "ps aux | grep -ie sim.js | awk '{print \\$2}' | xargs kill -9", false, function() {
runRemoteCommand(host, "rm -rf ebfull.github.io; git clone https://github.com/ebfull/ebfull.github.io.git", false, function() {
runRemoteCommand(host, "cd ebfull.github.io; node prep.js sim.js", false, function() {
console.log("(" + host + ") done provisioning");
cb();
})
})
});
});
}, hosts.length);
provision.drain = function() {
doStuff();
}
hosts.forEach(function(h) {
provision.push(h[0])
})