grafana/pkg/services/accesscontrol/migrator/migrator_bench_test.go
Gabriel MABILLE 261045d182
RBAC: Batch update on scope split migration (#72182)
* RBAC: Make the SplitScope migration concurrent

* Benchmark multiple alternatives: (updates in a loop, batch update, concurrent batch update)

* Only keep batching since mysql 5.7 does not seem to support concurrent batching

* Update pkg/services/accesscontrol/migrator/migrator.go

Co-authored-by: Ieva <ieva.vasiljeva@grafana.com>

---------

Co-authored-by: Ieva <ieva.vasiljeva@grafana.com>
2023-07-28 12:37:24 +02:00

28 lines
727 B
Go

package migrator
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/infra/db"
"github.com/grafana/grafana/pkg/infra/log"
)
func benchScopeSplitConcurrent(b *testing.B, count int) {
store := db.InitTestDB(b)
// Populate permissions
require.NoError(b, batchInsertPermissions(count, store), "could not insert permissions")
logger := log.New("migrator.test")
b.ResetTimer()
for n := 0; n < b.N; n++ {
err := MigrateScopeSplit(store, logger)
require.NoError(b, err)
}
}
func BenchmarkMigrateScopeSplitConcurrent_50K(b *testing.B) { benchScopeSplitConcurrent(b, 50000) }
func BenchmarkMigrateScopeSplitConcurrent_100K(b *testing.B) { benchScopeSplitConcurrent(b, 100000) }