npb_is.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. Copyright 2018 The Kubernetes Authors.
  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. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package workloads
  14. import (
  15. "fmt"
  16. "strings"
  17. "time"
  18. v1 "k8s.io/api/core/v1"
  19. "k8s.io/apimachinery/pkg/api/resource"
  20. kubeletconfig "k8s.io/kubernetes/pkg/kubelet/apis/config"
  21. )
  22. // npbISWorkload defines a workload to run the integer sort (IS) workload
  23. // from NAS parallel benchmark (NPB) suite.
  24. type npbISWorkload struct{}
  25. // Ensure npbISWorkload implements NodePerfWorkload interface.
  26. var _ NodePerfWorkload = &npbISWorkload{}
  27. func (w npbISWorkload) Name() string {
  28. return "npb-is"
  29. }
  30. func (w npbISWorkload) PodSpec() v1.PodSpec {
  31. var containers []v1.Container
  32. ctn := v1.Container{
  33. Name: fmt.Sprintf("%s-ctn", w.Name()),
  34. Image: "gcr.io/kubernetes-e2e-test-images/node-perf/npb-is:1.0",
  35. Resources: v1.ResourceRequirements{
  36. Requests: v1.ResourceList{
  37. v1.ResourceName(v1.ResourceCPU): resource.MustParse("16000m"),
  38. v1.ResourceName(v1.ResourceMemory): resource.MustParse("48Gi"),
  39. },
  40. Limits: v1.ResourceList{
  41. v1.ResourceName(v1.ResourceCPU): resource.MustParse("16000m"),
  42. v1.ResourceName(v1.ResourceMemory): resource.MustParse("48Gi"),
  43. },
  44. },
  45. Command: []string{"/bin/sh"},
  46. Args: []string{"-c", "/is.D.x"},
  47. }
  48. containers = append(containers, ctn)
  49. return v1.PodSpec{
  50. RestartPolicy: v1.RestartPolicyNever,
  51. Containers: containers,
  52. }
  53. }
  54. func (w npbISWorkload) Timeout() time.Duration {
  55. return 4 * time.Minute
  56. }
  57. func (w npbISWorkload) KubeletConfig(oldCfg *kubeletconfig.KubeletConfiguration) (newCfg *kubeletconfig.KubeletConfiguration, err error) {
  58. return oldCfg, nil
  59. }
  60. func (w npbISWorkload) PreTestExec() error {
  61. return nil
  62. }
  63. func (w npbISWorkload) PostTestExec() error {
  64. return nil
  65. }
  66. func (w npbISWorkload) ExtractPerformanceFromLogs(logs string) (perf time.Duration, err error) {
  67. perfLine, err := getMatchingLineFromLog(logs, "Time in seconds =")
  68. if err != nil {
  69. return perf, err
  70. }
  71. perfStrings := strings.Split(perfLine, "=")
  72. perfString := fmt.Sprintf("%ss", strings.TrimSpace(perfStrings[1]))
  73. perf, err = time.ParseDuration(perfString)
  74. return perf, err
  75. }