Skip to content

Conversation

alanprot
Copy link
Member

@alanprot alanprot commented May 16, 2023

What this PR does:
Create jsoniter SampleStream Decoder to optimize its deserialization.

QueryFrontend can benefit from this as it deserialize the responses from the queriers:

goos: linux
goarch: amd64
pkg: github.com/cortexproject/cortex/pkg/querier/tripperware/instantquery
cpu: Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz
                           │   /tmp/old   │              /tmp/new               │
                           │    sec/op    │    sec/op     vs base               │
_Decode/100_samples-32       280.5µ ± ∞ ¹   209.3µ ± ∞ ¹  -25.36% (p=0.008 n=5)
_Decode/1000_samples-32      2.875m ± ∞ ¹   2.133m ± ∞ ¹  -25.82% (p=0.008 n=5)
_Decode/10000_samples-32     28.83m ± ∞ ¹   21.55m ± ∞ ¹  -25.24% (p=0.008 n=5)
_Decode/100000_samples-32    304.5m ± ∞ ¹   247.3m ± ∞ ¹  -18.79% (p=0.008 n=5)
_Decode/1000000_samples-32    3.060 ± ∞ ¹    2.379 ± ∞ ¹  -22.27% (p=0.008 n=5)
geomean                      29.32m         22.42m        -23.54%
¹ need >= 6 samples for confidence interval at level 0.95

                           │   /tmp/old    │               /tmp/new               │
                           │     B/op      │     B/op       vs base               │
_Decode/100_samples-32       129.3Ki ± ∞ ¹   109.1Ki ± ∞ ¹  -15.67% (p=0.008 n=5)
_Decode/1000_samples-32      1.213Mi ± ∞ ¹   1.001Mi ± ∞ ¹  -17.49% (p=0.008 n=5)
_Decode/10000_samples-32     15.64Mi ± ∞ ¹   13.36Mi ± ∞ ¹  -14.53% (p=0.008 n=5)
_Decode/100000_samples-32    150.7Mi ± ∞ ¹   127.8Mi ± ∞ ¹  -15.18% (p=0.008 n=5)
_Decode/1000000_samples-32   1.422Gi ± ∞ ¹   1.185Gi ± ∞ ¹  -16.66% (p=0.008 n=5)
geomean                      13.93Mi         11.72Mi        -15.91%
¹ need >= 6 samples for confidence interval at level 0.95

                           │   /tmp/old   │              /tmp/new               │
                           │  allocs/op   │  allocs/op    vs base               │
_Decode/100_samples-32       2.839k ± ∞ ¹   2.239k ± ∞ ¹  -21.13% (p=0.008 n=5)
_Decode/1000_samples-32      28.05k ± ∞ ¹   22.05k ± ∞ ¹  -21.39% (p=0.008 n=5)
_Decode/10000_samples-32     280.1k ± ∞ ¹   220.1k ± ∞ ¹  -21.42% (p=0.008 n=5)
_Decode/100000_samples-32    2.800M ± ∞ ¹   2.200M ± ∞ ¹  -21.43% (p=0.008 n=5)
_Decode/1000000_samples-32   28.00M ± ∞ ¹   22.00M ± ∞ ¹  -21.43% (p=0.008 n=5)
geomean                      280.9k         220.9k        -21.36%
¹ need >= 6 samples for confidence interval at level 0.95

Which issue(s) this PR fixes:
Fixes #

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

Signed-off-by: Alan Protasio <[email protected]>
alanprot added 2 commits May 16, 2023 15:10
Signed-off-by: Alan Protasio <[email protected]>
Signed-off-by: Alan Protasio <[email protected]>
Copy link
Contributor

@yeya24 yeya24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good!


func decodeSampleStream(ptr unsafe.Pointer, iter *jsoniter.Iterator) {
lbls := labels.Labels{}
samples := []cortexpb.Sample{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it could be beneficial to preallocate the buffer here, but we can leave it as it is now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah.. i just did not know the number of samples beforehand... but maybe put something like 100 should be ok?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes a default value is fine.

@yeya24 yeya24 merged commit 0c41288 into cortexproject:master May 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants