Skip to content

Instantly share code, notes, and snippets.

@aybabtme
Created January 11, 2014 15:38
Show Gist options
  • Save aybabtme/8372361 to your computer and use it in GitHub Desktop.
Save aybabtme/8372361 to your computer and use it in GitHub Desktop.
wishful_thinking.go
func DreamWayOfDoingIt() {
clientPool := NewAWSPool(awsCredentials, aws.T1Micro, aws.USEast, 30)
serverPool := NewAWSPool(awsCredentials, aws.T1Micro, aws.China, 30)
Join(clientPool, serverPool).RunNow(func(h Host) []string {
return []string{
"sudo apt-get update",
"sudo apt-get upgrade -y",
"sudo apt-get install -y mercurial git bzr gcc",
"hg clone -u release https://code.google.com/p/go",
"cd go/src",
"./all.bash",
"cd $HOME",
"mkdir $HOME/gocode",
"export GOPATH=$HOME/gocode",
"export PATH=$PATH:$HOME/go/bin:$HOME/gocode/bin",
"go get github.com/aybabtme/fight/udp_vs_tcp/fight",
"cp ~/gocode/bin/fight ~/fight",
}
})
var wg sync.WaitGroup
for i := 0; i < 30; i++ {
client := clientPool[i]
server := serverPool[i]
go runExperiment(client, server, wg, i)
}
wg.Wait()
}
func runExperiment(client, server Host, wg sync.WaitGroup, id int) {
wg.Add(1)
defer wg.Done()
serverFilename := fmt.Sprintf("tcp_client_%s_to_%s_%3d", client.Zone, server.Zone, id)
clientFilename := fmt.Sprintf("tcp_server_%s_to_%s_%3d", client.Zone, server.Zone, id)
serverCmd := fmt.Sprintf(
"fight -role=tcp_server -remote=%s -out=%s",
client.PublicIpAddr,
serverFilename,
)
clientCmd := fmt.Sprintf(
"fight -role=tcp_client -remote=%s -out=%s",
server.PublicIpAddr,
clientFilename,
)
serverRes := server.RunNow(func(h Host) []string {
return []string{serverCmd}
})
serverRes.StdOut.BlockUntil("Listening...", time.Second*5)
clientRes := client.RunNow(func(h Host) []string {
return []string{clientCmd}
})
clientRes.Wait()
serverRes.Wait()
pool := NewTaskPool()
pool.Add(func() { client.CopyFile(clientFilename, "results/"+clientFilename) })
pool.Add(func() { server.CopyFile(serverFilename, "results/"+serverFilename) })
pool.ExecuteAll()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment