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
structured-logging: replace KObjs with KObjSlice for logging #110747
structured-logging: replace KObjs with KObjSlice for logging #110747
Conversation
Skipping CI for Draft Pull Request. |
/remove-sig api-machinery |
bdca75c
to
711364b
Compare
@@ -951,9 +951,7 @@ func (qs *queueSet) boundNextDispatchLocked(queue *queue) { | |||
} | |||
var virtualStartBound = oldestReqFromMinQueue.arrivalR | |||
if queue.nextDispatchR < virtualStartBound { | |||
if klogV := klog.V(4); klogV.Enabled() { |
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.
Working on benchmarking this function. Will update once i have the details here.
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 had no success in getting a clean way to write a benchmark test for this function. Any suggestion on this @pohly ?
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.
If the SIG doesn't already have benchmarks, then writing one is hard because it depends on domain knowledge.
When in doubt, leave the if check in place.
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.
Ack
/test all |
/test pull-kubernetes-conformance-kind-ga-only-parallel |
/test pull-kubernetes-e2e-gce-storage-snapshot |
1 similar comment
/test pull-kubernetes-e2e-gce-storage-snapshot |
@pohly Sure. Let me update the title of the PR accordingly. Is the current description in PR good enough or do you want me to add a bit more context ? |
The PR description is perfect. Lots of context and additional information. |
/assign @pohly |
/remove-sig api-machinery |
711364b
to
c3cbc44
Compare
if klogV := klog.V(2); klogV.Enabled() { | ||
klogV.InfoS("Found related ReplicaSets", "replicaSet", klog.KObj(rs), "relatedReplicaSets", klog.KObjs(relatedRSs)) | ||
klogV.InfoS("Found related ReplicaSets", "replicaSet", klog.KObj(rs), "relatedReplicaSets", klog.KObjSlice(relatedRSs)) |
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.
Here you can simplify the code and remove the if check.
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.
There was an existing benhmark for this already. Doing the check removal made it worse.
# With Changes
BenchmarkGetReplicaSetsWithSameController
BenchmarkGetReplicaSetsWithSameController-12 3291576 355.9 ns/op 184 B/op 6 allocs/op
BenchmarkGetReplicaSetsWithSameController-12 3359475 360.1 ns/op 184 B/op 6 allocs/op
BenchmarkGetReplicaSetsWithSameController-12 3335294 368.1 ns/op 184 B/op 6 allocs/op
BenchmarkGetReplicaSetsWithSameController-12 3296937 361.2 ns/op 184 B/op 6 allocs/op
BenchmarkGetReplicaSetsWithSameController-12 3275090 389.7 ns/op 184 B/op 6 allocs/op
# Without Changes
BenchmarkGetReplicaSetsWithSameController
BenchmarkGetReplicaSetsWithSameController-12 5501926 202.4 ns/op 48 B/op 2 allocs/op
BenchmarkGetReplicaSetsWithSameController-12 5227614 200.0 ns/op 48 B/op 2 allocs/op
BenchmarkGetReplicaSetsWithSameController-12 6073863 196.5 ns/op 48 B/op 2 allocs/op
BenchmarkGetReplicaSetsWithSameController-12 6055270 199.4 ns/op 48 B/op 2 allocs/op
BenchmarkGetReplicaSetsWithSameController-12 6022762 195.6 ns/op 48 B/op 2 allocs/op
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.
@pohly Do you want me to remote the entire logging bit here ?
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 wonder whether this is related to KObjSlice and/or KObj at all. In other words, what is the performance difference between
klog.V(2).InfoS("Some key/value pairs", "a", 1, "b", "x")
and
if klogV := klog.V(2); klogV.Enabled() {
klogV.InfoS("Some key/value pairs", "a", 1, "b", "x")
}
It is clear that we pay some price for using the simpler one-line version, but how high is that price? I don't know.
Can you perhaps investigate? That'll put the slowdown for passing KObj and KObjSlice into perspective. If they are still "more expensive", then keeping the if check makes sense. If they are equally expensive, then it probably doesn't.
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.
/ack . Let me do that and update back.
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 had a look and came to the conclusion that the if klogV := klog.V(2); klogV.Enabled()
variant is always faster. It matters a little bit more for KObjSlice
than normal scalars because it needs additional memory allocations.
So lets keep the if check here.
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.
/retest
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.
/lgtm
/assign @Random-Liu @smarterclayton For approval. |
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: harshanarayana, pohly, smarterclayton The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
This may need a release note. Would you add in the pr description? |
/release-note-none The only difference is some slight performance improvement. |
What type of PR is this?
/kind feature
What this PR does / why we need it:
This Pull request replaces the
KObjs
with their better performing counter partKObjSlice
. Since build: update to klog v2.70.0 #110724 is now merged, We can reap the benefits of the change that went into theklog
via replace KObjs with KObjSlice klog#322As part of the changes done to address Kubelet JSON logging performance test #102430, there was a Pull request that got merged (log message verbosity #106978) which made some changes to how the
klog.V(x).Enabled
checks were being made. This PR also takes second look at some of those changes to see if theif klogV := klog.V(x); klogV.Enabled()
wrapping is actually required or they can simply be replaced with theklog.V(x).Info{f|S}
. Currently this PR only replaces those items that do not have additional computation done for the logging artifacts under theif klogV := klog.V(x); klogV.Enabled()
check with their counter part ofklog.V(x)
calls directly.Which issue(s) this PR fixes:
Fixes #110737
Special notes for your reviewer:
Benchmark for
getReplicaSetsWithSameController
underreplca_set.go
Original changes were retained as is for the
if
condition wrapping for better performanceDoes this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:
TODO