I've been using an extremely basic user throttle rate with my DRF API and have been getting just... nonsensical results when I try to run benchmark tests.
For instance, when I set the throttle to 15/day my python benchmarker was able to make 29 (???) requests before actually being throttled.
Here are my base settings:
# Django Rest Framework
REST_FRAMEWORK = {
...
'DEFAULT_THROTTLE_CLASSES': [
'rest_framework.throttling.UserRateThrottle',
],
'DEFAULT_THROTTLE_RATES': {
'user': '15/day'
}
}
and here's my benchmarking program:
#!/usr/bin/env python3
# -*- coding: iso-8859-15 -*-
import requests, time, datetime
from pprint import pprint
TOKEN = [redacted]
CSDB_NEXT_URL = "http://localhost:8000/api/siteroles?format=json"
response = requests.get(CSDB_NEXT_URL, headers={'Authorization': 'Token {}'.format(TOKEN)})
startTime = datetime.datetime.now()
for i in range(0, 52):
data = requests.get(CSDB_NEXT_URL, headers={'Authorization': 'Token {}'.format(TOKEN)}).json()
if "Request was throttled" in str(data):
break
endTime = datetime.datetime.now()
print(data, '\n', i, " requests made in ", endTime-startTime, " seconds.").
and which yielded
[Running] /usr/bin/env python3 "/Users/jgossett/Documents/gateway3/utils/benchmarks/test"
{'detail': 'Request was throttled. Expected available in 86389 seconds.'}
29 requests made in 0:00:12.437853 seconds.[Done] exited with code=0 in 13.248 seconds
Now the number 29 here is especially troubling because it is larger than 15? Notably so? Does anyone know why this would be happening?