Skip to content

Instantly share code, notes, and snippets.

@joerodriguez
Last active August 29, 2015 14:04
Show Gist options
  • Save joerodriguez/3f2a73386aaae56024a3 to your computer and use it in GitHub Desktop.
Save joerodriguez/3f2a73386aaae56024a3 to your computer and use it in GitHub Desktop.
Stress test for traffic controller with many CLI connections
package main
import (
"flag"
"fmt"
"os"
"os/exec"
"os/signal"
"sync"
)
var cliCount = flag.Int("n", 1, "number of concurrent CLIs")
var echoOutput = flag.Bool("e", false, "echo output from CLIs")
var appName = flag.String("a", "", "app name to tail logs for")
func main() {
flag.Parse()
killChan := make(chan os.Signal)
signal.Notify(killChan, os.Kill, os.Interrupt)
stopCommandsChan := make(chan struct{})
go func() {
<-killChan
close(stopCommandsChan)
}()
procs := sync.WaitGroup{}
for i := 0; i < *cliCount; i++ {
fmt.Printf("Starting cli #%d\n", i)
cmd := exec.Command("cf", "logs", *appName)
if *echoOutput {
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
}
cmd.Start()
go func() {
<-stopCommandsChan
cmd.Process.Kill()
procs.Done()
}()
procs.Add(1)
}
procs.Wait()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment