A
A
Andrey Tokmakov2016-03-25 10:54:52
MySQL
Andrey Tokmakov, 2016-03-25 10:54:52

Why does the first request take a long time to complete?

Maybe someone came across ...
When loading any controller / action, the first query to the database is executed 700-900ms, while all SELECT queries are executed from 0.1ms to a maximum of 3.7ms approximately, but SHOW (request type, like a debugger calls names) requests - the first one is executed in 700-900ms and the rest in 70-80ms.
The first query kills so many times regardless of the size of the table, the size of the selected data, even the queries were rewritten in different ways, no difference.
Logs tried to disable everything, nothing has changed.
I sinned on the connection, I thought it was installing for a long time, but there is no 0.3ms.
How to be?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel Volintsev, 2016-03-31
@copist

Active Record is trying to read data about tables, I guess.
Go through the article on optimization for Yii2 www.yiiframework.com/doc-2.0/guide-tutorial-perfor... in particular caching data schemas and queries.
For Yii1 I can't find the same one. It used to be, but in Google search it was covered with dust.
Schema caching for ActiveRecord

return array(
    …
    'components'=>array(
        …
        'cache'=>array( // ... компонента для работы с кэшем
            'class'=>'CDbCache',
        ),
        'db'=>array( // ... компонента для работы с БД
            // ... настройки компоненты
            'schemaCachingDuration'=>3600, // <-- кэшировать схему данных для ActiveRecord на 1 час
        ),
    ),
);

There is also an option, using caching, to suppress the creation of connections to the database, if they are not needed at all: copist.ru/blog/2014/09/29/high-speed-yii-database

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question