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
Switch from encoding/json -> jsoniter #570
Conversation
f00f2c9
to
ef34012
Compare
do you think you can add some benchmarking so we can see what is the actual performance gains? |
Fixed bug in benchmarks, for some reason the difference isn't as large as I expected:
I'll need to spend some more time on this later :/ |
any progress with this? |
Some, at this point I can confirm that the benchmarks are accurate (meaning the perf improvement isn't what I expected). So this will require more investigation, but its possible changes will be required elsewhere as well (e.g. common package). I'll try to get some more time to investigate this week. |
I've also added some marshal benchmarks (for anyone else interested):
Which seems to indicate that the improvements claims from prometheus/prometheus#3536 aren't accurate. |
SamplePair is likely the issue here, I did a custom marshalling in Prometheus for Point. As a general note we're trying to get away from common/model. |
I added Type Encoder/Decoder funcs and am now seeing the perf improvement I was expecting. This seems like a pretty ugly way to do this (since we have to copy/paste this marshal logic all over). So maybe it would be helpful to change the marshaling/unmarshaling in common to be fast?
|
It wouldn't make sense to add those to common (especially as we're trying to do away with model). What I'd suggest is more appropriate structures be defined here. |
If thats the case, then I'd just add these here for now and leave the model move for a separate PR; this is a huge perf improvement that I'd like to get in sooner. |
now with this custom Marshaling/Unmarshaling for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think it would make sense to add some benchmarking for model.Vector
as well?
We could, but since the marshaling methods are on |
Yep It makes sense. Let's leave for another PR.
how about that one? |
I copied over the tests (basically) from prom's web api. When I did so I found that |
Times are int64s, so it is permitted though I've never come across it in practice. |
2bfd73b
to
f8f16b7
Compare
api/prometheus/v1/api_bench_test.go
Outdated
return m | ||
} | ||
|
||
func BenchmarkSerialization(b *testing.B) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer a more descriptive name like: BenchmarkSamplesSerialization
or even BenchmarkSamplesJsonSerialization
or BenchmarkSamplesJsonMarshaling
@beorn7 any idea why is this test failing https://travis-ci.org/prometheus/client_golang/jobs/533629401 |
@beorn7 Fixed the imports, although it looks like the unmarshaling doesn't work for nan/inf in <1.11 of go; do we need to support those versions or are we okay to drop them? |
We have a commitment to support the last three Go minor releases at least, more if possible without undue hassle. Thus, dropping 1.9 should be fine, but for Go 1.10, we should wait for 1.13 to be out for a while. Not sure what's a good way out of this. |
@beorn7 I have checked through the release notes and I don't see why it would be fixed in that version. I have also downloaded 1.10 and run the tests locally using it and they pass, so I'm not sure why its failing in CI
|
Semi-educated guess: This has to do with Go Modules support in Go 1.11+, but not in Go 1.10 and earlier. With Go Modules, the tests use Prometheus 2.9. Without Go Modules, they use the tip of master, which has changed the encoding of the alert values. We need #585 merged to be compatible again, but we will only do that once Prometheus 2.10 is released and tagged. |
@beorn7 I don't think so? The error is marshaling a |
Thanks for the investigation. Indeed, my semi-educated guess was way too semi… My guess was right, however, about Go Modules support being the issue. Go 1.11+ take json-iterator/go at the tag v1.1.6, while the earlier Go versions take the head of master and thus include the fix. The encoding of Inf and NaN is indeed required by Prometheus. How could that have ever worked? |
Early result: The Prometheus server is not using See https://prometheus.io/docs/prometheus/latest/querying/api/#expression-query-result-formats: “JSON does not support special float values such as NaN, Inf, and -Inf, so sample values are transferred as quoted JSON strings rather than raw numbers.” |
So should we change model SamplePair to a string instead of a float64?
…On Fri, May 24, 2019, 2:26 AM Björn Rabenstein ***@***.***> wrote:
Early result: The Prometheus server is *not* using model.SamplePair to
marshal sample pairs into JSON. The sample value is represented as a string.
See
https://prometheus.io/docs/prometheus/latest/querying/api/#expression-query-result-formats:
“JSON does not support special float values such as NaN, Inf, and -Inf, so
sample values are transferred as quoted JSON strings rather than raw
numbers.”
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#570?email_source=notifications&email_token=AAMLPHPYCOTLZCBW4XWFWF3PW6YE3A5CNFSM4HLOALJKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWEVNYA#issuecomment-495539936>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAMLPHJMDO4HVABXCRKK7KLPW6YE3ANCNFSM4HLOALJA>
.
|
I'm not an expert when it comes to JSON APIs and testing thereof. Perhaps just provide the actual JSON code as reference for the test? You could also check out the prometheus/prometheus code to see how the JSON is created in the actual Prometheus API server code (which I'm not very familiar with). Just random ideas… Perhaps @krasi-georgiev has some advice. |
will check in few days. |
080bbdd
to
9299023
Compare
@beorn7 @krasi-georgiev I have updated the PR to support this. Since we are already implementing our own marshal, I'm just doing the write as bytes instead of as a float64 -- this version works on jsoniter master. |
Is there trailing whitespace in ./api/prometheus/v1/api.go L94? |
@krasi-georgiev besides the formatting nit, does this look good to you? |
Signed-off-by: Thomas Jackson <jacksontj.89@gmail.com> Fixes prometheus#565
Signed-off-by: Thomas Jackson <jacksontj.89@gmail.com>
ran go fmt (fixed the whitespace), the CI run should pass now. |
And that test failure I've seen before that test is flaky for some reason :/ I don't see how I can re-trigger the tests -- I assume a maintainer has to do that? |
Restarted the flaky test. (I have #573 in my pipeline to unflake.) |
@beorn7 tests have passed, so we should be good for a merge |
I'll just wait for 👍 from @krasi-georgiev as he is the maintainer of this code. |
back to full speed work mode in 1-2 days so will approve soon. |
Signed-off-by: Thomas Jackson jacksontj.89@gmail.com
Fixes #565