Why are some Django Xadmin background pages loaded quickly and some slow?

Project environment

  • operating system: Ubuntu 16.04
  • Server: Nginx 1.10.3, uWSGI 2.0.17
  • Database: Mysql 5.7 (using Ali Cloud"s RDS)
  • Python:3.5.2
  • Django:2.0.3
  • Xadmin:2.0.1

problem description

  • I created N app, in the Django project, two of which are relatively large (the Mysql database stores 20W + data).
  • enters the background from Xadmin, and one of the projects keeps reporting an error of nginx:504 Gateway Time out . Later, the result is that the timeout period set by nginx for uWSGI is only 2s, which causes the data to time out before the query finishes.

    solution :

    timeout of uWSGI extended by Nginx

  • Nginx Xadmin
    40s2

:

  1. Nginx : Nginx Nginx
  2. uWSGI : uWSGI uWSGI Djangopython3 manage.py runserver uWSGI
  3. :20W+ 20W+
  4. Django ORM : 2s ORM
  5. Django ORM Django uWSGI Django
  6. : uWSGI CPU 100%

to sum up: the possibility of a problem is a large amount of data or a problem with a Django project, but I don"t know where to start. If you have encountered this kind of problem or can provide a solution to the great god, please do not hesitate to comment, thank you!


it's been almost a year. Forget it. I'll answer it myself.

at that time, it was because we had to filter and query the data in the background of Xadimn and calling the API API, but when filtering, the underlying SQL statement is actually% * %, which needs to be filtered by wildcards, which will lead to full-text search. Of course, it is slow to query 20W + data (Django's ORM table lookup mechanism should be like this, otherwise why do large projects use Tornado framework?) it should be optimized. I didn't know much about Django, at that time, so I used Flask to get the data directly from the database. And then. Just do other projects, but I still haven't learned the essence. I'll have a chance to do it again.

Menu