I've noticed that my Django application from time to time makes double database queries, instead of just one. The log file shows two similar requests at (almost) the exact same time.
Example:
[pid: 749|app: 0|req: 892/2837] x.x.x.x () {44 vars in 896 bytes} [Fri Sep 9 12:00:55 2016] GET /clinic_profile/61 => generated 0 bytes in 1 msecs (HTTP/1.1 301) 3 headers in 134 bytes (1 switches on core 0)
[pid: 750|app: 0|req: 659/2838] x.x.x.x () {44 vars in 898 bytes} [Fri Sep 9 12:00:55 2016] GET /clinic_profile/61/ => generated 84989 bytes in 374 msecs (HTTP/1.1 200) 3 headers in 102 bytes (1 switches on core 0)
This is a critical flaw in my system and I need to fix it asap.
Question: How can I filter out double requests?
Im using Django, Nginx and Ubuntu 14.04
It's doesn't look like a double db query, but a 301 redirect from
/clinic_profile/61
to/clinic_profile/61/
(it adds the trailing slash)For read traffic, use of a cache in front of the database protects the database against executing duplicate queries. Django has a cache framework:
https://docs.djangoproject.com/en/1.10/topics/cache/