@@ -31,6 +31,7 @@ import (
31
31
"github.com/stretchr/testify/require"
32
32
33
33
"vitess.io/vitess/go/test/utils"
34
+ "vitess.io/vitess/go/vt/concurrency"
34
35
"vitess.io/vitess/go/vt/grpcclient"
35
36
"vitess.io/vitess/go/vt/topo"
36
37
"vitess.io/vitess/go/vt/topo/memorytopo"
@@ -1513,6 +1514,66 @@ func TestConcurrentUpdates(t *testing.T) {
1513
1514
}, 5 * time .Second , 100 * time .Millisecond , "expected all updates to be processed" )
1514
1515
}
1515
1516
1517
+ // BenchmarkAccess_FastConsumer benchmarks the access time of the healthcheck for a fast consumer.
1518
+ func BenchmarkAccess_FastConsumer (b * testing.B ) {
1519
+ ctx := context .Background ()
1520
+ // reset error counters
1521
+ hcErrorCounters .ResetAll ()
1522
+ ts := memorytopo .NewServer (ctx , "cell" )
1523
+ defer ts .Close ()
1524
+ hc := createTestHc (ctx , ts )
1525
+ // close healthcheck
1526
+ defer hc .Close ()
1527
+
1528
+ // Subscribe to the healthcheck with a fast consumer.
1529
+ ch := hc .Subscribe ()
1530
+ go func () {
1531
+ for range ch {
1532
+ }
1533
+ }()
1534
+
1535
+ for i := 0 ; i < b .N ; i ++ {
1536
+ hc .broadcast (& TabletHealth {})
1537
+ }
1538
+ hc .Unsubscribe (ch )
1539
+ waitForEmptyMessageQueue (hc .subscribers [ch ])
1540
+ }
1541
+
1542
+ // BenchmarkAccess_SlowConsumer benchmarks the access time of the healthcheck for a slow consumer.
1543
+ func BenchmarkAccess_SlowConsumer (b * testing.B ) {
1544
+ ctx := context .Background ()
1545
+ // reset error counters
1546
+ hcErrorCounters .ResetAll ()
1547
+ ts := memorytopo .NewServer (ctx , "cell" )
1548
+ defer ts .Close ()
1549
+ hc := createTestHc (ctx , ts )
1550
+ // close healthcheck
1551
+ defer hc .Close ()
1552
+
1553
+ // Subscribe to the healthcheck with a fast consumer.
1554
+ ch := hc .Subscribe ()
1555
+ go func () {
1556
+ for range ch {
1557
+ time .Sleep (100 * time .Second )
1558
+ }
1559
+ }()
1560
+
1561
+ for i := 0 ; i < b .N ; i ++ {
1562
+ hc .broadcast (& TabletHealth {})
1563
+ }
1564
+ hc .Unsubscribe (ch )
1565
+ waitForEmptyMessageQueue (hc .subscribers [ch ])
1566
+ }
1567
+
1568
+ func waitForEmptyMessageQueue (queue * concurrency.MessageQueue [* TabletHealth ]) {
1569
+ for {
1570
+ if queue .Length () == 0 {
1571
+ return
1572
+ }
1573
+ time .Sleep (100 * time .Millisecond )
1574
+ }
1575
+ }
1576
+
1516
1577
func tabletDialer (ctx context.Context , tablet * topodatapb.Tablet , _ grpcclient.FailFast ) (queryservice.QueryService , error ) {
1517
1578
connMapMu .Lock ()
1518
1579
defer connMapMu .Unlock ()
0 commit comments