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
Use jsoniter to encode object #54289
Use jsoniter to encode object #54289
Conversation
standard encoding/json has performance issue,use jsoniter can help to reduce half of the encoding time. Signed-off-by: Peng Gao <peng.gao.dut@gmail.com>
Hi @ggaaooppeenngg. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: ggaaooppeenngg Assign the PR to them by writing No associated issue. Update pull-request body to add a reference to an issue, or get approval with The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these OWNERS Files:
You can indicate your approval by writing |
/assign @caesarxuchao |
I just see only this entry in the whole file using |
/cc @thockin |
I think it's ok to remove |
/ok-to-test |
it doesn't appear that jsoniter normalizes key order:
stable order is required |
@thockin did you exercise encoding in jsoniter as thoroughly as decoding? |
Signed-off-by: Peng Gao <peng.gao.dut@gmail.com>
Signed-off-by: Peng Gao <peng.gao.dut@gmail.com>
@@ -216,7 +215,7 @@ func (s *Serializer) Encode(obj runtime.Object, w io.Writer) error { | |||
_, err = w.Write(data) | |||
return err | |||
} | |||
encoder := json.NewEncoder(w) | |||
encoder := jsoniter.ConfigCompatibleWithStandardLibrary.NewEncoder(w) |
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.
Everything looks OK except this. Doesn't this have a negative impact of performance? It did when I measured it.
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 offered a bench commit, on my machine it's
pkg: k8s.io/kubernetes/staging/src/k8s.io/apimachinery/pkg/runtime/serializer/json
BenchmarkJsonEncoding-4 3000000 569 ns/op
BenchmarkJsoniterEncoding-4 5000000 316 ns/op
And from my cluster testing, the time share decreases from 60%s to 25%. How did you measure it?
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.
The benchmark doesn't use data that is similar to actual objects; can you get e.g. a big pod spec or something and run again?
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.
@lavalamp I pushed a commit, the result was not better, but just 20% improved.
pkg: k8s.io/kubernetes/staging/src/k8s.io/apimachinery/pkg/runtime/serializer/json
BenchmarkJsonEncoding-4 100000 13080 ns/op
BenchmarkJsoniterEncoding-4 200000 11158 ns/op
PASS
Signed-off-by: Peng Gao <peng.gao.dut@gmail.com>
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 made up a large pod for benchmark.
@@ -216,7 +215,7 @@ func (s *Serializer) Encode(obj runtime.Object, w io.Writer) error { | |||
_, err = w.Write(data) | |||
return err | |||
} | |||
encoder := json.NewEncoder(w) | |||
encoder := jsoniter.ConfigCompatibleWithStandardLibrary.NewEncoder(w) |
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.
@lavalamp I pushed a commit, the result was not better, but just 20% improved.
pkg: k8s.io/kubernetes/staging/src/k8s.io/apimachinery/pkg/runtime/serializer/json
BenchmarkJsonEncoding-4 100000 13080 ns/op
BenchmarkJsoniterEncoding-4 200000 11158 ns/op
PASS
Signed-off-by: Peng Gao <peng.gao.dut@gmail.com>
2661810
to
f8c34c5
Compare
/retest |
1 similar comment
/retest |
consistent failure:
|
Signed-off-by: Peng Gao <peng.gao.dut@gmail.com>
Signed-off-by: Peng Gao <peng.gao.dut@gmail.com>
Signed-off-by: Peng Gao <peng.gao.dut@gmail.com>
@ggaaooppeenngg: The following tests failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
In order to make json-iter to be compatible with standard library, it needs some work, wait for the lib stable then open it again. |
standard encoding/json has performance issue, use jsoniter
can help to reduce half of the encoding time.
Signed-off-by: Peng Gao peng.gao.dut@gmail.com
What this PR does / why we need it:
This PR change encoding/json to jsoniter, from the profiling it reduce the half of processing time.
Which issue this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)
format, will close that issue when PR gets merged): fixes #Special notes for your reviewer:
Release note:
/sig api-machinery