Overhead of a trip to MySql?

So, I’ve been developing django applications for a long time and I’m culinary help and that’s all: only using ORM and never creating my own SQL.

The main page of the site (the main interface in which users will spend 80% - 90% of their time) slows down when you have a large amount of user content (for example, photos, friends, other data, etc.),

So, I jumped into the sql logger (was pre-installed using pinax, I just turned it on in the settings) and imagine my surprise when he reported 500 database queries ! With sql manual code, I almost never ran more than 50 on the most complex pages.

In retrospect, this is not all together surprisingly, but it seems that this may not be good.

... even if only about a dozen requests accept 1ms +

So, I am wondering how much overhead is there in traveling around the world in mysql ? django and mysql are running on the same server , so there should be no network-related overhead.

+3
source share
4 answers

There are several ways to reduce the volume of requests.

  • Use .filter()and .all()to get a bunch of things; select and select a view function (or template through {%if%}). Python can process a package of strings faster than MySQL.

    " ". , SQL. , .

    , SQL. - ORM - .

  • . {{foo.bar.baz.quux}}, SQL bar, foo, baz, bar, quux, baz. .filter() Python .

    , , , SQL. , ORM, Python, ORM.

    ORM. .

+2

, ORM, , .

- - , . , , . , select_related() - .

SQL , , - , .

- , . , ?

, : ORM , - , Django; , .

, ORM , , : raw sql .

+4

- . Django Mysql, , , . , , , . 500 - , 50 . , 5000 .

, , 20 100 .

.

+3

, , , , , - .

, , , :

  • ( , ..) / , ,
  • - sql ( , , )
  • , , .
    • , ( SQL), , , .
  • .
  • .

, SQL. 500 , . , .

+1

Source: https://habr.com/ru/post/1722134/


All Articles