...

Source file src/k8s.io/kubernetes/test/e2e_node/perf/workloads/npb_ep.go

Documentation: k8s.io/kubernetes/test/e2e_node/perf/workloads

     1  /*
     2  Copyright 2018 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package workloads
    18  
    19  import (
    20  	"fmt"
    21  	"strings"
    22  	"time"
    23  
    24  	v1 "k8s.io/api/core/v1"
    25  	"k8s.io/apimachinery/pkg/api/resource"
    26  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    27  	kubeletconfig "k8s.io/kubernetes/pkg/kubelet/apis/config"
    28  	"k8s.io/kubernetes/pkg/kubelet/cm/cpumanager"
    29  	imageutils "k8s.io/kubernetes/test/utils/image"
    30  )
    31  
    32  // npbEPWorkload defines a workload to run the Embarrassingly Parallel (EP) workload
    33  // from NAS parallel benchmark (NPB) suite.
    34  type npbEPWorkload struct{}
    35  
    36  // Ensure npbEPWorkload implements NodePerfWorkload interface.
    37  var _ NodePerfWorkload = &npbEPWorkload{}
    38  
    39  func (w npbEPWorkload) Name() string {
    40  	return "npb-ep"
    41  }
    42  
    43  func (w npbEPWorkload) PodSpec() v1.PodSpec {
    44  	var containers []v1.Container
    45  	ctn := v1.Container{
    46  		Name:  fmt.Sprintf("%s-ctn", w.Name()),
    47  		Image: imageutils.GetE2EImage(imageutils.NodePerfNpbEp),
    48  		Resources: v1.ResourceRequirements{
    49  			Requests: v1.ResourceList{
    50  				v1.ResourceName(v1.ResourceCPU):    resource.MustParse("15000m"),
    51  				v1.ResourceName(v1.ResourceMemory): resource.MustParse("48Gi"),
    52  			},
    53  			Limits: v1.ResourceList{
    54  				v1.ResourceName(v1.ResourceCPU):    resource.MustParse("15000m"),
    55  				v1.ResourceName(v1.ResourceMemory): resource.MustParse("48Gi"),
    56  			},
    57  		},
    58  		Command: []string{"/bin/sh"},
    59  		Args:    []string{"-c", "/ep.D.x"},
    60  	}
    61  	containers = append(containers, ctn)
    62  
    63  	return v1.PodSpec{
    64  		RestartPolicy: v1.RestartPolicyNever,
    65  		Containers:    containers,
    66  	}
    67  }
    68  
    69  func (w npbEPWorkload) Timeout() time.Duration {
    70  	return 10 * time.Minute
    71  }
    72  
    73  func (w npbEPWorkload) KubeletConfig(oldCfg *kubeletconfig.KubeletConfiguration) (newCfg *kubeletconfig.KubeletConfiguration, err error) {
    74  	// Enable CPU Manager in Kubelet with static policy.
    75  	newCfg = oldCfg.DeepCopy()
    76  	// Set the CPU Manager policy to static.
    77  	newCfg.CPUManagerPolicy = string(cpumanager.PolicyStatic)
    78  	// Set the CPU Manager reconcile period to 10 second.
    79  	newCfg.CPUManagerReconcilePeriod = metav1.Duration{Duration: 10 * time.Second}
    80  
    81  	// The Kubelet panics if either kube-reserved or system-reserved is not set
    82  	// when static CPU Manager is enabled. Set cpu in kube-reserved > 0 so that
    83  	// kubelet doesn't panic.
    84  	if newCfg.KubeReserved == nil {
    85  		newCfg.KubeReserved = map[string]string{}
    86  	}
    87  
    88  	if _, ok := newCfg.KubeReserved["cpu"]; !ok {
    89  		newCfg.KubeReserved["cpu"] = "200m"
    90  	}
    91  
    92  	return newCfg, nil
    93  }
    94  
    95  func (w npbEPWorkload) PreTestExec() error {
    96  	cmd := "/bin/sh"
    97  	args := []string{"-c", "rm -f /var/lib/kubelet/cpu_manager_state"}
    98  	err := runCmd(cmd, args)
    99  
   100  	return err
   101  }
   102  
   103  func (w npbEPWorkload) PostTestExec() error {
   104  	cmd := "/bin/sh"
   105  	args := []string{"-c", "rm -f /var/lib/kubelet/cpu_manager_state"}
   106  	err := runCmd(cmd, args)
   107  
   108  	return err
   109  }
   110  
   111  func (w npbEPWorkload) ExtractPerformanceFromLogs(logs string) (perf time.Duration, err error) {
   112  	perfLine, err := getMatchingLineFromLog(logs, "Time in seconds =")
   113  	if err != nil {
   114  		return perf, err
   115  	}
   116  	perfStrings := strings.Split(perfLine, "=")
   117  	perfString := fmt.Sprintf("%ss", strings.TrimSpace(perfStrings[1]))
   118  	perf, err = time.ParseDuration(perfString)
   119  
   120  	return perf, err
   121  }
   122  

View as plain text