@@ -19,6 +19,7 @@ import (
19
19
"fmt"
20
20
"os"
21
21
"path"
22
+ "strconv"
22
23
"strings"
23
24
"testing"
24
25
"text/template"
@@ -34,10 +35,12 @@ import (
34
35
"istio.io/istio/pilot/pkg/config/kube/crd"
35
36
"istio.io/istio/pilot/pkg/features"
36
37
"istio.io/istio/pilot/pkg/model"
38
+ "istio.io/istio/pilot/pkg/networking/core/v1alpha3/route"
37
39
"istio.io/istio/pilot/pkg/networking/util"
38
40
v3 "istio.io/istio/pilot/pkg/xds/v3"
39
41
"istio.io/istio/pilot/test/xdstest"
40
42
"istio.io/istio/pkg/config"
43
+ "istio.io/istio/pkg/config/host"
41
44
"istio.io/istio/pkg/config/mesh"
42
45
"istio.io/istio/pkg/config/schema/collections"
43
46
"istio.io/istio/pkg/config/schema/gvk"
@@ -554,3 +557,57 @@ func BenchmarkPushRequest(b *testing.B) {
554
557
}
555
558
}
556
559
}
560
+
561
+ func makeCacheKey (n int ) model.XdsCacheEntry {
562
+ ns := strconv .Itoa (n )
563
+ key := & route.Cache {
564
+ RouteName : "something" ,
565
+ ClusterID : "my-cluster" ,
566
+ DNSDomain : "some.domain.example.com" ,
567
+ DNSCapture : true ,
568
+ DNSAutoAllocate : false ,
569
+ ListenerPort : 1234 ,
570
+ Services : []* model.Service {
571
+ {Hostname : host .Name (ns + "some1.example.com" ), Attributes : model.ServiceAttributes {Namespace : "test1" }},
572
+ {Hostname : host .Name (ns + "some2.example.com" ), Attributes : model.ServiceAttributes {Namespace : "test2" }},
573
+ },
574
+ DestinationRules : []* config.Config {
575
+ {Meta : config.Meta {Name : ns + "a" , Namespace : "b" }},
576
+ {Meta : config.Meta {Name : ns + "d" , Namespace : "e" }},
577
+ },
578
+ EnvoyFilterKeys : []string {ns + "1/a" , ns + "2/b" , ns + "3/c" },
579
+ }
580
+ return key
581
+ }
582
+
583
+ func BenchmarkCache (b * testing.B ) {
584
+ // Ensure cache doesn't grow too large
585
+ test .SetIntForTest (b , & features .XDSCacheMaxSize , 1_000 )
586
+ res := & discovery.Resource {Name : "test" }
587
+ zeroTime := time.Time {}
588
+ b .Run ("key" , func (b * testing.B ) {
589
+ key := makeCacheKey (1 )
590
+ for n := 0 ; n < b .N ; n ++ {
591
+ _ = key .Key ()
592
+ }
593
+ })
594
+ b .Run ("insert" , func (b * testing.B ) {
595
+ c := model .NewXdsCache ()
596
+
597
+ for n := 0 ; n < b .N ; n ++ {
598
+ key := makeCacheKey (n )
599
+ req := & model.PushRequest {Start : zeroTime .Add (time .Duration (n ))}
600
+ c .Add (key , req , res )
601
+ }
602
+ })
603
+ b .Run ("get" , func (b * testing.B ) {
604
+ c := model .NewXdsCache ()
605
+
606
+ key := makeCacheKey (1 )
607
+ req := & model.PushRequest {Start : zeroTime .Add (time .Duration (1 ))}
608
+ c .Add (key , req , res )
609
+ for n := 0 ; n < b .N ; n ++ {
610
+ c .Get (key )
611
+ }
612
+ })
613
+ }
0 commit comments