花费这么长时间的Symfony防火墙在做什么? [英] What is the Symfony firewall doing that takes so long?

查看:70
本文介绍了花费这么长时间的Symfony防火墙在做什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Symfony页面并不太慢(它的加载时间约为400毫秒),但是考虑到它只是一个具有基本身份验证的简单的hello world页面,因此它的加载时间应少于100毫秒.当我进入探查器时,会看到以下内容:

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 in less than 100 ms. When I enter the profiler, I see this:

请注意,它只说了250毫秒防火墙".我认为防火墙只是负责将用户限制在页面的某些区域内-我无法想象这会花费超过几毫秒的时间,再加上从数据库中获取用户信息所花费的时间(在这种情况下,这是61毫秒).

Notice it just says "Firewall" for 250 ms. I thought the firewall was just responsible for keeping users out of certain areas of the page - I can't imagine that taking any longer than a few milliseconds plus the time it takes to fetch the user information from the database (which in this case is 61 ms).

有人可以解释一下防火墙的实际作用吗?如果您对如何提高防火墙性能有任何一般性的建议,也将不胜感激.

Could somebody explain what the firewall actually does? If you have any general pointers on how to increase the firewall performance as well that would be greatly appreciated.

注意:我当然对此进行了Google搜索,我想预先指定要通过IP地址(而不是主机名)连接到MySQL数据库.我可以找到的所有其他慢速Symfony防火墙问题,似乎都是这个问题.

Note: I have Googled this of course, and I want to specify up front that I'm connecting to the MySQL database by IP address, not host name. This seemed to be the issue for every other case of slow Symfony firewall I could find.

我项目中的一些资源可能与之相关:

Some resources from my project that could be relevant:

  • security.yaml
  • routing.yaml
  • Astrups/SpectacleBundle/Entity/User.php
  • Astrups/SpectacleBundle/Service/Sha1Salted.php

推荐答案

A,事实证明 Rawdreeg 部分正确.我编写了20行PHP脚本来描述连接到MySQL服务器所花费的时间:

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:

<?php

$time = microtime(true);

$con = new PDO(...);

$connect_time = microtime(true);

$result = $con->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";

输出为:

Connection took 230.18503189087 ms
Query took 64.532995223999 ms

完全填补了Symfony分析器 的空白.好消息是,当我的应用程序上线时,它将通过套接字在本地连接到MySQL服务器,因此它可能会很快发展起来!除了在本地镜像MySQL服务器之外,在开发过程中我对速度几乎无能为力.

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.

所以总结一下答案; Symfony防火墙最初会创建与MySQL数据库的连接,而在我的情况下,该连接速度很慢.在我的情况下,MySQL连接时间占防火墙配置文件时间的80%以上.

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.

注意:我已经通过IP地址连接到MySQL服务器,并且已经在MySQL配置中添加了skip-name-resolve无济于事.

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.

这篇关于花费这么长时间的Symfony防火墙在做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