diff options
Diffstat (limited to 'test/benchmarks/base')
-rw-r--r-- | test/benchmarks/base/BUILD | 50 | ||||
-rw-r--r-- | test/benchmarks/base/base.go | 98 | ||||
-rw-r--r-- | test/benchmarks/base/size_test.go | 181 | ||||
-rw-r--r-- | test/benchmarks/base/startup_test.go | 144 | ||||
-rw-r--r-- | test/benchmarks/base/sysbench_test.go | 92 |
5 files changed, 0 insertions, 565 deletions
diff --git a/test/benchmarks/base/BUILD b/test/benchmarks/base/BUILD deleted file mode 100644 index a5a3cf2c1..000000000 --- a/test/benchmarks/base/BUILD +++ /dev/null @@ -1,50 +0,0 @@ -load("//tools:defs.bzl", "go_library") -load("//test/benchmarks:defs.bzl", "benchmark_test") - -package(licenses = ["notice"]) - -go_library( - name = "base", - testonly = 1, - srcs = [ - "base.go", - ], - deps = [ - "//pkg/test/dockerutil", - "//test/benchmarks/harness", - ], -) - -benchmark_test( - name = "startup_test", - srcs = ["startup_test.go"], - visibility = ["//:sandbox"], - deps = [ - "//pkg/test/dockerutil", - "//test/benchmarks/base", - "//test/benchmarks/harness", - ], -) - -benchmark_test( - name = "size_test", - srcs = ["size_test.go"], - visibility = ["//:sandbox"], - deps = [ - "//pkg/test/dockerutil", - "//test/benchmarks/base", - "//test/benchmarks/harness", - "//test/benchmarks/tools", - ], -) - -benchmark_test( - name = "sysbench_test", - 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 452926e5f..000000000 --- a/test/benchmarks/base/size_test.go +++ /dev/null @@ -1,181 +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" -) - -// BenchmarkSizeEmpty creates N empty containers and reads memory usage from -// /proc/meminfo. -func BenchmarkSizeEmpty(b *testing.B) { - machine, err := harness.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 := harness.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 := harness.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) { - harness.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 05a43ad17..000000000 --- a/test/benchmarks/base/startup_test.go +++ /dev/null @@ -1,144 +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" -) - -// BenchmarkStartEmpty times startup time for an empty container. -func BenchmarkStartupEmpty(b *testing.B) { - machine, err := harness.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 := harness.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 := harness.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) - } - - // Wait until the Client sees the server as up. - harness.DebugLog(b, "Waiting for container to start.") - 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) { - harness.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 d0f3f9261..000000000 --- a/test/benchmarks/base/sysbench_test.go +++ /dev/null @@ -1,92 +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" -) - -type testCase struct { - name string - test tools.Sysbench -} - -// BenchmarSysbench runs sysbench on the runtime. -func BenchmarkSysbench(b *testing.B) { - testCases := []testCase{ - { - name: "CPU", - test: &tools.SysbenchCPU{ - SysbenchBase: tools.SysbenchBase{ - Threads: 1, - }, - }, - }, - { - name: "Memory", - test: &tools.SysbenchMemory{ - SysbenchBase: tools.SysbenchBase{ - Threads: 1, - }, - }, - }, - { - name: "Mutex", - test: &tools.SysbenchMutex{ - SysbenchBase: tools.SysbenchBase{ - Threads: 8, - }, - }, - }, - } - - machine, err := harness.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) - - cmd := tc.test.MakeCmd(b) - b.ResetTimer() - out, err := sysbench.Run(ctx, dockerutil.RunOpts{ - Image: "benchmarks/sysbench", - }, cmd...) - if err != nil { - b.Fatalf("failed to run sysbench: %v: logs:%s", err, out) - } - b.StopTimer() - tc.test.Report(b, out) - }) - } -} |