-1

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

1
  • I don't see any problem there. The first is a redirect because of the missing slash at the end, it should not have any impact on your service. The second is the actual request that triggers some action. You should make sure the client uses the correct url (with trailing slash) in the first place. Sep 9, 2016 at 13:30

2 Answers 2

1

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)

2
  • Thats a good point, but its weird that the code in my view is executed twice. Would a redirect really to that?
    – Vingtoft
    Sep 9, 2016 at 13:37
  • If the redirect is handled by the webserver itself, it should not execute code on the server. If the redirect is handled in a script, it's quite possible. Sep 9, 2016 at 13:38
0

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/

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .