1

在我的一个 symfony 项目中,我最近遇到了巨大的性能问题,性能问题似乎隐藏在“Symfony\Bundle\SecurityBundle\Debug\TraceableFirewallListener”之后,恰好在“Symfony\Component\Security\Http\Firewall \上下文监听器”。

以下是我的开发服务器和实时服务器的屏幕截图 - 服务器规格符合要求,我绝对确定问题不在服务器背后,因为其他项目在类似服务器上运行良好。

我将不胜感激有关如何进一步解决或调试此问题的任何提示,因为我束手无策。Symfony 版本是 4.0.1,更新到最新版本并没有解决问题。

编辑:使用秒表组件进一步调试让我得出结论,加载时间来自 Symfony/Bridge/Doctrine/Security/User/EntityUserProvider,方法“refreshUser”,第 93 行,调用“$refreshedUser = $repository- >查找($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
4

2 回答 2

-1

我解决了这个问题,在 yourproject/config/bundles.php 中更改捆绑顺序

我不确定这个问题是如何出现的。但我无意中发现了这个把 symfony 和 sensio 包放在首位的补救措施。

我不建议更改捆绑订单。

编辑:对不起,我检查了,我的问题是学说包订单。

于 2020-10-05T15:50:49.340 回答
-2

跟进我在 3 月 1 日的编辑,我将提供为我修复加载时间的“解决方案”。我不认为这可以称为问题的解决方案,因为我操纵了框架的核心代码,这可能永远不应该做或没有必要。

我相当确定问题出在我长期以来构建的实体结构中,其中fetch=EAGER用户实体中有几个部分,应尽可能避免。

我将 Symfony/Bridge/Doctrine/Security/User/EntityUserProvider 中的第 93 行从

$refreshedUser = $repository->find($id);

$refreshedUser = $repository->find(['id' => $id]);

这将加载时间从 25 秒减少到约 50 毫秒,并将开发和直播的加载时间从 2.5 秒减少到约 100 毫秒。

于 2019-03-04T15:28:41.507 回答