update commander to support local mode. add script run_experiment.sh to run commander/soldier locally.

pull/58/head
Richard Liu 6 years ago
parent cebaa06c87
commit 7cc5af4140
  1. 3
      agent/main.go
  2. 44
      aws-experiment-launch/experiment/commander/main.go
  3. 24
      run_experiment.sh

@ -27,7 +27,6 @@ func logMemUsage() {
}
}
// TODO: @ricl, start another process for reporting.
func logCPUUsage() {
p, _ := process.NewProcess(pid)
for {
@ -37,6 +36,7 @@ func logCPUUsage() {
time.Sleep(3 * time.Second)
}
}
func main() {
_ip := flag.String("ip", "127.0.0.1", "IP of the node")
_port := flag.String("port", "9000", "port of the node.")
@ -45,7 +45,6 @@ func main() {
logFolder := flag.String("log_folder", "latest", "the folder collecting the logs of this execution")
flag.Parse()
fmt.Print(*configFile)
ip = *_ip
port = *_port
pid = int32(*_pid)

@ -1,3 +1,16 @@
/*
Commander has two modes to setup configuration: Local and S3.
Local Config Mode
The Default Mode.
Add `-mode local` or omit `-mode` to enter local config mode. In this mode, the `commander` will host the config file `config.txt` on the commander machine and `solider`s will download the config file from `http://{commander_ip}:{commander_port}/distribution_config.txt`.
Remote Config Mode
Add `-mode remote` to enter remote config mode. In this mode, the `soldier`s will download the config file from a remote URL (use `-config_url {url}` to set the URL).
*/
package main
import (
@ -19,7 +32,10 @@ import (
type commanderSetting struct {
ip string
port string
mode string
// Options in s3 mode
configURL string
configs [][]string
}
@ -35,13 +51,10 @@ var (
const (
DistributionFileName = "distribution_config.txt"
DefaultConfigUrl = "https://s3-us-west-2.amazonaws.com/unique-bucket-bin/distribution_config.txt"
)
func readConfigFile() [][]string {
if err := utils.DownloadFile(DistributionFileName, setting.configURL); err != nil {
panic(err)
}
if result, err := configr.ReadConfigFile(DistributionFileName); err != nil {
panic(err)
} else {
@ -57,6 +70,13 @@ func handleCommand(command string) {
switch cmd := args[0]; cmd {
case "config":
if setting.mode == "s3" {
// In s3 mode, download the config file from configURL first.
if err := utils.DownloadFile(DistributionFileName, setting.configURL); err != nil {
panic(err)
}
}
setting.configs = readConfigFile()
if setting.configs != nil {
log.Printf("The loaded config has %v nodes\n", len(setting.configs))
@ -82,11 +102,16 @@ func handleCommand(command string) {
}
}
func config(ip string, port string, configURL string) {
func config(ip string, port string, mode string, configURL string) {
setting.ip = ip
setting.port = port
setting.mode = mode
if mode == "local" {
setting.configURL = fmt.Sprintf("http://%s:%s/%s", ip, port, DistributionFileName)
} else {
setting.configURL = configURL
}
}
func dictateNodes(command string) {
resultChan := make(chan int)
@ -181,6 +206,10 @@ func jsonResponse(w http.ResponseWriter, code int, message string) {
}
func serve() {
if setting.mode == "local" {
// Only host config file if in local mode
http.Handle("/", http.FileServer(http.Dir("./")))
}
http.HandleFunc("/upload", handleUploadRequest)
err := http.ListenAndServe(":"+setting.port, nil)
if err != nil {
@ -192,10 +221,11 @@ func serve() {
func main() {
ip := flag.String("ip", "127.0.0.1", "The ip of commander, i.e. this machine")
port := flag.String("port", "8080", "The port which the commander uses to communicate with soldiers")
configURL := flag.String("config_url", "https://s3-us-west-2.amazonaws.com/unique-bucket-bin/distribution_config.txt", "The config URL")
mode := flag.String("mode", "local", "The config mode, local or s3")
configURL := flag.String("config_url", DefaultConfigUrl, "The config URL")
flag.Parse()
config(*ip, *port, *configURL)
config(*ip, *port, *mode, *configURL)
go serve()

@ -0,0 +1,24 @@
# Kill nodes if any
./kill_node.sh
go build -o bin/benchmark
go build -o bin/txgen client/txgen/main.go
go build -o bin/commander aws-experiment-launch/experiment/commander/main.go
go build -o bin/soldier aws-experiment-launch/experiment/soldier/main.go
cd bin
# Create a tmp folder for logs
t=`date +"%Y%m%d-%H%M%S"`
log_folder="tmp_log/log-$t"
mkdir -p $log_folder
# For each of the nodes, start soldier
config=distribution_config.txt
while IFS='' read -r line || [[ -n "$line" ]]; do
IFS=' ' read ip port mode shardId <<< $line
#echo $ip $port $mode
./soldier -ip $ip -port $port&
done < $config
./commander
Loading…
Cancel
Save