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

structured-logging: replace KObjs with KObjSlice for logging #110747

Conversation

harshanarayana
Copy link
Contributor

@harshanarayana harshanarayana commented Jun 23, 2022

What type of PR is this?

/kind feature

What this PR does / why we need it:

  1. This Pull request replaces the KObjs with their better performing counter part KObjSlice. Since build: update to klog v2.70.0 #110724 is now merged, We can reap the benefits of the change that went into the klog via replace KObjs with KObjSlice klog#322

  2. As 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 the if klogV := klog.V(x); klogV.Enabled() wrapping is actually required or they can simply be replaced with the klog.V(x).Info{f|S}. Currently this PR only replaces those items that do not have additional computation done for the logging artifacts under the if klogV := klog.V(x); klogV.Enabled() check with their counter part of klog.V(x) calls directly.

Which issue(s) this PR fixes:

Fixes #110737

Special notes for your reviewer:

Benchmark for getReplicaSetsWithSameController under replca_set.go

Original changes were retained as is for the if condition wrapping for better performance

# 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

Does this PR introduce a user-facing change?


Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:

[Usage]: https://github.com/kubernetes/community/pull/6719

TODO

  • Attach Benchmarking results for the changes

@k8s-ci-robot
Copy link
Contributor

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. kind/feature Categorizes issue or PR as related to a new feature. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Jun 23, 2022
@k8s-ci-robot k8s-ci-robot added area/apiserver area/kubelet sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/apps Categorizes an issue or PR as relevant to SIG Apps. sig/architecture Categorizes an issue or PR as relevant to SIG Architecture. sig/instrumentation Categorizes an issue or PR as relevant to SIG Instrumentation. sig/node Categorizes an issue or PR as relevant to SIG Node. wg/structured-logging Categorizes an issue or PR as relevant to WG Structured Logging. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Jun 23, 2022
@leilajal
Copy link
Contributor

/remove-sig api-machinery

@k8s-ci-robot k8s-ci-robot removed the sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. label Jun 23, 2022
@harshanarayana harshanarayana force-pushed the cleanup/GIT-110737/logging-improvements branch from bdca75c to 711364b Compare June 24, 2022 06:54
@@ -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() {
Copy link
Contributor Author

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.

Copy link
Contributor Author

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 ?

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ack

@k8s-ci-robot k8s-ci-robot added the sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. label Jun 24, 2022
@dims
Copy link
Member

dims commented Jun 24, 2022

/test all

@harshanarayana
Copy link
Contributor Author

/test pull-kubernetes-conformance-kind-ga-only-parallel

@harshanarayana
Copy link
Contributor Author

/test pull-kubernetes-e2e-gce-storage-snapshot

1 similar comment
@harshanarayana
Copy link
Contributor Author

/test pull-kubernetes-e2e-gce-storage-snapshot

@harshanarayana harshanarayana marked this pull request as ready for review June 28, 2022 15:49
@harshanarayana
Copy link
Contributor Author

@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 ?

@pohly
Copy link
Contributor

pohly commented Jun 29, 2022

The PR description is perfect. Lots of context and additional information.

@harshanarayana harshanarayana changed the title GIT-110737: replace KObjs with KObjSlice for logging structured-logging: replace KObjs with KObjSlice for logging Jun 29, 2022
@dgrisonnet
Copy link
Member

/assign @pohly
/triage accepted

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Jun 30, 2022
@leilajal
Copy link
Contributor

/remove-sig api-machinery

@k8s-ci-robot k8s-ci-robot removed the sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. label Jun 30, 2022
@harshanarayana harshanarayana force-pushed the cleanup/GIT-110737/logging-improvements branch from 711364b to c3cbc44 Compare July 1, 2022 04:22
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))
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor Author

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 ?

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor

@yangjunmyfm192085 yangjunmyfm192085 left a comment

Choose a reason for hiding this comment

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

/retest

Copy link
Contributor

@pohly pohly left a comment

Choose a reason for hiding this comment

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

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 28, 2022
@pohly
Copy link
Contributor

pohly commented Oct 28, 2022

/assign @Random-Liu @smarterclayton

For approval.

@smarterclayton
Copy link
Contributor

/approve

@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 2, 2022
@pacoxu
Copy link
Member

pacoxu commented Nov 3, 2022

This may need a release note. Would you add in the pr description?

@pohly
Copy link
Contributor

pohly commented Nov 3, 2022

/release-note-none

The only difference is some slight performance improvement.

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Nov 3, 2022
@k8s-ci-robot k8s-ci-robot merged commit 98742f9 into kubernetes:master Nov 3, 2022
SIG Node PR Triage automation moved this from Triage to Done Nov 3, 2022
@k8s-ci-robot k8s-ci-robot added this to the v1.26 milestone Nov 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/apiserver area/kubelet cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. release-note-none Denotes a PR that doesn't merit a release note. sig/apps Categorizes an issue or PR as relevant to SIG Apps. sig/architecture Categorizes an issue or PR as relevant to SIG Architecture. sig/instrumentation Categorizes an issue or PR as relevant to SIG Instrumentation. sig/node Categorizes an issue or PR as relevant to SIG Node. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on. wg/structured-logging Categorizes an issue or PR as relevant to WG Structured Logging.
Projects
Development

Successfully merging this pull request may close these issues.

structured logging: switch from KObjs to KObjSlice
10 participants