What is the Symfony firewall doing that takes so long?

前端 未结 3 1092
甜味超标
甜味超标 2020-12-14 05:30

My Symfony page isn\'t too slow (it loads in about 400 ms) but considering the fact that it\'s just a simple hello world page with basic authentication, it should be loading

3条回答
  •  执笔经年
    2020-12-14 06:18

    Alas, it turns out Rawdreeg was partly right. I made a 20 line PHP script to profile how long it takes to connect to my MySQL server:

    query('SHOW TABLES');
    
    $query_time = microtime(true);
    
    var_dump($result->fetchAll(PDO::FETCH_ASSOC));
    
    $time_con = ($connect_time - $time) * 1000;
    $time_query = ($query_time - $connect_time) * 1000;
    
    echo "Connection took $time_con ms\n";
    echo "Query took $time_query ms\n";
    

    The output was:

    Connection took 230.18503189087 ms
    Query took 64.532995223999 ms

    Which fills the blanks of the Symfony profiler perfectly. The good news is that when my application goes live, it will connect to the MySQL server locally by socket, so it'll probably be blazing fast! There is little I can do about the speed during the development though, other than mirroring the MySQL server locally.

    So to summarize the answer; the Symfony firewall initially creates the connection to the MySQL database, and in my case, that connection is quite slow. The MySQL connection time accounts for over 80% of the firewall's profiled time in my case.


    Note: I'm already connecting to the MySQL server by IP address, and I've added skip-name-resolve to the MySQL configuration to no avail.

提交回复
热议问题