![]() The following investigation occurred during development. Add TimingHistogram impl that shares lock with WeightedHistogram Benchmarking and profiling shows that two layers of locking is noticeably more expensive than one. After adding this new alternative, I now get the following benchmark results. ``` (base) mspreitz@mjs12 kubernetes % go test -benchmem -run=^$ -bench ^BenchmarkTimingHistogram$ k8s.io/component-base/metrics/prometheusextension goos: darwin goarch: amd64 pkg: k8s.io/component-base/metrics/prometheusextension cpu: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz BenchmarkTimingHistogram-16 22232037 52.79 ns/op 0 B/op 0 allocs/op PASS ok k8s.io/component-base/metrics/prometheusextension 1.404s (base) mspreitz@mjs12 kubernetes % go test -benchmem -run=^$ -bench ^BenchmarkTimingHistogram$ k8s.io/component-base/metrics/prometheusextension goos: darwin goarch: amd64 pkg: k8s.io/component-base/metrics/prometheusextension cpu: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz BenchmarkTimingHistogram-16 22190997 54.50 ns/op 0 B/op 0 allocs/op PASS ok k8s.io/component-base/metrics/prometheusextension 1.435s ``` and ``` (base) mspreitz@mjs12 kubernetes % go test -benchmem -run=^$ -bench ^BenchmarkTimingHistogramDirect$ k8s.io/component-base/metrics/prometheusextension goos: darwin goarch: amd64 pkg: k8s.io/component-base/metrics/prometheusextension cpu: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz BenchmarkTimingHistogramDirect-16 28863244 40.99 ns/op 0 B/op 0 allocs/op PASS ok k8s.io/component-base/metrics/prometheusextension 1.890s (base) mspreitz@mjs12 kubernetes % (base) mspreitz@mjs12 kubernetes % (base) mspreitz@mjs12 kubernetes % go test -benchmem -run=^$ -bench ^BenchmarkTimingHistogramDirect$ k8s.io/component-base/metrics/prometheusextension goos: darwin goarch: amd64 pkg: k8s.io/component-base/metrics/prometheusextension cpu: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz BenchmarkTimingHistogramDirect-16 27994173 40.37 ns/op 0 B/op 0 allocs/op PASS ok k8s.io/component-base/metrics/prometheusextension 1.384s ``` So the new implementation is roughly 20% faster than the original. Add overlooked exception, rename timingHistogram to timingHistogramLayered Use the direct (one mutex) style of TimingHistogram impl This is about a 20% gain in CPU speed on my development machine, in benchmarks without lock contention. Following are two consecutive trials. (base) mspreitz@mjs12 prometheusextension % go test -benchmem -run=^$ -bench Histogram . goos: darwin goarch: amd64 pkg: k8s.io/component-base/metrics/prometheusextension cpu: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz BenchmarkTimingHistogramLayered-16 21650905 51.91 ns/op 0 B/op 0 allocs/op BenchmarkTimingHistogramDirect-16 29876860 39.33 ns/op 0 B/op 0 allocs/op BenchmarkWeightedHistogram-16 49227044 24.13 ns/op 0 B/op 0 allocs/op BenchmarkHistogram-16 41063907 28.82 ns/op 0 B/op 0 allocs/op PASS ok k8s.io/component-base/metrics/prometheusextension 5.432s (base) mspreitz@mjs12 prometheusextension % go test -benchmem -run=^$ -bench Histogram . goos: darwin goarch: amd64 pkg: k8s.io/component-base/metrics/prometheusextension cpu: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz BenchmarkTimingHistogramLayered-16 22483816 51.72 ns/op 0 B/op 0 allocs/op BenchmarkTimingHistogramDirect-16 29697291 39.39 ns/op 0 B/op 0 allocs/op BenchmarkWeightedHistogram-16 48919845 24.03 ns/op 0 B/op 0 allocs/op BenchmarkHistogram-16 41153044 29.26 ns/op 0 B/op 0 allocs/op PASS ok k8s.io/component-base/metrics/prometheusextension 5.044s Remove layered implementation of TimingHistogram |
||
---|---|---|
.. | ||
boilerplate | ||
conformance | ||
e2e-internal | ||
gen-swagger-doc | ||
jenkins | ||
lib | ||
make-rules | ||
testdata | ||
tools | ||
verify-flags | ||
.descriptions_failures | ||
.import-aliases | ||
.spelling_failures | ||
benchmark-go.sh | ||
build-cross.sh | ||
build-go.sh | ||
cherry_pick_pull.sh | ||
dev-build-and-push.sh | ||
dev-build-and-up.sh | ||
dev-push-conformance.sh | ||
e2e-node-test.sh | ||
generate-docs.sh | ||
get-build.sh | ||
ginkgo-e2e.sh | ||
grab-profiles.sh | ||
install-etcd.sh | ||
lint-dependencies.sh | ||
list-feature-tests.sh | ||
local-up-cluster.sh | ||
logcheck.conf | ||
module-graph.sh | ||
OWNERS | ||
pin-dependency.sh | ||
print-workspace-status.sh | ||
README.md | ||
run-in-gopath.sh | ||
run-prometheus-on-etcd-scrapes.sh | ||
serve-prom-scrapes.sh | ||
test-go.sh | ||
test-integration.sh | ||
unwanted-dependencies.json | ||
update-all.sh | ||
update-codegen.sh | ||
update-conformance-yaml.sh | ||
update-generated-api-compatibility-data.sh | ||
update-generated-device-plugin-dockerized.sh | ||
update-generated-device-plugin.sh | ||
update-generated-docs.sh | ||
update-generated-kms-dockerized.sh | ||
update-generated-kms.sh | ||
update-generated-kubelet-plugin-registration-dockerized.sh | ||
update-generated-kubelet-plugin-registration.sh | ||
update-generated-pod-resources-dockerized.sh | ||
update-generated-pod-resources.sh | ||
update-generated-protobuf-dockerized.sh | ||
update-generated-protobuf.sh | ||
update-generated-runtime-dockerized.sh | ||
update-generated-runtime.sh | ||
update-generated-stable-metrics.sh | ||
update-generated-swagger-docs.sh | ||
update-gofmt.sh | ||
update-import-aliases.sh | ||
update-internal-modules.sh | ||
update-kustomize.sh | ||
update-mocks.sh | ||
update-netparse-cve.sh | ||
update-openapi-spec.sh | ||
update-translations.sh | ||
update-vendor-licenses.sh | ||
update-vendor.sh | ||
update-yamlfmt.sh | ||
verify-all.sh | ||
verify-api-groups.sh | ||
verify-boilerplate.sh | ||
verify-cli-conventions.sh | ||
verify-codegen.sh | ||
verify-conformance-requirements.sh | ||
verify-conformance-yaml.sh | ||
verify-description.sh | ||
verify-e2e-test-ownership.sh | ||
verify-external-dependencies-version.sh | ||
verify-flags-underscore.py | ||
verify-generated-device-plugin.sh | ||
verify-generated-docs.sh | ||
verify-generated-files-remake.sh | ||
verify-generated-files.sh | ||
verify-generated-kms.sh | ||
verify-generated-kubelet-plugin-registration.sh | ||
verify-generated-pod-resources.sh | ||
verify-generated-protobuf.sh | ||
verify-generated-runtime.sh | ||
verify-generated-stable-metrics.sh | ||
verify-generated-swagger-docs.sh | ||
verify-gofmt.sh | ||
verify-golangci-lint.sh | ||
verify-govet-levee.sh | ||
verify-govet.sh | ||
verify-import-aliases.sh | ||
verify-import-boss.sh | ||
verify-imports.sh | ||
verify-internal-modules.sh | ||
verify-linkcheck.sh | ||
verify-mocks.sh | ||
verify-netparse-cve.sh | ||
verify-no-vendor-cycles.sh | ||
verify-non-mutating-validation.sh | ||
verify-openapi-spec.sh | ||
verify-pkg-names.sh | ||
verify-prerelease-lifecycle-tags.sh | ||
verify-prometheus-imports.sh | ||
verify-publishing-bot.py | ||
verify-readonly-packages.sh | ||
verify-shellcheck.sh | ||
verify-spelling.sh | ||
verify-staging-meta-files.sh | ||
verify-test-code.sh | ||
verify-test-featuregates.sh | ||
verify-test-images.sh | ||
verify-typecheck-providerless.sh | ||
verify-typecheck.sh | ||
verify-vendor-licenses.sh | ||
verify-vendor.sh | ||
verify-yamlfmt.sh |
Kubernetes hack GuideLines
This document describes how you can use the scripts from hack
directory
and gives a brief introduction and explanation of these scripts.
Overview
The hack
directory contains many scripts that ensure continuous development of kubernetes,
enhance the robustness of the code, improve development efficiency, etc.
The explanations and descriptions of these scripts are helpful for contributors.
For details, refer to the following guidelines.
Key scripts
verify-all.sh
: This script is a vestigial redirection, Please do not add "real" logic. It is equivalent tomake verify
.update-all.sh
: This script is a vestigial redirection, Please do not add "real" logic. Thetrue
target of this makerule ishack/make-rules/update.sh
.It is equivalent tomake update
.
Attention
Note that all scripts must be run from the Kubernetes root directory.
We should run hack/verify-all.sh
before submitting a PR and if anything fails run hack/update-all.sh
.