[lxc-devel] [lxd/master] More lxd-benchmark refactors

albertodonato on Github lxc-bot at linuxcontainers.org
Wed Sep 6 09:16:24 UTC 2017


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 417 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20170906/f44ce556/attachment.bin>
-------------- next part --------------
From 870f10caea4b32f0624f595e1e02f3a750c9e00c Mon Sep 17 00:00:00 2001
From: Alberto Donato <alberto.donato at canonical.com>
Date: Tue, 5 Sep 2017 18:01:47 +0200
Subject: [PATCH 1/6] benchmark: add StopContainers function

Signed-off-by: Alberto Donato <alberto.donato at canonical.com>
---
 lxd-benchmark/benchmark/benchmark.go | 36 ++++++++++++++++++++++++++----------
 lxd-benchmark/benchmark/operation.go | 16 ++++++++++++++++
 2 files changed, 42 insertions(+), 10 deletions(-)
 create mode 100644 lxd-benchmark/benchmark/operation.go

diff --git a/lxd-benchmark/benchmark/benchmark.go b/lxd-benchmark/benchmark/benchmark.go
index 5b5fb6fdd..82b8d5666 100644
--- a/lxd-benchmark/benchmark/benchmark.go
+++ b/lxd-benchmark/benchmark/benchmark.go
@@ -135,6 +135,30 @@ func GetContainers(c lxd.ContainerServer) ([]api.Container, error) {
 	return containers, nil
 }
 
