Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize the decoding of SampleStream #5349

Merged
merged 3 commits into from
May 17, 2023

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 <alanprot@gmail.com>
alanprot added 2 commits May 16, 2023 15:10
Signed-off-by: Alan Protasio <alanprot@gmail.com>
Signed-off-by: Alan Protasio <alanprot@gmail.com>
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!

@@ -83,6 +83,31 @@ type Request interface {
WithStats(stats string) Request
}

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