From cebaa06c8705ab37eea5d54bfd4059bb818071c0 Mon Sep 17 00:00:00 2001 From: Richard Liu Date: Wed, 15 Aug 2018 15:05:39 -0700 Subject: [PATCH 1/2] add soldier commander to kill_node.sh --- kill_node.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kill_node.sh b/kill_node.sh index f24623082..0d57b3253 100755 --- a/kill_node.sh +++ b/kill_node.sh @@ -1,4 +1,4 @@ -for pid in `/bin/ps -fu $USER| grep "benchmark\|txgen" | grep -v "grep" | awk '{print $2}'`; +for pid in `/bin/ps -fu $USER| grep "benchmark\|txgen\|soldier\|commander" | grep -v "grep" | awk '{print $2}'`; do echo 'Killed process: '$pid kill -9 $pid From 7cc5af41409c59b5dcf7f5467cf3c306c15caafe Mon Sep 17 00:00:00 2001 From: Richard Liu Date: Wed, 15 Aug 2018 15:11:02 -0700 Subject: [PATCH 2/2] update commander to support local mode. add script run_experiment.sh to run commander/soldier locally. --- agent/main.go | 3 +- .../experiment/commander/main.go | 52 +++++++++++++++---- run_experiment.sh | 24 +++++++++ 3 files changed, 66 insertions(+), 13 deletions(-) create mode 100755 run_experiment.sh diff --git a/agent/main.go b/agent/main.go index 204857d42..88307be6f 100644 --- a/agent/main.go +++ b/agent/main.go @@ -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) diff --git a/aws-experiment-launch/experiment/commander/main.go b/aws-experiment-launch/experiment/commander/main.go index c859db264..299477997 100644 --- a/aws-experiment-launch/experiment/commander/main.go +++ b/aws-experiment-launch/experiment/commander/main.go @@ -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 ( @@ -17,10 +30,13 @@ import ( ) type commanderSetting struct { - ip string - port string + ip string + port string + mode string + // Options in s3 mode configURL string - configs [][]string + + configs [][]string } type sessionInfo struct { @@ -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,10 +102,15 @@ 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.configURL = configURL + 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) { @@ -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() diff --git a/run_experiment.sh b/run_experiment.sh new file mode 100755 index 000000000..d126decd0 --- /dev/null +++ b/run_experiment.sh @@ -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 \ No newline at end of file