[lxc-devel] [lxd/master] lxd-benchmark improvements

stgraber on Github lxc-bot at linuxcontainers.org
Fri Oct 6 20:33:29 UTC 2017


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 313 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20171006/cd51c6fd/attachment.bin>
-------------- next part --------------
From 958c96b7e3e17a29562a2575aed5e51ca7e277ce Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Fri, 6 Oct 2017 14:28:31 -0400
Subject: [PATCH 1/4] shared: Cleanup use of log
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 shared/cert.go | 19 ++++++-------------
 1 file changed, 6 insertions(+), 13 deletions(-)

diff --git a/shared/cert.go b/shared/cert.go
index d9f19df5b..ac3ab3248 100644
--- a/shared/cert.go
+++ b/shared/cert.go
@@ -14,7 +14,6 @@ import (
 	"encoding/pem"
 	"fmt"
 	"io/ioutil"
-	"log"
 	"math/big"
 	"net"
 	"net/http"
@@ -95,16 +94,14 @@ func GenCert(certf string, keyf string, certtype bool) error {
 
 	certOut, err := os.Create(certf)
 	if err != nil {
-		log.Fatalf("failed to open %s for writing: %s", certf, err)
-		return err
+		return fmt.Errorf("Failed to open %s for writing: %v", certf, err)
 	}
 	certOut.Write(certBytes)
 	certOut.Close()
 
 	keyOut, err := os.OpenFile(keyf, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
 	if err != nil {
-		log.Printf("failed to open %s for writing: %s", keyf, err)
-		return err
+		return fmt.Errorf("Failed to open %s for writing: %v", keyf, err)
 	}
 	keyOut.Write(keyBytes)
 	keyOut.Close()
@@ -116,14 +113,12 @@ func GenCert(certf string, keyf string, certtype bool) error {
 func GenerateMemCert(client bool) ([]byte, []byte, error) {
 	privk, err := rsa.GenerateKey(rand.Reader, 4096)
 	if err != nil {
-		log.Fatalf("failed to generate key")
-		return nil, nil, err
+		return nil, nil, fmt.Errorf("Failed to generate key: %v", err)
 	}
 
 	hosts, err := mynames()
 	if err != nil {
-		log.Fatalf("Failed to get my hostname")
-		return nil, nil, err
+		return nil, nil, fmt.Errorf("Failed to get my hostname: %v", err)
 	}
 
 	validFrom := time.Now()
@@ -132,8 +127,7 @@ func GenerateMemCert(client bool) ([]byte, []byte, error) {
 	serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
 	serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
 	if err != nil {
-		log.Fatalf("failed to generate serial number: %s", err)
-		return nil, nil, err
+		return nil, nil, fmt.Errorf("Failed to generate serial number: %v", err)
 	}
 
 	userEntry, err := user.Current()
@@ -183,8 +177,7 @@ func GenerateMemCert(client bool) ([]byte, []byte, error) {
 
 	derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, &privk.PublicKey, privk)
 	if err != nil {
-		log.Fatalf("Failed to create certificate: %s", err)
-		return nil, nil, err
+		return nil, nil, fmt.Errorf("Failed to create certificate: %v", err)
 	}
 
 	cert := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: derBytes})

From faad52c7921287f4e1c679d9b4e8dc307f9ea617 Mon Sep 17 00:00:00 2001
From: Simos Xenitellis <simos at users.noreply.github.com>
Date: Wed, 27 Sep 2017 18:38:14 +0300
Subject: [PATCH 2/4] lxd-benchmark: Change name of `spawn` command to `launch`

LXD supports the four commands launch, start, stop, delete.
lxd-benchmark performs equivalent actions over a number of containers.
lxd-benchmark has the four commands spawn, start, stop, delete.
The `spawn` command should be renamed to `launch`.

Signed-off-by: Simos Xenitellis <simos at users.noreply.github.com>
---
 lxd-benchmark/benchmark/benchmark.go |  8 ++++----
 lxd-benchmark/main.go                | 10 +++++-----
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/lxd-benchmark/benchmark/benchmark.go b/lxd-benchmark/benchmark/benchmark.go
index 94dd8058e..581214234 100644
--- a/lxd-benchmark/benchmark/benchmark.go
+++ b/lxd-benchmark/benchmark/benchmark.go
@@ -35,8 +35,8 @@ func PrintServerInfo(c lxd.ContainerServer) error {
 	return nil
 }
 
-// SpawnContainers launches a set of containers.
-func SpawnContainers(c lxd.ContainerServer, count int, parallel int, image string, privileged bool, start bool, freeze bool) (time.Duration, error) {
+// LaunchContainers launches a set of containers.
+func LaunchContainers(c lxd.ContainerServer, count int, parallel int, image string, privileged bool, start bool, freeze bool) (time.Duration, error) {
 	var duration time.Duration
 
 	batchSize, err := getBatchSize(parallel)
@@ -58,7 +58,7 @@ func SpawnContainers(c lxd.ContainerServer, count int, parallel int, image strin
 
 		err := createContainer(c, fingerprint, name, privileged)
 		if err != nil {
-			logf("Failed to spawn container '%s': %s", name, err)
+			logf("Failed to launch container '%s': %s", name, err)
 			return
 		}
 
@@ -99,7 +99,7 @@ func CreateContainers(c lxd.ContainerServer, count int, parallel int, fingerprin
 
 		err := createContainer(c, fingerprint, name, privileged)
 		if err != nil {
-			logf("Failed to spawn container '%s': %s", name, err)
+			logf("Failed to launch container '%s': %s", name, err)
 			return
 		}
 	}
diff --git a/lxd-benchmark/main.go b/lxd-benchmark/main.go
index 76bc9e2fd..a8116d031 100644
--- a/lxd-benchmark/main.go
+++ b/lxd-benchmark/main.go
@@ -33,7 +33,7 @@ func main() {
 
 func run(args []string) error {
 	// Parse command line
-	if len(os.Args) == 1 || !shared.StringInSlice(os.Args[1], []string{"spawn", "start", "stop", "delete"}) {
+	if len(os.Args) == 1 || !shared.StringInSlice(os.Args[1], []string{"launch", "start", "stop", "delete"}) {
 		if len(os.Args) > 1 && os.Args[1] == "--version" {
 			fmt.Println(version.Version)
 			return nil
@@ -45,7 +45,7 @@ func run(args []string) error {
 		}
 		gnuflag.SetOut(out)
 
-		fmt.Fprintf(out, "Usage: %s spawn [--count=COUNT] [--image=IMAGE] [--privileged=BOOL] [--start=BOOL] [--freeze=BOOL] [--parallel=COUNT]\n", os.Args[0])
+		fmt.Fprintf(out, "Usage: %s launch [--count=COUNT] [--image=IMAGE] [--privileged=BOOL] [--start=BOOL] [--freeze=BOOL] [--parallel=COUNT]\n", os.Args[0])
 		fmt.Fprintf(out, "       %s start [--parallel=COUNT]\n", os.Args[0])
 		fmt.Fprintf(out, "       %s stop [--parallel=COUNT]\n", os.Args[0])
 		fmt.Fprintf(out, "       %s delete [--parallel=COUNT]\n\n", os.Args[0])
@@ -56,7 +56,7 @@ func run(args []string) error {
 			return nil
 		}
 
-		return fmt.Errorf("A valid action (spawn, start, stop, delete) must be passed.")
+		return fmt.Errorf("A valid action (launch, start, stop, delete) must be passed.")
 	}
 
 	gnuflag.Parse(true)
@@ -83,8 +83,8 @@ func run(args []string) error {
 	action := os.Args[1]
 	var duration time.Duration
 	switch action {
-	case "spawn":
-		duration, err = benchmark.SpawnContainers(
+	case "launch":
+		duration, err = benchmark.LaunchContainers(
 			c, *argCount, *argParallel, *argImage, *argPrivileged, *argStart, *argFreeze)
 		if err != nil {
 			return err

From aee12554058ecbb6b8c13f4a21c374d809ae2f87 Mon Sep 17 00:00:00 2001
From: Simos Xenitellis <simos at users.noreply.github.com>
Date: Fri, 29 Sep 2017 16:54:01 +0300
Subject: [PATCH 3/4] lxd-benchmark: Add "spawn" as equivalent but deprecated
 to "launch"

Originally, lxd-benchmark used `spawn` as the command to create
containers. Now `spawn` is being deprecated to `launch`.

Signed-off-by: Simos Xenitellis <simos at users.noreply.github.com>
---
 lxd-benchmark/main.go | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/lxd-benchmark/main.go b/lxd-benchmark/main.go
index a8116d031..e23638e33 100644
--- a/lxd-benchmark/main.go
+++ b/lxd-benchmark/main.go
@@ -33,7 +33,8 @@ func main() {
 
 func run(args []string) error {
 	// Parse command line
-	if len(os.Args) == 1 || !shared.StringInSlice(os.Args[1], []string{"launch", "start", "stop", "delete"}) {
+	// "spawn" is being deprecated, use "launch" instead.
+	if len(os.Args) == 1 || !shared.StringInSlice(os.Args[1], []string{"launch", "spawn", "start", "stop", "delete"}) {
 		if len(os.Args) > 1 && os.Args[1] == "--version" {
 			fmt.Println(version.Version)
 			return nil
@@ -83,7 +84,8 @@ func run(args []string) error {
 	action := os.Args[1]
 	var duration time.Duration
 	switch action {
-	case "launch":
+	// "spawn" is being deprecated.
+	case "launch", "spawn":
 		duration, err = benchmark.LaunchContainers(
 			c, *argCount, *argParallel, *argImage, *argPrivileged, *argStart, *argFreeze)
 		if err != nil {

From 57ca45cd564476afc048ab7bdfb70a0caf6f26f3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Fri, 6 Oct 2017 16:32:24 -0400
Subject: [PATCH 4/4] tests: Update perf.sh to "lxd-benchmark launch"
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 test/perf.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/test/perf.sh b/test/perf.sh
index 22f82fd39..6cbfd1b13 100755
--- a/test/perf.sh
+++ b/test/perf.sh
@@ -77,11 +77,11 @@ ensure_import_testimage
 # shellcheck disable=SC2034
 TEST_RESULT=failure
 
-run_benchmark "create-one" "create 1 container" spawn --count 1 --start=false --image=testimage
+run_benchmark "create-one" "create 1 container" launch --count 1 --start=false --image=testimage
 run_benchmark "start-one" "start 1 container" start
 run_benchmark "stop-one" "stop 1 container" stop
 run_benchmark "delete-one" "delete 1 container" delete
-run_benchmark "create-128" "create 128 containers" spawn --count 128 --start=false --image=testimage
+run_benchmark "create-128" "create 128 containers" launch --count 128 --start=false --image=testimage
 run_benchmark "start-128" "start 128 containers" start
 run_benchmark "delete-128" "delete 128 containers" delete
 


More information about the lxc-devel mailing list