Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests(filter): add some benchmark for index match #838

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions filter/pattern_index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,55 @@ func TestPatternIndex(t *testing.T) {
}
})
}

func BenchmarkPatternIndex(b *testing.B) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

мб это перетащить лучше в perfomance_tests/filter?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Там более высокоуровневые тесты, вот и не стал складывать туда. Это скорее бенчмарк самих хранилищ. Но можно и туда, если считаешь. Другой вопрос, надо ли эти тесты вам ? Собственно зачем они.

Я тут делаю подобную библиотечку для матчинга у себя. Вот и хотел для сравнения. Результаты пока интересные - реализация с префиксными деревьями похожа по производительности на реализацию в Мойре. А реализация без (с индивидуальной проверкой по каждому правилу) оказалась ощутимо быстрее - в 3,5 раза примерно. Подтяну еще может тесты из perofmance_tests/filter. Пусть PR пока повесит - вызреет.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

помечу пр как драфт тогда пока

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

реализация с префиксными деревьями похожа по производительности на реализацию в Мойре - в мойре же как раз префиксное дерево :)

logger, _ := logging.GetLogger("PatternIndex")

patterns := []string{
"Simple.matching.pattern",
"Simple.matching.pattern.*",
"Star.single.*",
"Star.*.double.any*",
"Bracket.{one,two,three}.pattern",
"Bracket.pr{one,two,three}suf",
"Complex.matching.pattern",
"Complex.*.*",
"Complex.*.",
"Complex.*{one,two,three}suf*.pattern",
"Question.?at_begin",
"Question.at_the_end?",
}

metrics := []string{"Simple.matching.pattern",
"Star.single.anything",
"Star.anything.double.anything",
"Bracket.one.pattern",
"Bracket.two.pattern",
"Bracket.three.pattern",
"Bracket.pronesuf",
"Bracket.prtwosuf",
"Bracket.prthreesuf",
"Complex.matching.pattern",
"Complex.anything.pattern",
"Complex.prefixonesuffix.pattern",
"Complex.prefixtwofix.pattern",
"Complex.anything.pattern",
"Question.1at_begin",
"Question.at_the_end2",
"Two.dots..together",
"Simple.notmatching.pattern",
"Star.nothing",
"Bracket.one.nothing",
"Bracket.nothing.pattern",
"Complex.prefixonesuffix",
}

index := NewPatternIndex(logger, patterns)

b.ResetTimer()
for i := 0; i < b.N; i++ {
for j := 0; j < len(metrics); j++ {
_ = index.MatchPatterns(metrics[j])
}
}
}
55 changes: 55 additions & 0 deletions filter/series_by_tag_pattern_index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,58 @@ func TestSeriesByTagPatternIndex(t *testing.T) {
}
})
}

func BenchmarkSeriesByTagPatternIndex(b *testing.B) {
var logger, _ = logging.GetLogger("SeriesByTag")

tagSpecsByPattern := map[string][]TagSpec{
"name=cpu.test1.test2": {{"name", EqualOperator, "cpu.test1.test2"}},
"name=cpu.*.test2": {{"name", EqualOperator, "cpu.*.test2"}},
"name=cpu.test1.*": {{"name", EqualOperator, "cpu.test1.*"}},
"name=cpu.*.*": {{"name", EqualOperator, "cpu.*.*"}},

"name=cpu.*.test2;tag1=val1": {
{"name", EqualOperator, "cpu.*.test2"},
{"tag1", EqualOperator, "val1"}},
"name=cpu.*.test2;tag2=val2": {
{"name", EqualOperator, "cpu.*.test2"},
{"tag2", EqualOperator, "val2"}},
"name=cpu.*.test2;tag1=val1;tag2=val2": {
{"name", EqualOperator, "cpu.*.test2"},
{"tag1", EqualOperator, "val1"},
{"tag2", EqualOperator, "val2"}},

"name!=cpu.test1.test2;tag1=val1;tag2=val2": {
{"name", NotEqualOperator, "cpu.test1.test2"},
{"tag1", EqualOperator, "val1"},
{"tag2", EqualOperator, "val2"}},
"name=~cpu;tag1=val1": {
{"name", MatchOperator, "cpu"},
{"tag1", EqualOperator, "val1"}},
"tag1=val1;tag2=val2": {
{"tag1", EqualOperator, "val1"},
{"tag2", EqualOperator, "val2"}},
}

testCases := []struct {
Name string
Labels map[string]string
}{
{"cpu.test1.test2", map[string]string{}},
{"cpu.test1.test2", map[string]string{"tag": "val"}},
{"cpu.test1.test2", map[string]string{"tag1": "val1"}},
{"cpu.test1.test2", map[string]string{"tag1": "val2"}},
{"cpu.test1.test2", map[string]string{"tag1": "val1", "tag2": "val1"}},
{"cpu.test1.test2", map[string]string{"tag2": "val2"}},
{"cpu.test1.test2", map[string]string{"tag1": "val1", "tag2": "val2"}},
}

index := NewSeriesByTagPatternIndex(logger, tagSpecsByPattern)

b.ResetTimer()
for i := 0; i < b.N; i++ {
for j := 0; j < len(testCases); j++ {
_ = index.MatchPatterns(testCases[j].Name, testCases[j].Labels)
}
}
}