istio

Форк
0
/
metrics_test.go 
79 строк · 1.7 Кб
1
// Copyright Istio Authors
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
package queue
15

16
import (
17
	"sync"
18
	"testing"
19
	"time"
20

21
	"istio.io/istio/pilot/pkg/features"
22
)
23

24
func BenchmarkMetricsQueue(b *testing.B) {
25
	features.EnableControllerQueueMetrics = true
26
	q := NewQueue(1 * time.Microsecond)
27
	s := make(chan struct{})
28
	go q.Run(s)
29
	for n := 0; n < b.N; n++ {
30
		wg := sync.WaitGroup{}
31
		wg.Add(1)
32
		q.Push(func() error {
33
			wg.Done()
34
			return nil
35
		})
36
		wg.Wait()
37

38
	}
39
	close(s)
40
}
41

42
func BenchmarkMetricsQueueDisabled(b *testing.B) {
43
	features.EnableControllerQueueMetrics = false
44
	q := NewQueue(1 * time.Microsecond)
45
	s := make(chan struct{})
46
	go q.Run(s)
47
	for n := 0; n < b.N; n++ {
48
		wg := sync.WaitGroup{}
49
		wg.Add(1)
50
		q.Push(func() error {
51
			wg.Done()
52
			return nil
53
		})
54
		wg.Wait()
55
	}
56
	close(s)
57
}
58

59
func BenchmarkMetricsQueueInc(b *testing.B) {
60
	q := newQueueMetrics("test")
61
	for n := 0; n < b.N; n++ {
62
		q.depth.Increment()
63
	}
64
}
65

66
func BenchmarkMetricsQueueRec(b *testing.B) {
67
	q := newQueueMetrics("test")
68
	for n := 0; n < b.N; n++ {
69
		q.depth.Record(100)
70
	}
71
}
72

73
func BenchmarkMetricsQueueSinceInSeconds(b *testing.B) {
74
	q := newQueueMetrics("test")
75
	dt := time.Now()
76
	for n := 0; n < b.N; n++ {
77
		q.sinceInSeconds(dt)
78
	}
79
}
80

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.