Skip to content

Instantly share code, notes, and snippets.

@tom025
Created March 12, 2015 14:24
Show Gist options
  • Save tom025/590ad409399fb48f3bc8 to your computer and use it in GitHub Desktop.
Save tom025/590ad409399fb48f3bc8 to your computer and use it in GitHub Desktop.
Comparing `BulkInfo()` and `Info()` performance
package main
import (
"fmt"
"time"
"github.com/cloudfoundry-incubator/garden"
"github.com/cloudfoundry-incubator/garden/client"
"github.com/cloudfoundry-incubator/garden/client/connection"
)
var gc garden.Client
func main() {
refresh := false
c := connection.New("tcp", "localhost:7777")
gc = client.New(c)
if refresh {
clean()
}
containers := []garden.Container{}
if refresh {
for i := 0; i < 200; i++ {
container, err := createContainer()
if err != nil {
panic(err)
}
containers = append(containers, container)
}
} else {
var err error
containers, err = gc.Containers(garden.Properties{})
if err != nil {
panic(err)
}
}
infoInitTime := time.Now()
for _, container := range containers {
container.Info()
}
infoStopTime := time.Now()
fmt.Printf("Info calls took: %d μs\n", infoStopTime.Sub(infoInitTime)/time.Microsecond)
handles := []string{}
for _, container := range containers {
handles = append(handles, container.Handle())
}
bulkInfoInitTime := time.Now()
gc.BulkInfo(handles)
bulkInfoStopTime := time.Now()
fmt.Printf("BulkInfo calls took: %d μs\n", bulkInfoStopTime.Sub(bulkInfoInitTime)/time.Microsecond)
}
func createContainer() (garden.Container, error) {
spec := garden.ContainerSpec{
RootFSPath: "docker:///busybox",
GraceTime: time.Hour,
}
return gc.Create(spec)
}
func clean() {
containers, err := gc.Containers(garden.Properties{})
if err != nil {
panic(err)
}
for _, container := range containers {
gc.Destroy(container.Handle())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment