TraceableFirewallListener 加载时间极长
TraceableFirewallListener extremely long loading time
在我的一个 symfony 项目中,我最近 运行 遇到了巨大的性能问题,其中性能问题似乎隐藏在 "Symfony\Bundle\SecurityBundle\Debug\TraceableFirewallListener" 之后,恰好在 "Symfony\Component\Security\Http\Firewall\ContextListener"。
以下是我的开发服务器和实时服务器的屏幕截图 - 服务器规格符合要求,我绝对确定问题不在服务器后面,因为其他项目已经 运行 很棒相似的服务器。
对于如何进一步解决或调试此问题的任何提示,我将不胜感激,因为我无能为力。 Symfony版本是4.0.1,更新到最新版本没有解决问题。
编辑: 使用秒表组件进一步调试使我得出结论,加载时间来自 Symfony/Bridge/Doctrine/Security/User/EntityUserProvider,方法 "refreshUser",第 93 行,调用“$refreshedUser = $repository->find($id);”对于最大的部分,如 2681 毫秒中的 2647 毫秒。不过,我不知道从现在起该去哪里。
开发
直播
我的安全配置:
security:
# https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
encoders:
App\Entity\User:
algorithm: bcrypt
legacy_encoder:
algorithm: md5
encode_as_base64: false
iterations: 1
providers:
in_memory: { memory: ~ }
db_provider:
entity:
class: App\Entity\User
property: username
role_hierarchy:
ROLE_USER_MO: ROLE_USER
ROLE_USER_WKB: ROLE_USER
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
#pattern: ^/
#http_basic: ~
anonymous: ~
provider: db_provider
user_checker: App\Security\UserChecker
logout:
path: /logout
target: /login
form_login:
login_path: login
check_path: login
access_control:
#- { path: ^/, roles: ROLE_USER }
#- { path: ^/login, allow_if: "is_anonymous() and !is_authenticated()" }
- { path: ^/motivwelten, roles: ROLE_USER }
- { path: ^/services/.*, roles: ROLE_USER }
- { path: ^/shop, roles: ROLE_USER }
- { path: ^/shop/.*, roles: ROLE_USER }
- { path: ^/user/.*, roles: ROLE_USER }
- { path: ^/password-forgotten, allow_if: "is_anonymous() and !is_authenticated()" }
- { path: ^/password-forgotten/.*, allow_if: "is_anonymous() and !is_authenticated()" }
- { path: ^/downloads, roles: ROLE_USER }
erase_credentials: false
在我 3 月 1 日的编辑之后,我将提供 "solution" 为我修复加载时间。我不认为这可以称为问题的解决方案,因为我操纵了框架的核心代码,这可能永远不应该或没有必要。
我相当确定问题出在我长期以来构建的实体结构上,用户实体中有几个 fetch=EAGER
部分,应尽可能避免。
我将 Symfony/Bridge/Doctrine/Security/User/EntityUserProvider 中的第 93 行从
更改为
$refreshedUser = $repository->find($id);
到
$refreshedUser = $repository->find(['id' => $id]);
这将开发和实时的加载时间分别从 25 秒减少到约 50 毫秒,从 2.5 秒减少到约 100 毫秒。
我在 yourproject/config/bundles.php
中更改捆绑顺序解决了这个问题
我不确定这个问题是怎么出现的。但我无意中发现了将 symfony 和 sensio 包放在第一位的补救措施。
我不建议更改捆绑订单。
编辑:
抱歉,我检查了一下,我遇到的问题是教义包顺序。
在我的一个 symfony 项目中,我最近 运行 遇到了巨大的性能问题,其中性能问题似乎隐藏在 "Symfony\Bundle\SecurityBundle\Debug\TraceableFirewallListener" 之后,恰好在 "Symfony\Component\Security\Http\Firewall\ContextListener"。
以下是我的开发服务器和实时服务器的屏幕截图 - 服务器规格符合要求,我绝对确定问题不在服务器后面,因为其他项目已经 运行 很棒相似的服务器。
对于如何进一步解决或调试此问题的任何提示,我将不胜感激,因为我无能为力。 Symfony版本是4.0.1,更新到最新版本没有解决问题。
编辑: 使用秒表组件进一步调试使我得出结论,加载时间来自 Symfony/Bridge/Doctrine/Security/User/EntityUserProvider,方法 "refreshUser",第 93 行,调用“$refreshedUser = $repository->find($id);”对于最大的部分,如 2681 毫秒中的 2647 毫秒。不过,我不知道从现在起该去哪里。
开发
直播
我的安全配置:
security:
# https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
encoders:
App\Entity\User:
algorithm: bcrypt
legacy_encoder:
algorithm: md5
encode_as_base64: false
iterations: 1
providers:
in_memory: { memory: ~ }
db_provider:
entity:
class: App\Entity\User
property: username
role_hierarchy:
ROLE_USER_MO: ROLE_USER
ROLE_USER_WKB: ROLE_USER
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
#pattern: ^/
#http_basic: ~
anonymous: ~
provider: db_provider
user_checker: App\Security\UserChecker
logout:
path: /logout
target: /login
form_login:
login_path: login
check_path: login
access_control:
#- { path: ^/, roles: ROLE_USER }
#- { path: ^/login, allow_if: "is_anonymous() and !is_authenticated()" }
- { path: ^/motivwelten, roles: ROLE_USER }
- { path: ^/services/.*, roles: ROLE_USER }
- { path: ^/shop, roles: ROLE_USER }
- { path: ^/shop/.*, roles: ROLE_USER }
- { path: ^/user/.*, roles: ROLE_USER }
- { path: ^/password-forgotten, allow_if: "is_anonymous() and !is_authenticated()" }
- { path: ^/password-forgotten/.*, allow_if: "is_anonymous() and !is_authenticated()" }
- { path: ^/downloads, roles: ROLE_USER }
erase_credentials: false
在我 3 月 1 日的编辑之后,我将提供 "solution" 为我修复加载时间。我不认为这可以称为问题的解决方案,因为我操纵了框架的核心代码,这可能永远不应该或没有必要。
我相当确定问题出在我长期以来构建的实体结构上,用户实体中有几个 fetch=EAGER
部分,应尽可能避免。
我将 Symfony/Bridge/Doctrine/Security/User/EntityUserProvider 中的第 93 行从
更改为$refreshedUser = $repository->find($id);
到
$refreshedUser = $repository->find(['id' => $id]);
这将开发和实时的加载时间分别从 25 秒减少到约 50 毫秒,从 2.5 秒减少到约 100 毫秒。
我在 yourproject/config/bundles.php
中更改捆绑顺序解决了这个问题我不确定这个问题是怎么出现的。但我无意中发现了将 symfony 和 sensio 包放在第一位的补救措施。
我不建议更改捆绑订单。
编辑: 抱歉,我检查了一下,我遇到的问题是教义包顺序。