1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
// +build postgres
package reconciler
import (
"fmt"
"testing"
"github.com/prometheus/client_golang/prometheus"
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/v14/internal/praefect"
"gitlab.com/gitlab-org/gitaly/v14/internal/testhelper"
)
func BenchmarkReconcile(b *testing.B) {
for _, numberOfRepositories := range []int{1000, 10_000, 100_000, 1_000_000} {
b.Run(fmt.Sprintf("%d", numberOfRepositories), func(b *testing.B) {
b.Run("best case", func(b *testing.B) {
benchmarkReconcile(b, numberOfRepositories, false)
})
b.Run("worst case", func(b *testing.B) {
benchmarkReconcile(b, numberOfRepositories, true)
})
})
}
}
func benchmarkReconcile(b *testing.B, numRepositories int, worstCase bool) {
b.StopTimer()
ctx, cancel := testhelper.Context()
defer cancel()
db := getDB(b)
behind := 0
if worstCase {
// 2 out of 3 storages will be outdated and in need of replication
behind = 1
}
_, err := db.ExecContext(ctx, `
WITH repositories AS (
INSERT INTO repositories
SELECT 'virtual-storage-1', 'repository-'|| SERIES.INDEX, 5
FROM GENERATE_SERIES(1, $1) SERIES(INDEX)
RETURNING virtual_storage, relative_path, generation
)
INSERT INTO storage_repositories
SELECT
virtual_storage,
relative_path,
storage,
CASE WHEN storage = 'gitaly-1' THEN generation ELSE generation - $2 END AS generation
FROM repositories
CROSS JOIN (SELECT unnest('{gitaly-1, gitaly-2, gitaly-3}'::text[]) AS storage) AS storages
`, numRepositories, behind)
require.NoError(b, err)
storages := map[string][]string{"virtual-storage-1": {"gitaly-1", "gitaly-2", "gitaly-3"}}
for n := 0; n < b.N; n++ {
db.Truncate(b, "replication_queue", "replication_queue_lock", "replication_queue_job_lock")
r := NewReconciler(
testhelper.DiscardTestLogger(b),
db,
praefect.StaticHealthChecker(storages),
storages,
prometheus.DefBuckets,
)
b.StartTimer()
err = r.reconcile(ctx)
b.StopTimer()
require.NoError(b, err)
}
}
|