Hi I am facing extreme inconsistency in Throttling mechanism in Django rest framework. I have the api endpoint to throttle 10 requests/sec
but when I send 20 requests at the same time using Apache Benchmark the api should throttle 10 requests whereas it throttles 4, 6
and it is inconsistent. sometimes it does not even throttle any requests.
class StatusApiThrottle(CustomeRateThrottle):
rate = '10/s'
scope = 'status'
def allow_request(self, request, view): # independent throttle for GET request on view
if request.method == "POST":
return True
return super().allow_request(request, view)
cache configuration
CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": "redis://127.0.0.1:6379/1",
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient"
},
"KEY_PREFIX": "myapp"
}
}
Run the app using gunicorn
gunicorn app --workers 2 --threads=2
Testing using Apache benchMark
$ ab -n 20 -c 20 -v 1 http://127.0.0.1:8080/api/v1/access/842b1012-53ef-4e98-9a20-484e681c3789
result #1
Complete requests: 20
Failed requests: 6
result #2
Complete requests: 20
Failed requests: 3