@@ -11,11 +11,13 @@ import (
11
11
"testing"
12
12
"time"
13
13
14
+ "github.com/prometheus/common/model"
14
15
"github.com/stretchr/testify/assert"
15
16
"github.com/stretchr/testify/require"
16
17
"github.com/weaveworks/common/httpgrpc"
17
18
"github.com/weaveworks/common/user"
18
19
20
+ "github.com/cortexproject/cortex/pkg/cortexpb"
19
21
"github.com/cortexproject/cortex/pkg/querier/tripperware"
20
22
)
21
23
@@ -444,3 +446,66 @@ func Test_sortPlanForQuery(t *testing.T) {
444
446
})
445
447
}
446
448
}
449
+
450
+ func Benchmark_Decode (b * testing.B ) {
451
+ maxSamplesCount := 1000000
452
+ samples := make ([]tripperware.SampleStream , maxSamplesCount )
453
+
454
+ for i := 0 ; i < maxSamplesCount ; i ++ {
455
+ samples [i ].Labels = append (samples [i ].Labels , cortexpb.LabelAdapter {Name : fmt .Sprintf ("Sample%v" , i ), Value : fmt .Sprintf ("Value%v" , i )})
456
+ samples [i ].Labels = append (samples [i ].Labels , cortexpb.LabelAdapter {Name : fmt .Sprintf ("Sample2%v" , i ), Value : fmt .Sprintf ("Value2%v" , i )})
457
+ samples [i ].Labels = append (samples [i ].Labels , cortexpb.LabelAdapter {Name : fmt .Sprintf ("Sample3%v" , i ), Value : fmt .Sprintf ("Value3%v" , i )})
458
+ samples [i ].Samples = append (samples [i ].Samples , cortexpb.Sample {TimestampMs : int64 (i ), Value : float64 (i )})
459
+ }
460
+
461
+ for name , tc := range map [string ]struct {
462
+ sampleStream []tripperware.SampleStream
463
+ }{
464
+ "100 samples" : {
465
+ sampleStream : samples [:100 ],
466
+ },
467
+ "1000 samples" : {
468
+ sampleStream : samples [:1000 ],
469
+ },
470
+ "10000 samples" : {
471
+ sampleStream : samples [:10000 ],
472
+ },
473
+ "100000 samples" : {
474
+ sampleStream : samples [:100000 ],
475
+ },
476
+ "1000000 samples" : {
477
+ sampleStream : samples [:1000000 ],
478
+ },
479
+ } {
480
+ b .Run (name , func (b * testing.B ) {
481
+ r := PrometheusInstantQueryResponse {
482
+ Data : PrometheusInstantQueryData {
483
+ ResultType : model .ValMatrix .String (),
484
+ Result : PrometheusInstantQueryResult {
485
+ Result : & PrometheusInstantQueryResult_Matrix {
486
+ Matrix : & Matrix {
487
+ SampleStreams : tc .sampleStream ,
488
+ },
489
+ },
490
+ },
491
+ },
492
+ }
493
+
494
+ body , err := json .Marshal (r )
495
+ require .NoError (b , err )
496
+
497
+ b .ResetTimer ()
498
+ b .ReportAllocs ()
499
+
500
+ for i := 0 ; i < b .N ; i ++ {
501
+ response := & http.Response {
502
+ StatusCode : 200 ,
503
+ Body : io .NopCloser (bytes .NewBuffer (body )),
504
+ }
505
+ _ , err := InstantQueryCodec .DecodeResponse (context .Background (), response , nil )
506
+ require .NoError (b , err )
507
+ }
508
+ })
509
+ }
510
+
511
+ }
0 commit comments