NO-JIRA: replace global refresh sync lock in OIDC provider with per-refresh-token one
This PR replaces the sync lock that would apply to all HTTP-serving spawned goroutines with a sync-lock that is specific to each of the refresh tokens. That reduces token refresh request handling time by about 30%.
Results from the benchmarking:
global lock
Running tool: /usr/bin/go test -benchmem -run=^$ -bench ^BenchmarkRefreshSession$ github.com/openshift/console/pkg/auth -race
goos: linux
goarch: amd64
pkg: github.com/openshift/console/pkg/auth
cpu: Intel(R) Core(TM) i7-10610U CPU @ 1.80GHz
BenchmarkRefreshSession/BenchmarkRefreshSession-Users=1-8 1000000000 0.03653 ns/op 0 B/op 0 allocs/op
BenchmarkRefreshSession/BenchmarkRefreshSession-Users=10-8 1000000000 0.3441 ns/op 0 B/op 0 allocs/op
BenchmarkRefreshSession/BenchmarkRefreshSession-Users=20-8 1000000000 0.7806 ns/op 0 B/op 0 allocs/op
BenchmarkRefreshSession/BenchmarkRefreshSession-Users=50-8 1 1997942694 ns/op 140775320 B/op 1768612 allocs/op
BenchmarkRefreshSession/BenchmarkRefreshSession-Users=100-8 1 3946182110 ns/op 280938136 B/op 3536162 allocs/op
BenchmarkRefreshSession/BenchmarkRefreshSession-Users=200-8 1 7879313886 ns/op 561838968 B/op 7093861 allocs/op
BenchmarkRefreshSession/BenchmarkRefreshSession-Users=500-8 1 19764448281 ns/op 1402379520 B/op 17756174 allocs/op
BenchmarkRefreshSession/BenchmarkRefreshSession-Users=1000-8 1 41249797966 ns/op 2804039928 B/op 35546087 allocs/op
PASS
ok github.com/openshift/console/pkg/auth 117.237s
per-refresh-token lock
Running tool: /usr/bin/go test -benchmem -run=^$ -bench ^BenchmarkRefreshSession$ github.com/openshift/console/pkg/auth -race
goos: linux
goarch: amd64
pkg: github.com/openshift/console/pkg/auth
cpu: Intel(R) Core(TM) i7-10610U CPU @ 1.80GHz
BenchmarkRefreshSession/BenchmarkRefreshSession-Users=1-8 1000000000 0.03203 ns/op 0 B/op 0 allocs/op
BenchmarkRefreshSession/BenchmarkRefreshSession-Users=10-8 1000000000 0.1949 ns/op 0 B/op 0 allocs/op
BenchmarkRefreshSession/BenchmarkRefreshSession-Users=20-8 1000000000 0.4204 ns/op 0 B/op 0 allocs/op
BenchmarkRefreshSession/BenchmarkRefreshSession-Users=50-8 1 1078943935 ns/op 141152776 B/op 1780860 allocs/op
BenchmarkRefreshSession/BenchmarkRefreshSession-Users=100-8 1 2203305487 ns/op 284332664 B/op 3566720 allocs/op
BenchmarkRefreshSession/BenchmarkRefreshSession-Users=200-8 1 4523241884 ns/op 563987296 B/op 7139411 allocs/op
BenchmarkRefreshSession/BenchmarkRefreshSession-Users=500-8 1 13822808403 ns/op 1411784760 B/op 17894645 allocs/op
BenchmarkRefreshSession/BenchmarkRefreshSession-Users=1000-8 1 26968971744 ns/op 2828981672 B/op 35851229 allocs/op
PASS
ok github.com/openshift/console/pkg/auth 63.630s
/assign @jhadvig
built on top of https://github.com/openshift/console/pull/13647 that adds unit tests
@stlaz: This pull request explicitly references no jira issue.
In response to this:
This PR replaces the sync lock that would apply to all HTTP-serving spawned goroutines with a sync-lock that is specific to each of the refresh tokens. That reduces token refresh request handling time by about 50%.
Results from the benchmarking:
global lock
Running tool: /usr/bin/go test -benchmem -run=^$ -bench ^BenchmarkRefreshSession$ github.com/openshift/console/pkg/auth -race goos: linux goarch: amd64 pkg: github.com/openshift/console/pkg/auth cpu: Intel(R) Core(TM) i7-10610U CPU @ 1.80GHz BenchmarkRefreshSession/BenchmarkRefreshSession-Users=1-8 1000000000 0.03653 ns/op 0 B/op 0 allocs/op BenchmarkRefreshSession/BenchmarkRefreshSession-Users=10-8 1000000000 0.3441 ns/op 0 B/op 0 allocs/op BenchmarkRefreshSession/BenchmarkRefreshSession-Users=20-8 1000000000 0.7806 ns/op 0 B/op 0 allocs/op BenchmarkRefreshSession/BenchmarkRefreshSession-Users=50-8 1 1997942694 ns/op 140775320 B/op 1768612 allocs/op BenchmarkRefreshSession/BenchmarkRefreshSession-Users=100-8 1 3946182110 ns/op 280938136 B/op 3536162 allocs/op BenchmarkRefreshSession/BenchmarkRefreshSession-Users=200-8 1 7879313886 ns/op 561838968 B/op 7093861 allocs/op BenchmarkRefreshSession/BenchmarkRefreshSession-Users=500-8 1 19764448281 ns/op 1402379520 B/op 17756174 allocs/op BenchmarkRefreshSession/BenchmarkRefreshSession-Users=1000-8 1 41249797966 ns/op 2804039928 B/op 35546087 allocs/op PASS ok github.com/openshift/console/pkg/auth 117.237sper-refresh-token lock
Running tool: /usr/bin/go test -benchmem -run=^$ -bench ^BenchmarkRefreshSession$ github.com/openshift/console/pkg/auth -race goos: linux goarch: amd64 pkg: github.com/openshift/console/pkg/auth cpu: Intel(R) Core(TM) i7-10610U CPU @ 1.80GHz BenchmarkRefreshSession/BenchmarkRefreshSession-Users=1-8 1000000000 0.03203 ns/op 0 B/op 0 allocs/op BenchmarkRefreshSession/BenchmarkRefreshSession-Users=10-8 1000000000 0.1949 ns/op 0 B/op 0 allocs/op BenchmarkRefreshSession/BenchmarkRefreshSession-Users=20-8 1000000000 0.4204 ns/op 0 B/op 0 allocs/op BenchmarkRefreshSession/BenchmarkRefreshSession-Users=50-8 1 1078943935 ns/op 141152776 B/op 1780860 allocs/op BenchmarkRefreshSession/BenchmarkRefreshSession-Users=100-8 1 2203305487 ns/op 284332664 B/op 3566720 allocs/op BenchmarkRefreshSession/BenchmarkRefreshSession-Users=200-8 1 4523241884 ns/op 563987296 B/op 7139411 allocs/op BenchmarkRefreshSession/BenchmarkRefreshSession-Users=500-8 1 13822808403 ns/op 1411784760 B/op 17894645 allocs/op BenchmarkRefreshSession/BenchmarkRefreshSession-Users=1000-8 1 26968971744 ns/op 2828981672 B/op 35851229 allocs/op PASS ok github.com/openshift/console/pkg/auth 63.630s/assign @jhadvig
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 openshift-eng/jira-lifecycle-plugin repository.
[APPROVALNOTIFIER] This PR is NOT APPROVED
This pull-request has been approved by: stlaz Once this PR has been reviewed and has the lgtm label, please ask for approval from jhadvig. For more information see the Kubernetes Code Review Process.
The full list of commands accepted by this bot can be found here.
Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment
@stlaz: all tests passed!
Full PR test history. Your PR dashboard.
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.