github.phpd.cn/cilium/cilium@v1.6.12/test/runtime/benchmark.go (about)

     1  // Copyright 2019 Authors of Cilium
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package RuntimeTest
    16  
    17  import (
    18  	"bytes"
    19  	"fmt"
    20  	"os"
    21  	"path/filepath"
    22  	"strings"
    23  
    24  	"github.com/cilium/cilium/pkg/logging"
    25  	. "github.com/cilium/cilium/test/ginkgo-ext"
    26  	"github.com/cilium/cilium/test/helpers"
    27  	"github.com/cilium/cilium/test/helpers/constants"
    28  
    29  	. "github.com/onsi/gomega"
    30  	"github.com/sirupsen/logrus"
    31  )
    32  
    33  func superNetperfRRIPv4(s *helpers.SSHMeta, client string, server string, num int) *helpers.CmdRes {
    34  	var res *helpers.CmdRes
    35  
    36  	serverNet, _ := s.ContainerInspectNet(server)
    37  	serverIpv4 := serverNet[helpers.IPv4]
    38  	By("super_netperf to %s from %s (should succeed)", server, client)
    39  	cmd := fmt.Sprintf("super_netperf %d -t TCP_RR -H %s", num, serverIpv4)
    40  	res = s.ContainerExec(client, cmd)
    41  	res.ExpectSuccess("failed: %s", cmd)
    42  	return res
    43  }
    44  
    45  // SuperNetperfRR launches 'num' parallel netperf TCP_RR
    46  // (request/response) tests from client to server.
    47  func superNetperfRR(s *helpers.SSHMeta, client string, server string, num int) *helpers.CmdRes {
    48  	return superNetperfRRIPv4(s, client, server, num)
    49  }
    50  
    51  func superNetperfStreamIPv4(s *helpers.SSHMeta, client string, server string, num int) *helpers.CmdRes {
    52  	var res *helpers.CmdRes
    53  
    54  	serverNet, _ := s.ContainerInspectNet(server)
    55  	serverIpv4 := serverNet[helpers.IPv4]
    56  	By("super_netperf to %s from %s (should succeed)", server, client)
    57  	cmd := fmt.Sprintf("super_netperf %d -f g -t TCP_STREAM -H %s", num, serverIpv4)
    58  	res = s.ContainerExec(client, cmd)
    59  	res.ExpectSuccess("failed: %s", cmd)
    60  	return res
    61  }
    62  
    63  // SuperNetperfStream launches 'num' parallel netperf TCP_STREAM
    64  // tests from client to server.
    65  func superNetperfStream(s *helpers.SSHMeta, client string, server string, num int) *helpers.CmdRes {
    66  	return superNetperfStreamIPv4(s, client, server, num)
    67  }
    68  
    69  var _ = Describe("BenchmarkNetperfPerformance", func() {
    70  	var (
    71  		vm          *helpers.SSHMeta
    72  		monitorStop = func() error { return nil }
    73  
    74  		log    = logging.DefaultLogger
    75  		logger = logrus.NewEntry(log)
    76  
    77  		PerfLogFile   = "l4bench_perf.log"
    78  		PerfLogWriter bytes.Buffer
    79  	)
    80  
    81  	BeforeAll(func() {
    82  		vm = helpers.InitRuntimeHelper(helpers.Runtime, logger)
    83  		ExpectCiliumReady(vm)
    84  	})
    85  
    86  	JustBeforeEach(func() {
    87  		monitorStop = vm.MonitorStart()
    88  	})
    89  
    90  	JustAfterEach(func() {
    91  		vm.ValidateNoErrorsInLogs(CurrentGinkgoTestDescription().Duration)
    92  		Expect(monitorStop()).To(BeNil(), "cannot stop monitor command")
    93  	})
    94  
    95  	AfterFailed(func() {
    96  		vm.ReportFailed(
    97  			"cilium service list",
    98  			"cilium policy get")
    99  	})
   100  
   101  	AfterEach(func() {
   102  		LogPerm := os.FileMode(0666)
   103  		testPath, err := helpers.CreateReportDirectory()
   104  		Expect(err).Should(BeNil(), "cannot create log file")
   105  		helpers.WriteOrAppendToFile(filepath.Join(testPath, PerfLogFile), PerfLogWriter.Bytes(), LogPerm)
   106  		PerfLogWriter.Reset()
   107  	}, 500)
   108  
   109  	AfterAll(func() {
   110  		vm.CloseSSHClient()
   111  	})
   112  
   113  	createContainers := func() {
   114  		By("create Client container")
   115  		vm.ContainerCreate(helpers.Client, constants.NetperfImage, helpers.CiliumDockerNetwork, "-l id.client")
   116  		By("create Server containers")
   117  		vm.ContainerCreate(helpers.Server, constants.NetperfImage, helpers.CiliumDockerNetwork, "-l id.server")
   118  		vm.PolicyDelAll()
   119  		Expect(vm.WaitEndpointsReady()).To(BeNil(), "Endpoints are not ready")
   120  	}
   121  
   122  	removeContainers := func(containerName string) {
   123  		By("removing container %s", containerName)
   124  		res := vm.ContainerRm(containerName)
   125  		Expect(res.WasSuccessful()).Should(BeTrue(), "Container removal failed")
   126  	}
   127  
   128  	deleteContainers := func() {
   129  		removeContainers(helpers.Client)
   130  		removeContainers(helpers.Server)
   131  	}
   132  
   133  	superNetperfRRLog := func(client string, server string, num int) {
   134  		res := superNetperfRR(vm, client, server, num)
   135  		fmt.Fprintf(&PerfLogWriter, "%s,", strings.TrimSuffix(res.GetStdOut(), "\n"))
   136  	}
   137  
   138  	superNetperfStreamLog := func(client string, server string, num int) {
   139  		res := superNetperfStream(vm, client, server, num)
   140  		fmt.Fprintf(&PerfLogWriter, "%s,", strings.TrimSuffix(res.GetStdOut(), "\n"))
   141  	}
   142  
   143  	Context("Benchmark Netperf Tests", func() {
   144  		BeforeAll(func() {
   145  			createContainers()
   146  		})
   147  
   148  		AfterAll(func() {
   149  			deleteContainers()
   150  		})
   151  
   152  		It("Test L4 Netperf TCP_RR Performance lo:1", func() {
   153  			superNetperfRRLog(helpers.Server, helpers.Server, 1)
   154  		}, 300)
   155  
   156  		It("Test L4 Netperf TCP_RR Performance lo:10", func() {
   157  			superNetperfRRLog(helpers.Server, helpers.Server, 10)
   158  		}, 300)
   159  
   160  		It("Test L4 Netperf Performance lo:100", func() {
   161  			superNetperfRRLog(helpers.Server, helpers.Server, 100)
   162  		}, 300)
   163  
   164  		It("Test L4 Netperf TCP_RR Performance lo:1000", func() {
   165  			superNetperfRRLog(helpers.Server, helpers.Server, 1000)
   166  		}, 300)
   167  
   168  		It("Test L4 Netperf TCP_RR Performance inter-container:1", func() {
   169  			superNetperfRRLog(helpers.Client, helpers.Server, 1)
   170  		}, 300)
   171  
   172  		It("Test L4 Netperf TCP_RR Performance inter-container:10", func() {
   173  			superNetperfRRLog(helpers.Client, helpers.Server, 10)
   174  		}, 300)
   175  
   176  		It("Test L4 Netperf TCP_RR Performance inter-container:100", func() {
   177  			superNetperfRRLog(helpers.Client, helpers.Server, 100)
   178  		}, 300)
   179  
   180  		It("Test L4 Netperf TCP_RR Performance inter-container:1000", func() {
   181  			superNetperfRRLog(helpers.Client, helpers.Server, 1000)
   182  		}, 300)
   183  
   184  		It("Test L4 Netperf TCP_STREAM Performance lo:1", func() {
   185  			superNetperfStreamLog(helpers.Server, helpers.Server, 1)
   186  		}, 300)
   187  
   188  		It("Test L4 Netperf TCP_STREAM Performance lo:10", func() {
   189  			superNetperfStreamLog(helpers.Server, helpers.Server, 10)
   190  		}, 300)
   191  
   192  		It("Test L4 Netperf TCP_STREAM Performance lo:100", func() {
   193  			superNetperfStreamLog(helpers.Server, helpers.Server, 100)
   194  		}, 300)
   195  
   196  		It("Test L4 Netperf TCP_STREAM Performance lo:1000", func() {
   197  			superNetperfStreamLog(helpers.Server, helpers.Server, 1000)
   198  		}, 300)
   199  
   200  		It("Test L4 Netperf TCP_STREAM Performance lo:1", func() {
   201  			superNetperfStreamLog(helpers.Client, helpers.Server, 1)
   202  		}, 300)
   203  
   204  		It("Test L4 Netperf TCP_STREAM Performance lo:10", func() {
   205  			superNetperfStreamLog(helpers.Client, helpers.Server, 10)
   206  		}, 300)
   207  
   208  		It("Test L4 Netperf TCP_STREAM Performance lo:100", func() {
   209  			superNetperfStreamLog(helpers.Client, helpers.Server, 100)
   210  		}, 300)
   211  
   212  		It("Test L4 Netperf TCP_STREAM Performance lo:1000", func() {
   213  			superNetperfStreamLog(helpers.Client, helpers.Server, 1000)
   214  		}, 300)
   215  	})
   216  
   217  	Context("Benchmark Netperf Tests Sockops-Enabled", func() {
   218  		BeforeAll(func() {
   219  			vm.SetUpCiliumWithSockops()
   220  			ExpectCiliumReady(vm)
   221  			createContainers()
   222  		})
   223  
   224  		AfterAll(func() {
   225  			deleteContainers()
   226  		})
   227  
   228  		It("Test L4 Netperf TCP_RR Performance Sockops lo:1", func() {
   229  			superNetperfRRLog(helpers.Server, helpers.Server, 1)
   230  		}, 300)
   231  
   232  		It("Test L4 Netperf TCP_RR Performance Sockops lo:10", func() {
   233  			superNetperfRRLog(helpers.Server, helpers.Server, 10)
   234  		}, 300)
   235  
   236  		It("Test L4 Netperf TCP_RR Performance Sockops lo:100", func() {
   237  			superNetperfRRLog(helpers.Server, helpers.Server, 100)
   238  		}, 300)
   239  
   240  		It("Test L4 Netperf TCP_RR Performance Sockops lo:1000", func() {
   241  			superNetperfRRLog(helpers.Server, helpers.Server, 1000)
   242  		}, 300)
   243  
   244  		It("Test L4 Netperf TCP_RR Performance Sockops inter-container:1", func() {
   245  			superNetperfRRLog(helpers.Client, helpers.Server, 1)
   246  		}, 300)
   247  
   248  		It("Test L4 Netperf TCP_RR Performance Sockops inter-container:10", func() {
   249  			superNetperfRRLog(helpers.Client, helpers.Server, 10)
   250  		}, 300)
   251  
   252  		It("Test L4 Netperf TCP_RR Performance Sockops inter-container:100", func() {
   253  			superNetperfRRLog(helpers.Client, helpers.Server, 100)
   254  		}, 300)
   255  
   256  		It("Test L4 Netperf TCP_RR Performance Sockops inter-container:1000", func() {
   257  			superNetperfRRLog(helpers.Client, helpers.Server, 1000)
   258  		}, 300)
   259  
   260  		It("Test L4 Netperf TCP_STREAM Performance Sockops lo:1", func() {
   261  			superNetperfStreamLog(helpers.Server, helpers.Server, 1)
   262  		}, 300)
   263  
   264  		It("Test L4 Netperf TCP_STREAM Performance Sockops lo:10", func() {
   265  			superNetperfStreamLog(helpers.Server, helpers.Server, 10)
   266  		}, 300)
   267  
   268  		It("Test L4 Netperf TCP_STREAM Performance Sockops lo:100", func() {
   269  			superNetperfStreamLog(helpers.Server, helpers.Server, 100)
   270  		}, 300)
   271  
   272  		It("Test L4 Netperf TCP_STREAM Performance Sockops lo:1000", func() {
   273  			superNetperfStreamLog(helpers.Server, helpers.Server, 1000)
   274  		}, 300)
   275  
   276  		It("Test L4 Netperf TCP_STREAM Performance Sockops lo:1", func() {
   277  			superNetperfStreamLog(helpers.Client, helpers.Server, 1)
   278  		}, 300)
   279  
   280  		It("Test L4 Netperf TCP_STREAM Performance Sockops lo:10", func() {
   281  			superNetperfStreamLog(helpers.Client, helpers.Server, 10)
   282  		}, 300)
   283  
   284  		It("Test L4 Netperf TCP_STREAM Performance Sockops lo:100", func() {
   285  			superNetperfStreamLog(helpers.Client, helpers.Server, 100)
   286  		}, 300)
   287  
   288  		It("Test L4 Netperf TCP_STREAM Performance Sockops lo:1000", func() {
   289  			superNetperfStreamLog(helpers.Client, helpers.Server, 1000)
   290  		}, 300)
   291  	})
   292  })