https://github.com/cilium/cilium
Revision 8019191909443bf02237b4583e0f5b87b44a6331 authored by Thomas Graf on 07 October 2020, 14:11:02 UTC, committed by Thomas Graf on 09 October 2020, 07:22:43 UTC
[ upstream commit 208c69ceddb127d811c7dc011c69bd51b14896e1 ]

So far, the rate limiting has been enforced before enforcing parallel
requests. In theory, this is better because we can return error code
429 earlier to tell callers to slow down.

In practice, many callers will retry immediately anyway which means that
all the limiting will happen by the rate limiter. The rate limiter
relies on reservations that need to be canceled. If too many requests
happen in parallel, reservations can't be canceled quickly enough.

By swapping the enforcement of parallel requests with the rate limiter,
all requests will block for at least MaxWaitDuration if more than the
allowed number of parallel requests are pending which will naturally
pace the callers.

Swapping the enforcement order requires the acquired semaphore to be
released in error cases of the rate limiter. This requires to change the
structure of Wait() to have a single error handling structure. By
reusing finishRequest(), the metrics handler has to be adjusted slightly
to account for new outcomes as it now bumps the metric for canceled
requests as well. What remains unchanged is that only successful API
requests are used to calculate the mean processing duration.

Fixes: 3141e6581e0 ("rate: Add API rate limiting system")
Signed-off-by: Thomas Graf <thomas@cilium.io>
1 parent 09fee20
History
Tip revision: 8019191909443bf02237b4583e0f5b87b44a6331 authored by Thomas Graf on 07 October 2020, 14:11:02 UTC
api-limiter: Enforce ParallelRequests before applying rate limiting
Tip revision: 8019191
File Mode Size
.github
.travis
Documentation
api
bpf
bugtool
cilium
cilium-health
common
contrib
daemon
envoy
examples
hack
install
jenkinsfiles
operator
pkg
plugins
proxylib
test
tests
tools
vendor
.authors.aux -rw-r--r-- 416 bytes
.dockerignore -rw-r--r-- 884 bytes
.gitignore -rw-r--r-- 818 bytes
.gitmodules -rw-r--r-- 0 bytes
.mailmap -rw-r--r-- 1.5 KB
.travis.yml -rw-r--r-- 367 bytes
.travis.yml.tmpl -rw-r--r-- 387 bytes
AUTHORS -rw-r--r-- 11.6 KB
CHANGELOG.md -rw-r--r-- 85.2 KB
CODEOWNERS -rw-r--r-- 1.3 KB
CONTRIBUTING.md -rw-r--r-- 208 bytes
Dockerfile -rw-r--r-- 2.3 KB
Dockerfile.builder -rw-r--r-- 1.7 KB
FURTHER_READINGS.rst -rw-r--r-- 4.4 KB
GO_VERSION -rw-r--r-- 8 bytes
Jenkinsfile.nightly l--------- 32 bytes
LICENSE -rw-r--r-- 11.1 KB
MAINTAINERS.rst -rw-r--r-- 1.4 KB
Makefile -rw-r--r-- 17.9 KB
Makefile.defs -rw-r--r-- 2.5 KB
Makefile.quiet -rw-r--r-- 626 bytes
README.rst -rw-r--r-- 12.7 KB
SECURITY.md -rw-r--r-- 615 bytes
USERS.md -rw-r--r-- 3.5 KB
VERSION -rw-r--r-- 7 bytes
Vagrantfile -rw-r--r-- 11.8 KB
cilium-docker-plugin.Dockerfile -rw-r--r-- 553 bytes
cilium-operator.Dockerfile -rw-r--r-- 706 bytes
docs.Jenkinsfile l--------- 29 bytes
flannel.Jenkinsfile l--------- 32 bytes
ginkgo-kubernetes-all.Jenkinsfile l--------- 46 bytes
ginkgo.Jenkinsfile l--------- 31 bytes
go.mod -rw-r--r-- 41.2 KB
go.sum -rw-r--r-- 67.7 KB
kubernetes-upstream.Jenkinsfile l--------- 44 bytes
vagrant_box_defaults.rb -rw-r--r-- 270 bytes

README.rst

back to top