github.com/schwarzm/garden-linux@v0.0.0-20150507151835-33bca2147c47/integration/performance/create_measure_test.go (about) 1 package performance_test 2 3 import ( 4 "runtime" 5 "strconv" 6 7 "log" 8 "os" 9 10 "github.com/cloudfoundry-incubator/garden" 11 gclient "github.com/cloudfoundry-incubator/garden/client" 12 "github.com/cloudfoundry-incubator/garden/client/connection" 13 . "github.com/onsi/ginkgo" 14 . "github.com/onsi/gomega" 15 ) 16 17 const ( 18 creates = 40 19 createSamples = 5 20 ) 21 22 var _ = Describe("Concurrent container creation", func() { 23 24 BeforeEach(func() { 25 runtime.GOMAXPROCS(runtime.NumCPU()) 26 }) 27 28 Measure("multiple concurrent creates", func(b Benchmarker) { 29 if os.Getenv("GARDEN_PERFORMANCE") == "" { 30 log.Println("GARDEN_PERFORMANCE undefined; skipping") 31 return 32 } 33 handles := []string{} 34 35 b.Time("concurrent creations", func() { 36 chans := []chan string{} 37 for i := 0; i < creates; i++ { 38 ch := make(chan string, 1) 39 go func(c chan string, index int) { 40 defer GinkgoRecover() 41 client := gclient.New(connection.New("tcp", "localhost:7777")) 42 b.Time("create-"+strconv.Itoa(index), func() { 43 ctr, err := client.Create(garden.ContainerSpec{}) 44 Expect(err).ToNot(HaveOccurred()) 45 c <- ctr.Handle() 46 }) 47 }(ch, i) 48 chans = append(chans, ch) 49 } 50 51 for _, ch := range chans { 52 handle := <-ch 53 if handle != "" { 54 handles = append(handles, handle) 55 56 } 57 } 58 }) 59 60 for _, handle := range handles { 61 client := gclient.New(connection.New("tcp", "localhost:7777")) 62 Expect(client.Destroy(handle)).To(Succeed()) 63 } 64 65 }, createSamples) 66 67 })