benchmark_util.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. // +build linux
  2. /*
  3. Copyright 2015 The Kubernetes Authors.
  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. http://www.apache.org/licenses/LICENSE-2.0
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. */
  14. package e2e_node
  15. import (
  16. "sort"
  17. "time"
  18. "k8s.io/kubernetes/pkg/api/unversioned"
  19. "k8s.io/kubernetes/test/e2e/framework"
  20. "k8s.io/kubernetes/test/e2e/perftype"
  21. )
  22. const (
  23. // TODO(coufon): be consistent with perf_util.go version
  24. currentDataVersion = "v1"
  25. TimeSeriesTag = "[Result:TimeSeries]"
  26. TimeSeriesEnd = "[Finish:TimeSeries]"
  27. )
  28. type NodeTimeSeries struct {
  29. // value in OperationData is an array of timestamps
  30. OperationData map[string][]int64 `json:"op_series,omitempty"`
  31. ResourceData map[string]*ResourceSeries `json:"resource_series,omitempty"`
  32. Labels map[string]string `json:"labels"`
  33. Version string `json:"version"`
  34. }
  35. // logDensityTimeSeries logs the time series data of operation and resource usage
  36. func logDensityTimeSeries(rc *ResourceCollector, create, watch map[string]unversioned.Time, testName string) {
  37. timeSeries := &NodeTimeSeries{
  38. Labels: map[string]string{
  39. "node": framework.TestContext.NodeName,
  40. "test": testName,
  41. },
  42. Version: currentDataVersion,
  43. }
  44. // Attach operation time series.
  45. timeSeries.OperationData = map[string][]int64{
  46. "create": getCumulatedPodTimeSeries(create),
  47. "running": getCumulatedPodTimeSeries(watch),
  48. }
  49. // Attach resource time series.
  50. timeSeries.ResourceData = rc.GetResourceTimeSeries()
  51. // Log time series with tags
  52. framework.Logf("%s %s\n%s", TimeSeriesTag, framework.PrettyPrintJSON(timeSeries), TimeSeriesEnd)
  53. }
  54. type int64arr []int64
  55. func (a int64arr) Len() int { return len(a) }
  56. func (a int64arr) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
  57. func (a int64arr) Less(i, j int) bool { return a[i] < a[j] }
  58. // getCumulatedPodTimeSeries gets the cumulative pod number time series.
  59. func getCumulatedPodTimeSeries(timePerPod map[string]unversioned.Time) []int64 {
  60. timeSeries := make(int64arr, 0)
  61. for _, ts := range timePerPod {
  62. timeSeries = append(timeSeries, ts.Time.UnixNano())
  63. }
  64. // Sort all timestamps.
  65. sort.Sort(timeSeries)
  66. return timeSeries
  67. }
  68. // getLatencyPerfData returns perf data of pod startup latency.
  69. func getLatencyPerfData(latency framework.LatencyMetric, testName string) *perftype.PerfData {
  70. return &perftype.PerfData{
  71. Version: currentDataVersion,
  72. DataItems: []perftype.DataItem{
  73. {
  74. Data: map[string]float64{
  75. "Perc50": float64(latency.Perc50) / 1000000,
  76. "Perc90": float64(latency.Perc90) / 1000000,
  77. "Perc99": float64(latency.Perc99) / 1000000,
  78. "Perc100": float64(latency.Perc100) / 1000000,
  79. },
  80. Unit: "ms",
  81. Labels: map[string]string{
  82. "datatype": "latency",
  83. "latencytype": "create-pod",
  84. },
  85. },
  86. },
  87. Labels: map[string]string{
  88. "node": framework.TestContext.NodeName,
  89. "test": testName,
  90. },
  91. }
  92. }
  93. // getThroughputPerfData returns perf data of pod creation startup throughput.
  94. func getThroughputPerfData(batchLag time.Duration, e2eLags []framework.PodLatencyData, podsNr int, testName string) *perftype.PerfData {
  95. return &perftype.PerfData{
  96. Version: currentDataVersion,
  97. DataItems: []perftype.DataItem{
  98. {
  99. Data: map[string]float64{
  100. "batch": float64(podsNr) / batchLag.Minutes(),
  101. "single-worst": 1.0 / e2eLags[len(e2eLags)-1].Latency.Minutes(),
  102. },
  103. Unit: "pods/min",
  104. Labels: map[string]string{
  105. "datatype": "throughput",
  106. "latencytype": "create-pod",
  107. },
  108. },
  109. },
  110. Labels: map[string]string{
  111. "node": framework.TestContext.NodeName,
  112. "test": testName,
  113. },
  114. }
  115. }