github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/cdc/scheduler/internal/v3/agent/agent_bench_test.go (about) 1 // Copyright 2022 PingCAP, Inc. 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 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package agent 15 16 import ( 17 "fmt" 18 "testing" 19 20 "github.com/pingcap/tiflow/cdc/model" 21 "github.com/pingcap/tiflow/cdc/scheduler/schedulepb" 22 "github.com/pingcap/tiflow/pkg/spanz" 23 ) 24 25 func benchmarkHeartbeatResponse(b *testing.B, bench func(b *testing.B, a *agent)) { 26 upperBound := 16384 27 for size := 1; size <= upperBound; size *= 2 { 28 tableExec := newMockTableExecutor() 29 liveness := model.LivenessCaptureAlive 30 a := &agent{ 31 tableM: newTableSpanManager(model.ChangeFeedID{}, tableExec), 32 liveness: &liveness, 33 } 34 35 for j := 0; j < size; j++ { 36 span := spanz.TableIDToComparableSpan(model.TableID(10000 + j)) 37 _ = a.tableM.addTableSpan(span) 38 } 39 40 b.ResetTimer() 41 bench(b, a) 42 b.StopTimer() 43 } 44 } 45 46 func BenchmarkRefreshAllTables(b *testing.B) { 47 benchmarkHeartbeatResponse(b, func(b *testing.B, a *agent) { 48 total := a.tableM.tables.Len() 49 b.Run(fmt.Sprintf("%d tables", total), func(b *testing.B) { 50 for i := 0; i < b.N; i++ { 51 a.handleMessageHeartbeat(&schedulepb.Heartbeat{}) 52 } 53 }) 54 }) 55 }