diff options
Diffstat (limited to 'test/benchmarks/base')
-rw-r--r-- | test/benchmarks/base/BUILD | 52 | ||||
-rw-r--r-- | test/benchmarks/base/base.go | 98 | ||||
-rw-r--r-- | test/benchmarks/base/size_test.go | 183 | ||||
-rw-r--r-- | test/benchmarks/base/startup_test.go | 146 | ||||
-rw-r--r-- | test/benchmarks/base/sysbench_test.go | 99 |
5 files changed, 0 insertions, 578 deletions
diff --git a/test/benchmarks/base/BUILD b/test/benchmarks/base/BUILD deleted file mode 100644 index b4b55317b..000000000 --- a/test/benchmarks/base/BUILD +++ /dev/null @@ -1,52 +0,0 @@ -load("//tools:defs.bzl", "go_library", "go_test") - -package(licenses = ["notice"]) - -go_library( - name = "base", - testonly = 1, - srcs = [ - "base.go", - ], - deps = [ - "//pkg/test/dockerutil", - "//test/benchmarks/harness", - ], -) - -go_test( - name = "startup_test", - size = "enormous", - srcs = ["startup_test.go"], - visibility = ["//:sandbox"], - deps = [ - "//pkg/test/dockerutil", - "//test/benchmarks/base", - "//test/benchmarks/harness", - ], -) - -go_test( - name = "size_test", - size = "enormous", - srcs = ["size_test.go"], - visibility = ["//:sandbox"], - deps = [ - "//pkg/test/dockerutil", - "//test/benchmarks/base", - "//test/benchmarks/harness", - "//test/benchmarks/tools", - ], -) - -go_test( - name = "sysbench_test", - size = "enormous", - srcs = ["sysbench_test.go"], - visibility = ["//:sandbox"], - deps = [ - "//pkg/test/dockerutil", - "//test/benchmarks/harness", - "//test/benchmarks/tools", - ], -) diff --git a/test/benchmarks/base/base.go b/test/benchmarks/base/base.go deleted file mode 100644 index 979564af9..000000000 --- a/test/benchmarks/base/base.go +++ /dev/null @@ -1,98 +0,0 @@ -// Copyright 2020 The gVisor Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package base holds utility methods common to the base tests. -package base - -import ( - "context" - "net" - "testing" - "time" - - "gvisor.dev/gvisor/pkg/test/dockerutil" - "gvisor.dev/gvisor/test/benchmarks/harness" -) - -// ServerArgs wraps args for startServers and runServerWorkload. -type ServerArgs struct { - Machine harness.Machine - Port int - RunOpts dockerutil.RunOpts - Cmd []string -} - -// StartServers starts b.N containers defined by 'runOpts' and 'cmd' and uses -// 'machine' to check that each is up. -func StartServers(ctx context.Context, b *testing.B, args ServerArgs) []*dockerutil.Container { - b.Helper() - servers := make([]*dockerutil.Container, 0, b.N) - - // Create N servers and wait until each of them is serving. - for i := 0; i < b.N; i++ { - server := args.Machine.GetContainer(ctx, b) - servers = append(servers, server) - if err := server.Spawn(ctx, args.RunOpts, args.Cmd...); err != nil { - CleanUpContainers(ctx, servers) - b.Fatalf("failed to spawn node instance: %v", err) - } - - // Get the container IP. - servingIP, err := server.FindIP(ctx, false) - if err != nil { - CleanUpContainers(ctx, servers) - b.Fatalf("failed to get ip from server: %v", err) - } - - // Wait until the server is up. - if err := harness.WaitUntilServing(ctx, args.Machine, servingIP, args.Port); err != nil { - CleanUpContainers(ctx, servers) - b.Fatalf("failed to wait for serving") - } - } - return servers -} - -// CleanUpContainers cleans up a slice of containers. -func CleanUpContainers(ctx context.Context, containers []*dockerutil.Container) { - for _, c := range containers { - if c != nil { - c.CleanUp(ctx) - } - } -} - -// RedisInstance returns a Redis container and its reachable IP. -func RedisInstance(ctx context.Context, b *testing.B, machine harness.Machine) (*dockerutil.Container, net.IP) { - b.Helper() - // Spawn a redis instance for the app to use. - redis := machine.GetNativeContainer(ctx, b) - if err := redis.Spawn(ctx, dockerutil.RunOpts{ - Image: "benchmarks/redis", - }); err != nil { - redis.CleanUp(ctx) - b.Fatalf("failed to spwan redis instance: %v", err) - } - - if out, err := redis.WaitForOutput(ctx, "Ready to accept connections", 3*time.Second); err != nil { - redis.CleanUp(ctx) - b.Fatalf("failed to start redis server: %v %s", err, out) - } - redisIP, err := redis.FindIP(ctx, false) - if err != nil { - redis.CleanUp(ctx) - b.Fatalf("failed to get IP from redis instance: %v", err) - } - return redis, redisIP -} diff --git a/test/benchmarks/base/size_test.go b/test/benchmarks/base/size_test.go deleted file mode 100644 index acc49cc7c..000000000 --- a/test/benchmarks/base/size_test.go +++ /dev/null @@ -1,183 +0,0 @@ -// Copyright 2020 The gVisor Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package size_test - -import ( - "context" - "os" - "testing" - "time" - - "gvisor.dev/gvisor/pkg/test/dockerutil" - "gvisor.dev/gvisor/test/benchmarks/base" - "gvisor.dev/gvisor/test/benchmarks/harness" - "gvisor.dev/gvisor/test/benchmarks/tools" -) - -var testHarness harness.Harness - -// BenchmarkSizeEmpty creates N empty containers and reads memory usage from -// /proc/meminfo. -func BenchmarkSizeEmpty(b *testing.B) { - machine, err := testHarness.GetMachine() - if err != nil { - b.Fatalf("failed to get machine: %v", err) - } - defer machine.CleanUp() - meminfo := tools.Meminfo{} - ctx := context.Background() - containers := make([]*dockerutil.Container, 0, b.N) - - // DropCaches before the test. - harness.DropCaches(machine) - - // Check available memory on 'machine'. - cmd, args := meminfo.MakeCmd() - before, err := machine.RunCommand(cmd, args...) - if err != nil { - b.Fatalf("failed to get meminfo: %v", err) - } - - // Make N containers. - for i := 0; i < b.N; i++ { - container := machine.GetContainer(ctx, b) - containers = append(containers, container) - if err := container.Spawn(ctx, dockerutil.RunOpts{ - Image: "benchmarks/alpine", - }, "sh", "-c", "echo Hello && sleep 1000"); err != nil { - base.CleanUpContainers(ctx, containers) - b.Fatalf("failed to run container: %v", err) - } - if _, err := container.WaitForOutputSubmatch(ctx, "Hello", 5*time.Second); err != nil { - base.CleanUpContainers(ctx, containers) - b.Fatalf("failed to read container output: %v", err) - } - } - - // Drop caches again before second measurement. - harness.DropCaches(machine) - - // Check available memory after containers are up. - after, err := machine.RunCommand(cmd, args...) - base.CleanUpContainers(ctx, containers) - if err != nil { - b.Fatalf("failed to get meminfo: %v", err) - } - meminfo.Report(b, before, after) -} - -// BenchmarkSizeNginx starts N containers running Nginx, checks that they're -// serving, and checks memory used based on /proc/meminfo. -func BenchmarkSizeNginx(b *testing.B) { - machine, err := testHarness.GetMachine() - if err != nil { - b.Fatalf("failed to get machine with: %v", err) - } - defer machine.CleanUp() - - // DropCaches for the first measurement. - harness.DropCaches(machine) - - // Measure MemAvailable before creating containers. - meminfo := tools.Meminfo{} - cmd, args := meminfo.MakeCmd() - before, err := machine.RunCommand(cmd, args...) - if err != nil { - b.Fatalf("failed to run meminfo command: %v", err) - } - - // Make N Nginx containers. - ctx := context.Background() - runOpts := dockerutil.RunOpts{ - Image: "benchmarks/nginx", - } - const port = 80 - servers := base.StartServers(ctx, b, - base.ServerArgs{ - Machine: machine, - Port: port, - RunOpts: runOpts, - Cmd: []string{"nginx", "-c", "/etc/nginx/nginx_gofer.conf"}, - }) - defer base.CleanUpContainers(ctx, servers) - - // DropCaches after servers are created. - harness.DropCaches(machine) - // Take after measurement. - after, err := machine.RunCommand(cmd, args...) - if err != nil { - b.Fatalf("failed to run meminfo command: %v", err) - } - meminfo.Report(b, before, after) -} - -// BenchmarkSizeNode starts N containers running a Node app, checks that -// they're serving, and checks memory used based on /proc/meminfo. -func BenchmarkSizeNode(b *testing.B) { - machine, err := testHarness.GetMachine() - if err != nil { - b.Fatalf("failed to get machine with: %v", err) - } - defer machine.CleanUp() - - // Make a redis instance for Node to connect. - ctx := context.Background() - redis, redisIP := base.RedisInstance(ctx, b, machine) - defer redis.CleanUp(ctx) - - // DropCaches after redis is created. - harness.DropCaches(machine) - - // Take before measurement. - meminfo := tools.Meminfo{} - cmd, args := meminfo.MakeCmd() - before, err := machine.RunCommand(cmd, args...) - if err != nil { - b.Fatalf("failed to run meminfo commend: %v", err) - } - - // Create N Node servers. - runOpts := dockerutil.RunOpts{ - Image: "benchmarks/node", - WorkDir: "/usr/src/app", - Links: []string{redis.MakeLink("redis")}, - } - nodeCmd := []string{"node", "index.js", redisIP.String()} - const port = 8080 - servers := base.StartServers(ctx, b, - base.ServerArgs{ - Machine: machine, - Port: port, - RunOpts: runOpts, - Cmd: nodeCmd, - }) - defer base.CleanUpContainers(ctx, servers) - - // DropCaches after servers are created. - harness.DropCaches(machine) - // Take after measurement. - cmd, args = meminfo.MakeCmd() - after, err := machine.RunCommand(cmd, args...) - if err != nil { - b.Fatalf("failed to run meminfo command: %v", err) - } - meminfo.Report(b, before, after) -} - -// TestMain is the main method for package network. -func TestMain(m *testing.M) { - testHarness.Init() - os.Exit(m.Run()) -} diff --git a/test/benchmarks/base/startup_test.go b/test/benchmarks/base/startup_test.go deleted file mode 100644 index 8ef9f99c4..000000000 --- a/test/benchmarks/base/startup_test.go +++ /dev/null @@ -1,146 +0,0 @@ -// Copyright 2020 The gVisor Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package startup_test - -import ( - "context" - "fmt" - "os" - "testing" - - "gvisor.dev/gvisor/pkg/test/dockerutil" - "gvisor.dev/gvisor/test/benchmarks/base" - "gvisor.dev/gvisor/test/benchmarks/harness" -) - -var testHarness harness.Harness - -// BenchmarkStartEmpty times startup time for an empty container. -func BenchmarkStartupEmpty(b *testing.B) { - machine, err := testHarness.GetMachine() - if err != nil { - b.Fatalf("failed to get machine: %v", err) - } - defer machine.CleanUp() - - ctx := context.Background() - for i := 0; i < b.N; i++ { - harness.DebugLog(b, "Running container: %d", i) - container := machine.GetContainer(ctx, b) - defer container.CleanUp(ctx) - if _, err := container.Run(ctx, dockerutil.RunOpts{ - Image: "benchmarks/alpine", - }, "true"); err != nil { - b.Fatalf("failed to run container: %v", err) - } - harness.DebugLog(b, "Ran container: %d", i) - } -} - -// BenchmarkStartupNginx times startup for a Nginx instance. -// Time is measured from start until the first request is served. -func BenchmarkStartupNginx(b *testing.B) { - // The machine to hold Nginx and the Node Server. - machine, err := testHarness.GetMachine() - if err != nil { - b.Fatalf("failed to get machine with: %v", err) - } - defer machine.CleanUp() - - ctx := context.Background() - runOpts := dockerutil.RunOpts{ - Image: "benchmarks/nginx", - } - runServerWorkload(ctx, b, - base.ServerArgs{ - Machine: machine, - RunOpts: runOpts, - Port: 80, - Cmd: []string{"nginx", "-c", "/etc/nginx/nginx_gofer.conf"}, - }) -} - -// BenchmarkStartupNode times startup for a Node application instance. -// Time is measured from start until the first request is served. -// Note that the Node app connects to a Redis instance before serving. -func BenchmarkStartupNode(b *testing.B) { - machine, err := testHarness.GetMachine() - if err != nil { - b.Fatalf("failed to get machine with: %v", err) - } - defer machine.CleanUp() - - ctx := context.Background() - redis, redisIP := base.RedisInstance(ctx, b, machine) - defer redis.CleanUp(ctx) - runOpts := dockerutil.RunOpts{ - Image: "benchmarks/node", - WorkDir: "/usr/src/app", - Links: []string{redis.MakeLink("redis")}, - } - - cmd := []string{"node", "index.js", redisIP.String()} - runServerWorkload(ctx, b, - base.ServerArgs{ - Machine: machine, - Port: 8080, - RunOpts: runOpts, - Cmd: cmd, - }) -} - -// runServerWorkload runs a server workload defined by 'runOpts' and 'cmd'. -// 'clientMachine' is used to connect to the server on 'serverMachine'. -func runServerWorkload(ctx context.Context, b *testing.B, args base.ServerArgs) { - b.ResetTimer() - for i := 0; i < b.N; i++ { - harness.DebugLog(b, "Running iteration: %d", i) - if err := func() error { - server := args.Machine.GetContainer(ctx, b) - defer func() { - b.StopTimer() - // Cleanup servers as we run so that we can go indefinitely. - server.CleanUp(ctx) - b.StartTimer() - }() - harness.DebugLog(b, "Spawning container: %s", args.RunOpts.Image) - if err := server.Spawn(ctx, args.RunOpts, args.Cmd...); err != nil { - return fmt.Errorf("failed to spawn node instance: %v", err) - } - - harness.DebugLog(b, "Finding Container IP") - servingIP, err := server.FindIP(ctx, false) - if err != nil { - return fmt.Errorf("failed to get ip from server: %v", err) - } - - harness.DebugLog(b, "Waiting for container to start.") - // Wait until the Client sees the server as up. - if err := harness.WaitUntilServing(ctx, args.Machine, servingIP, args.Port); err != nil { - return fmt.Errorf("failed to wait for serving: %v", err) - } - return nil - }(); err != nil { - b.Fatal(err) - } - harness.DebugLog(b, "Ran iteration: %d", i) - } -} - -// TestMain is the main method for package network. -func TestMain(m *testing.M) { - testHarness.Init() - os.Exit(m.Run()) -} diff --git a/test/benchmarks/base/sysbench_test.go b/test/benchmarks/base/sysbench_test.go deleted file mode 100644 index bbb797e14..000000000 --- a/test/benchmarks/base/sysbench_test.go +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright 2020 The gVisor Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package sysbench_test - -import ( - "context" - "testing" - - "gvisor.dev/gvisor/pkg/test/dockerutil" - "gvisor.dev/gvisor/test/benchmarks/harness" - "gvisor.dev/gvisor/test/benchmarks/tools" -) - -var testHarness harness.Harness - -type testCase struct { - name string - test tools.Sysbench -} - -// BenchmarSysbench runs sysbench on the runtime. -func BenchmarkSysbench(b *testing.B) { - - testCases := []testCase{ - testCase{ - name: "CPU", - test: &tools.SysbenchCPU{ - Base: tools.SysbenchBase{ - Threads: 1, - Time: 5, - }, - MaxPrime: 50000, - }, - }, - testCase{ - name: "Memory", - test: &tools.SysbenchMemory{ - Base: tools.SysbenchBase{ - Threads: 1, - }, - BlockSize: "1M", - TotalSize: "500G", - }, - }, - testCase{ - name: "Mutex", - test: &tools.SysbenchMutex{ - Base: tools.SysbenchBase{ - Threads: 8, - }, - Loops: 1, - Locks: 10000000, - Num: 4, - }, - }, - } - - machine, err := testHarness.GetMachine() - if err != nil { - b.Fatalf("failed to get machine: %v", err) - } - defer machine.CleanUp() - - for _, tc := range testCases { - param := tools.Parameter{ - Name: "testname", - Value: tc.name, - } - name, err := tools.ParametersToName(param) - if err != nil { - b.Fatalf("Failed to parse params: %v", err) - } - b.Run(name, func(b *testing.B) { - ctx := context.Background() - sysbench := machine.GetContainer(ctx, b) - defer sysbench.CleanUp(ctx) - - out, err := sysbench.Run(ctx, dockerutil.RunOpts{ - Image: "benchmarks/sysbench", - }, tc.test.MakeCmd()...) - if err != nil { - b.Fatalf("failed to run sysbench: %v: logs:%s", err, out) - } - tc.test.Report(b, out) - }) - } -} |