From 3894db28090b3ede29b00e9d4983afa495b8aac5 Mon Sep 17 00:00:00 2001 From: Ryan Uber Date: Sat, 26 Sep 2015 09:27:40 -0700 Subject: [PATCH] demo/digitalocean: add bench app --- demo/digitalocean/app/main.go | 53 +++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 demo/digitalocean/app/main.go diff --git a/demo/digitalocean/app/main.go b/demo/digitalocean/app/main.go new file mode 100644 index 000000000..97c1c8c21 --- /dev/null +++ b/demo/digitalocean/app/main.go @@ -0,0 +1,53 @@ +package main + +import ( + "fmt" + "time" + + "github.com/hashicorp/nomad/api" + "github.com/hashicorp/nomad/nomad/structs" +) + +func main() { + client, err := api.NewClient(api.DefaultConfig()) + if err != nil { + fmt.Println(err.Error()) + return + } + + total := 4000 + running := 0 + start := time.Now() + allocClient := client.Allocations() + + fmt.Printf("benchmarking %d allocations\n", total) + for i := 0; ; i++ { + time.Sleep(100 * time.Millisecond) + + allocs, _, err := allocClient.List(nil) + if err != nil { + fmt.Println(err.Error()) + + // keep going to paper over minor errors + continue + } + now := time.Now() + + for _, alloc := range allocs { + if alloc.ClientStatus == structs.AllocClientStatusRunning { + if running == 0 { + fmt.Println("time to first running: %s", now.Sub(start)) + } + running++ + } + } + + if i%10 == 0 || running == total { + fmt.Printf("%d running after %s\n", running, now.Sub(start)) + } + + if running == total { + return + } + } +}