+// StopContainers stops containers created by the benchmark.
+func StopContainers(c lxd.ContainerServer, containers []api.Container, parallel int) error {
+	batchSize, err := getBatchSize(parallel)
+	if err != nil {
+		return err
+	}
+
+	stopContainer := func(index int, wg *sync.WaitGroup) {
+		defer wg.Done()
+
+		container := containers[index]
+		if container.IsActive() {
+			err := stopContainer(c, container.Name)
+			if err != nil {
+				logf("Failed to stop container '%s': %s", container.Name, err)
+				return
+			}
+		}
+	}
+
+	processBatch(len(containers), batchSize, stopContainer)
+	return nil
+}
+
 // DeleteContainers removes containers created by the benchmark.
 func DeleteContainers(c lxd.ContainerServer, containers []api.Container, parallel int) error {
 	batchSize, err := getBatchSize(parallel)
@@ -150,17 +174,9 @@ func DeleteContainers(c lxd.ContainerServer, containers []api.Container, paralle
 
 		ct := containers[index]
 
-		// Stop
 		if ct.IsActive() {
-			op, err := c.UpdateContainerState(ct.Name, api.ContainerStatePut{Action: "stop", Timeout: -1, Force: true}, "")
-			if err != nil {
-				logf("Failed to delete container '%s': %s", ct.Name, err)
-				return
-			}
-
-			err = op.Wait()
-			if err != nil {
-				logf("Failed to delete container '%s': %s", ct.Name, err)
+			if stopContainer(c, ct.Name) != nil {
+				logf("Failed to stop container '%s': %s", ct.Name, err)
 				return
 			}
 		}
diff --git a/lxd-benchmark/benchmark/operation.go b/lxd-benchmark/benchmark/operation.go
new file mode 100644
index 000000000..bbf648c32
--- /dev/null
+++ b/lxd-benchmark/benchmark/operation.go
@@ -0,0 +1,16 @@
+package benchmark
+
+import (
+	"github.com/lxc/lxd/client"
+	"github.com/lxc/lxd/shared/api"
+)
+
+func stopContainer(c lxd.ContainerServer, name string) error {
+	op, err := c.UpdateContainerState(
+		name, api.ContainerStatePut{Action: "stop", Timeout: -1, Force: true}, "")
+	if err != nil {
+		return err
+	}
+
+	return op.Wait()
+}

From 52c6391147a1982bfea14c4130500709a6284796 Mon Sep 17 00:00:00 2001
From: Alberto Donato <alberto.donato at canonical.com>
Date: Tue, 5 Sep 2017 18:14:25 +0200
Subject: [PATCH 2/6] benchmark: return operations duration

Signed-off-by: Alberto Donato <alberto.donato at canonical.com>
---
 lxd-benchmark/benchmark/benchmark.go | 32 +++++++++++++++++++-------------
 lxd-benchmark/main.go                |  6 ++++--
 2 files changed, 23 insertions(+), 15 deletions(-)

diff --git a/lxd-benchmark/benchmark/benchmark.go b/lxd-benchmark/benchmark/benchmark.go
index 82b8d5666..ffd8fefa5 100644
--- a/lxd-benchmark/benchmark/benchmark.go
+++ b/lxd-benchmark/benchmark/benchmark.go
@@ -35,17 +35,19 @@ func PrintServerInfo(c lxd.ContainerServer) error {
 }
 
 // SpawnContainers launches a set of containers.
-func SpawnContainers(c lxd.ContainerServer, count int, parallel int, image string, privileged bool, freeze bool) error {
+func SpawnContainers(c lxd.ContainerServer, count int, parallel int, image string, privileged bool, freeze bool) (time.Duration, error) {
+	var duration time.Duration
+
 	batchSize, err := getBatchSize(parallel)
 	if err != nil {
-		return err
+		return duration, err
 	}
 
 	printTestConfig(count, batchSize, image, privileged, freeze)
 
 	fingerprint, err := ensureImage(c, image)
 	if err != nil {
-		return err
+		return duration, err
 	}
 
 	startContainer := func(index int, wg *sync.WaitGroup) {
@@ -111,8 +113,8 @@ func SpawnContainers(c lxd.ContainerServer, count int, parallel int, image strin
 		}
 	}
 
-	processBatch(count, batchSize, startContainer)
-	return nil
+	duration = processBatch(count, batchSize, startContainer)
+	return duration, nil
 }
 
 // GetContainers returns containers created by the benchmark.
@@ -136,10 +138,12 @@ func GetContainers(c lxd.ContainerServer) ([]api.Container, error) {
 }
 
 // StopContainers stops containers created by the benchmark.
-func StopContainers(c lxd.ContainerServer, containers []api.Container, parallel int) error {
+func StopContainers(c lxd.ContainerServer, containers []api.Container, parallel int) (time.Duration, error) {
+	var duration time.Duration
+
 	batchSize, err := getBatchSize(parallel)
 	if err != nil {
-		return err
+		return duration, err
 	}
 
 	stopContainer := func(index int, wg *sync.WaitGroup) {
@@ -155,15 +159,17 @@ func StopContainers(c lxd.ContainerServer, containers []api.Container, parallel
 		}
 	}
 
-	processBatch(len(containers), batchSize, stopContainer)
-	return nil
+	duration = processBatch(len(containers), batchSize, stopContainer)
+	return duration, nil
 }
 
 // DeleteContainers removes containers created by the benchmark.
-func DeleteContainers(c lxd.ContainerServer, containers []api.Container, parallel int) error {
+func DeleteContainers(c lxd.ContainerServer, containers []api.Container, parallel int) (time.Duration, error) {
+	var duration time.Duration
+
 	batchSize, err := getBatchSize(parallel)
 	if err != nil {
-		return err
+		return duration, err
 	}
 
 	count := len(containers)
@@ -195,8 +201,8 @@ func DeleteContainers(c lxd.ContainerServer, containers []api.Container, paralle
 		}
 	}
 
-	processBatch(count, batchSize, deleteContainer)
-	return nil
+	duration = processBatch(count, batchSize, deleteContainer)
+	return duration, nil
 }
 
 func getBatchSize(parallel int) (int, error) {
diff --git a/lxd-benchmark/main.go b/lxd-benchmark/main.go
index b6e15d5fb..1b84652d0 100644
--- a/lxd-benchmark/main.go
+++ b/lxd-benchmark/main.go
@@ -65,13 +65,15 @@ func run(args []string) error {
 
 	switch os.Args[1] {
 	case "spawn":
-		return benchmark.SpawnContainers(c, *argCount, *argParallel, *argImage, *argPrivileged, *argFreeze)
+		_, err = benchmark.SpawnContainers(c, *argCount, *argParallel, *argImage, *argPrivileged, *argFreeze)
+		return err
 	case "delete":
 		containers, err := benchmark.GetContainers(c)
 		if err != nil {
 			return err
 		}
-		return benchmark.DeleteContainers(c, containers, *argParallel)
+		_, err = benchmark.DeleteContainers(c, containers, *argParallel)
+		return err
 	}
 
 	return nil

From 62309b14a278df38e22082273a5199ac9def292e Mon Sep 17 00:00:00 2001
From: Alberto Donato <alberto.donato at canonical.com>
Date: Wed, 6 Sep 2017 09:52:22 +0200
Subject: [PATCH 3/6] benchmark: add CreateContainers function

Signed-off-by: Alberto Donato <alberto.donato at canonical.com>
---
 lxd-benchmark/benchmark/benchmark.go | 61 ++++++++++++++++++++----------------
 lxd-benchmark/benchmark/operation.go | 24 ++++++++++++++
 2 files changed, 58 insertions(+), 27 deletions(-)

diff --git a/lxd-benchmark/benchmark/benchmark.go b/lxd-benchmark/benchmark/benchmark.go
index ffd8fefa5..935d7c3f6 100644
--- a/lxd-benchmark/benchmark/benchmark.go
+++ b/lxd-benchmark/benchmark/benchmark.go
@@ -53,39 +53,15 @@ func SpawnContainers(c lxd.ContainerServer, count int, parallel int, image strin
 	startContainer := func(index int, wg *sync.WaitGroup) {
 		defer wg.Done()
 
-		// Configure
-		config := map[string]string{}
-		if privileged {
-			config["security.privileged"] = "true"
-		}
-		config["user.lxd-benchmark"] = "true"
-
-		// Create
-		nameFormat := "benchmark-%." + fmt.Sprintf("%d", len(fmt.Sprintf("%d", count))) + "d"
-		name := fmt.Sprintf(nameFormat, index+1)
-		req := api.ContainersPost{
-			Name: name,
-			Source: api.ContainerSource{
-				Type:        "image",
-				Fingerprint: fingerprint,
-			},
-		}
-		req.Config = config
-
-		op, err := c.CreateContainer(req)
-		if err != nil {
-			logf("Failed to spawn container '%s': %s", name, err)
-			return
-		}
+		name := getContainerName(count, index)
 
-		err = op.Wait()
-		if err != nil {
+		if createContainer(c, fingerprint, name, privileged) != nil {
 			logf("Failed to spawn container '%s': %s", name, err)
 			return
 		}
 
 		// Start
-		op, err = c.UpdateContainerState(name, api.ContainerStatePut{Action: "start", Timeout: -1}, "")
+		op, err := c.UpdateContainerState(name, api.ContainerStatePut{Action: "start", Timeout: -1}, "")
 		if err != nil {
 			logf("Failed to spawn container '%s': %s", name, err)
 			return
@@ -117,6 +93,32 @@ func SpawnContainers(c lxd.ContainerServer, count int, parallel int, image strin
 	return duration, nil
 }
 
+// CreateContainers create the specified number of containers.
+func CreateContainers(c lxd.ContainerServer, count int, parallel int, fingerprint string) (time.Duration, error) {
+	var duration time.Duration
+
+	batchSize, err := getBatchSize(parallel)
+	if err != nil {
+		return duration, err
+	}
+
+	createContainer := func(index int, wg *sync.WaitGroup) {
+		defer wg.Done()
+
+		name := getContainerName(count, index)
+
+		err := createContainer(c, fingerprint, name, false)
+		if err != nil {
+			logf("Failed to spawn container '%s': %s", name, err)
+			return
+		}
+	}
+
+	duration = processBatch(count, batchSize, createContainer)
+
+	return duration, nil
+}
+
 // GetContainers returns containers created by the benchmark.
 func GetContainers(c lxd.ContainerServer) ([]api.Container, error) {
 	containers := []api.Container{}
@@ -220,6 +222,11 @@ func getBatchSize(parallel int) (int, error) {
 	return batchSize, nil
 }
 
+func getContainerName(count int, index int) string {
+	nameFormat := "benchmark-%." + fmt.Sprintf("%d", len(fmt.Sprintf("%d", count))) + "d"
+	return fmt.Sprintf(nameFormat, index+1)
+}
+
 func ensureImage(c lxd.ContainerServer, image string) (string, error) {
 	var fingerprint string
 
diff --git a/lxd-benchmark/benchmark/operation.go b/lxd-benchmark/benchmark/operation.go
index bbf648c32..c0d829875 100644
--- a/lxd-benchmark/benchmark/operation.go
+++ b/lxd-benchmark/benchmark/operation.go
@@ -5,6 +5,30 @@ import (
 	"github.com/lxc/lxd/shared/api"
 )
 
+func createContainer(c lxd.ContainerServer, fingerprint string, name string, privileged bool) error {
+	config := map[string]string{}
+	if privileged {
+		config["security.privileged"] = "true"
+	}
+	config["user.lxd-benchmark"] = "true"
+
+	req := api.ContainersPost{
+		Name: name,
+		Source: api.ContainerSource{
+			Type:        "image",
+			Fingerprint: fingerprint,
+		},
+	}
+	req.Config = config
+
+	op, err := c.CreateContainer(req)
+	if err != nil {
+		return err
+	}
+
+	return op.Wait()
+}
+
 func stopContainer(c lxd.ContainerServer, name string) error {
 	op, err := c.UpdateContainerState(
 		name, api.ContainerStatePut{Action: "stop", Timeout: -1, Force: true}, "")

From 45b2ad1ba78b52680d21a35c596c61c8008dc56d Mon Sep 17 00:00:00 2001
From: Alberto Donato <alberto.donato at canonical.com>
Date: Wed, 6 Sep 2017 10:21:25 +0200
Subject: [PATCH 4/6] benchmark: add StartContainers function

Signed-off-by: Alberto Donato <alberto.donato at canonical.com>
---
 lxd-benchmark/benchmark/benchmark.go | 38 ++++++++++++++++++++++++++----------
 lxd-benchmark/benchmark/operation.go | 10 ++++++++++
 2 files changed, 38 insertions(+), 10 deletions(-)

diff --git a/lxd-benchmark/benchmark/benchmark.go b/lxd-benchmark/benchmark/benchmark.go
index 935d7c3f6..ae7352b21 100644
--- a/lxd-benchmark/benchmark/benchmark.go
+++ b/lxd-benchmark/benchmark/benchmark.go
@@ -60,16 +60,8 @@ func SpawnContainers(c lxd.ContainerServer, count int, parallel int, image strin
 			return
 		}
 
-		// Start
-		op, err := c.UpdateContainerState(name, api.ContainerStatePut{Action: "start", Timeout: -1}, "")
-		if err != nil {
-			logf("Failed to spawn container '%s': %s", name, err)
-			return
-		}
-
-		err = op.Wait()
-		if err != nil {
-			logf("Failed to spawn container '%s': %s", name, err)
+		if startContainer(c, name) != nil {
+			logf("Failed to start container '%s': %s", name, err)
 			return
 		}
 
@@ -139,6 +131,32 @@ func GetContainers(c lxd.ContainerServer) ([]api.Container, error) {
 	return containers, nil
 }
 
+// StartContainers starts containers created by the benchmark.
+func StartContainers(c lxd.ContainerServer, containers []api.Container, parallel int) (time.Duration, error) {
+	var duration time.Duration
+
+	batchSize, err := getBatchSize(parallel)
+	if err != nil {
+		return duration, err
+	}
+
+	startContainer := func(index int, wg *sync.WaitGroup) {
+		defer wg.Done()
+
+		container := containers[index]
+		if container.IsActive() {
+			err := startContainer(c, container.Name)
+			if err != nil {
+				logf("Failed to start container '%s': %s", container.Name, err)
+				return
+			}
+		}
+	}
+
+	duration = processBatch(len(containers), batchSize, startContainer)
+	return duration, nil
+}
+
 // StopContainers stops containers created by the benchmark.
 func StopContainers(c lxd.ContainerServer, containers []api.Container, parallel int) (time.Duration, error) {
 	var duration time.Duration
diff --git a/lxd-benchmark/benchmark/operation.go b/lxd-benchmark/benchmark/operation.go
index c0d829875..d5771d2ae 100644
--- a/lxd-benchmark/benchmark/operation.go
+++ b/lxd-benchmark/benchmark/operation.go
@@ -29,6 +29,16 @@ func createContainer(c lxd.ContainerServer, fingerprint string, name string, pri
 	return op.Wait()
 }
 
+func startContainer(c lxd.ContainerServer, name string) error {
+	op, err := c.UpdateContainerState(
+		name, api.ContainerStatePut{Action: "start", Timeout: -1}, "")
+	if err != nil {
+		return err
+	}
+
+	return op.Wait()
+}
+
 func stopContainer(c lxd.ContainerServer, name string) error {
 	op, err := c.UpdateContainerState(
 		name, api.ContainerStatePut{Action: "stop", Timeout: -1, Force: true}, "")

From 5120c362c74aa37cf548ee58b39bf93e8d9134f4 Mon Sep 17 00:00:00 2001
From: Alberto Donato <alberto.donato at canonical.com>
Date: Wed, 6 Sep 2017 10:42:31 +0200
Subject: [PATCH 5/6] benchmark: add freezeContainer function

Signed-off-by: Alberto Donato <alberto.donato at canonical.com>
---
 lxd-benchmark/benchmark/benchmark.go | 12 ++----------
 lxd-benchmark/benchmark/operation.go | 10 ++++++++++
 2 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/lxd-benchmark/benchmark/benchmark.go b/lxd-benchmark/benchmark/benchmark.go
index ae7352b21..010307d68 100644
--- a/lxd-benchmark/benchmark/benchmark.go
+++ b/lxd-benchmark/benchmark/benchmark.go
@@ -65,17 +65,9 @@ func SpawnContainers(c lxd.ContainerServer, count int, parallel int, image strin
 			return
 		}
 
-		// Freeze
 		if freeze {
-			op, err := c.UpdateContainerState(name, api.ContainerStatePut{Action: "freeze", Timeout: -1}, "")
-			if err != nil {
-				logf("Failed to spawn container '%s': %s", name, err)
-				return
-			}
-
-			err = op.Wait()
-			if err != nil {
-				logf("Failed to spawn container '%s': %s", name, err)
+			if freezeContainer(c, name) != nil {
+				logf("Failed to freeze container '%s': %s", name, err)
 				return
 			}
 		}
diff --git a/lxd-benchmark/benchmark/operation.go b/lxd-benchmark/benchmark/operation.go
index d5771d2ae..3274bfc59 100644
--- a/lxd-benchmark/benchmark/operation.go
+++ b/lxd-benchmark/benchmark/operation.go
@@ -48,3 +48,13 @@ func stopContainer(c lxd.ContainerServer, name string) error {
 
 	return op.Wait()
 }
+
+func freezeContainer(c lxd.ContainerServer, name string) error {
+	op, err := c.UpdateContainerState(
+		name, api.ContainerStatePut{Action: "freeze", Timeout: -1}, "")
+	if err != nil {
+		return err
+	}
+
+	return op.Wait()
+}

From a64999d6ef9195a1f905a8be922c7acbfe2d6211 Mon Sep 17 00:00:00 2001
From: Alberto Donato <alberto.donato at canonical.com>
Date: Wed, 6 Sep 2017 10:13:52 +0200
Subject: [PATCH 6/6] benchmark: split private functions to separate files

Signed-off-by: Alberto Donato <alberto.donato at canonical.com>
---
 lxd-benchmark/benchmark/batch.go     | 61 ++++++++++++++++++++++++
 lxd-benchmark/benchmark/benchmark.go | 90 ++----------------------------------
 lxd-benchmark/benchmark/operation.go |  2 +-
 lxd-benchmark/benchmark/util.go      | 38 +++++++++++++++
 4 files changed, 103 insertions(+), 88 deletions(-)
 create mode 100644 lxd-benchmark/benchmark/batch.go
 create mode 100644 lxd-benchmark/benchmark/util.go

diff --git a/lxd-benchmark/benchmark/batch.go b/lxd-benchmark/benchmark/batch.go
new file mode 100644
index 000000000..0e2399480
--- /dev/null
+++ b/lxd-benchmark/benchmark/batch.go
@@ -0,0 +1,61 @@
+package benchmark
+
+import (
+	"io/ioutil"
+	"sync"
+	"time"
+)
+
+func getBatchSize(parallel int) (int, error) {
+	batchSize := parallel
+	if batchSize < 1 {
+		// Detect the number of parallel actions
+		cpus, err := ioutil.ReadDir("/sys/bus/cpu/devices")
+		if err != nil {
+			return -1, err
+		}
+
+		batchSize = len(cpus)
+	}
+
+	return batchSize, nil
+}
+
+func processBatch(count int, batchSize int, process func(index int, wg *sync.WaitGroup)) time.Duration {
+	batches := count / batchSize
+	remainder := count % batchSize
+	processed := 0
+	wg := sync.WaitGroup{}
+	nextStat := batchSize
+
+	logf("Batch processing start")
+	timeStart := time.Now()
+
+	for i := 0; i < batches; i++ {
+		for j := 0; j < batchSize; j++ {
+			wg.Add(1)
+			go process(processed, &wg)
+			processed++
+		}
+		wg.Wait()
+
+		if processed >= nextStat {
+			interval := time.Since(timeStart).Seconds()
+			logf("Processed %d containers in %.3fs (%.3f/s)", processed, interval, float64(processed)/interval)
+			nextStat = nextStat * 2
+		}
+
+	}
+
+	for k := 0; k < remainder; k++ {
+		wg.Add(1)
+		go process(processed, &wg)
+		processed++
+	}
+	wg.Wait()
+
+	timeEnd := time.Now()
+	duration := timeEnd.Sub(timeStart)
+	logf("Batch processing completed in %.3fs", duration.Seconds())
+	return duration
+}
diff --git a/lxd-benchmark/benchmark/benchmark.go b/lxd-benchmark/benchmark/benchmark.go
index 010307d68..ea04b3645 100644
--- a/lxd-benchmark/benchmark/benchmark.go
+++ b/lxd-benchmark/benchmark/benchmark.go
@@ -2,7 +2,6 @@ package benchmark
 
 import (
 	"fmt"
-	"io/ioutil"
 	"strings"
 	"sync"
 	"time"
@@ -13,6 +12,8 @@ import (
 	"github.com/lxc/lxd/shared/version"
 )
 
+const userConfigKey = "user.lxd-benchmark"
+
 // PrintServerInfo prints out information about the server.
 func PrintServerInfo(c lxd.ContainerServer) error {
 	server, _, err := c.GetServer()
@@ -113,7 +114,7 @@ func GetContainers(c lxd.ContainerServer) ([]api.Container, error) {
 	}
 
 	for _, container := range allContainers {
-		if container.Config["user.lxd-benchmark"] != "true" {
+		if container.Config[userConfigKey] != "true" {
 			continue
 		}
 
@@ -217,26 +218,6 @@ func DeleteContainers(c lxd.ContainerServer, containers []api.Container, paralle
 	return duration, nil
 }
 
-func getBatchSize(parallel int) (int, error) {
-	batchSize := parallel
-	if batchSize < 1 {
-		// Detect the number of parallel actions
-		cpus, err := ioutil.ReadDir("/sys/bus/cpu/devices")
-		if err != nil {
-			return -1, err
-		}
-
-		batchSize = len(cpus)
-	}
-
-	return batchSize, nil
-}
-
-func getContainerName(count int, index int) string {
-	nameFormat := "benchmark-%." + fmt.Sprintf("%d", len(fmt.Sprintf("%d", count))) + "d"
-	return fmt.Sprintf(nameFormat, index+1)
-}
-
 func ensureImage(c lxd.ContainerServer, image string) (string, error) {
 	var fingerprint string
 
@@ -294,68 +275,3 @@ func ensureImage(c lxd.ContainerServer, image string) (string, error) {
 	return fingerprint, nil
 }
 
-func processBatch(count int, batchSize int, process func(index int, wg *sync.WaitGroup)) time.Duration {
-	batches := count / batchSize
-	remainder := count % batchSize
-	processed := 0
-	wg := sync.WaitGroup{}
-	nextStat := batchSize
-
-	logf("Batch processing start")
-	timeStart := time.Now()
-
-	for i := 0; i < batches; i++ {
-		for j := 0; j < batchSize; j++ {
-			wg.Add(1)
-			go process(processed, &wg)
-			processed++
-		}
-		wg.Wait()
-
-		if processed >= nextStat {
-			interval := time.Since(timeStart).Seconds()
-			logf("Processed %d containers in %.3fs (%.3f/s)", processed, interval, float64(processed)/interval)
-			nextStat = nextStat * 2
-		}
-
-	}
-
-	for k := 0; k < remainder; k++ {
-		wg.Add(1)
-		go process(processed, &wg)
-		processed++
-	}
-	wg.Wait()
-
-	timeEnd := time.Now()
-	duration := timeEnd.Sub(timeStart)
-	logf("Batch processing completed in %.3fs", duration.Seconds())
-	return duration
-}
-
-func logf(format string, args ...interface{}) {
-	fmt.Printf(fmt.Sprintf("[%s] %s\n", time.Now().Format(time.StampMilli), format), args...)
-}
-
-func printTestConfig(count int, batchSize int, image string, privileged bool, freeze bool) {
-	privilegedStr := "unprivileged"
-	if privileged {
-		privilegedStr = "privileged"
-	}
-	mode := "normal startup"
-	if freeze {
-		mode = "start and freeze"
-	}
-
-	batches := count / batchSize
-	remainder := count % batchSize
-	fmt.Printf("Test variables:\n")
-	fmt.Printf("  Container count: %d\n", count)
-	fmt.Printf("  Container mode: %s\n", privilegedStr)
-	fmt.Printf("  Startup mode: %s\n", mode)
-	fmt.Printf("  Image: %s\n", image)
-	fmt.Printf("  Batches: %d\n", batches)
-	fmt.Printf("  Batch size: %d\n", batchSize)
-	fmt.Printf("  Remainder: %d\n", remainder)
-	fmt.Printf("\n")
-}
diff --git a/lxd-benchmark/benchmark/operation.go b/lxd-benchmark/benchmark/operation.go
index 3274bfc59..e01e5aaf3 100644
--- a/lxd-benchmark/benchmark/operation.go
+++ b/lxd-benchmark/benchmark/operation.go
@@ -10,7 +10,7 @@ func createContainer(c lxd.ContainerServer, fingerprint string, name string, pri
 	if privileged {
 		config["security.privileged"] = "true"
 	}
-	config["user.lxd-benchmark"] = "true"
+	config[userConfigKey] = "true"
 
 	req := api.ContainersPost{
 		Name: name,
diff --git a/lxd-benchmark/benchmark/util.go b/lxd-benchmark/benchmark/util.go
new file mode 100644
index 000000000..76972c684
--- /dev/null
+++ b/lxd-benchmark/benchmark/util.go
@@ -0,0 +1,38 @@
+package benchmark
+
+import (
+	"fmt"
+	"time"
+)
+
+func getContainerName(count int, index int) string {
+	nameFormat := "benchmark-%." + fmt.Sprintf("%d", len(fmt.Sprintf("%d", count))) + "d"
+	return fmt.Sprintf(nameFormat, index+1)
+}
+
+func logf(format string, args ...interface{}) {
+	fmt.Printf(fmt.Sprintf("[%s] %s\n", time.Now().Format(time.StampMilli), format), args...)
+}
+
+func printTestConfig(count int, batchSize int, image string, privileged bool, freeze bool) {
+	privilegedStr := "unprivileged"
+	if privileged {
+		privilegedStr = "privileged"
+	}
+	mode := "normal startup"
+	if freeze {
+		mode = "start and freeze"
+	}
+
+	batches := count / batchSize
+	remainder := count % batchSize
+	fmt.Printf("Test variables:\n")
+	fmt.Printf("  Container count: %d\n", count)
+	fmt.Printf("  Container mode: %s\n", privilegedStr)
+	fmt.Printf("  Startup mode: %s\n", mode)
+	fmt.Printf("  Image: %s\n", image)
+	fmt.Printf("  Batches: %d\n", batches)
+	fmt.Printf("  Batch size: %d\n", batchSize)
+	fmt.Printf("  Remainder: %d\n", remainder)
+	fmt.Printf("\n")
+}


More information about the lxc-devel mailing list