Symfony 3 - 登录时的防火墙侦听器性能

Symfony 3 - Firewall Listener Performance at Login

回复了我自己的问题,贴在这里供大家参考。


设置

我的应用开箱即用,运行ning:

然后,进一步优化:

瓶颈

但是,当我通过登录表单进行身份验证时,有一条路线非常慢,那就是 fos_user_security_check 路线。

它显示 Symfony\Bundle\SecurityBundle\EventListener\FirewallListener 作为罪魁祸首 - 虽然我不确定为什么会这样,因为这条路线在我的本地机器上快速亮起但在我的生产机器上没有。

我尝试过的事情

我看过的相关帖子

两个字!! "Encryption Algorithm".

There is a compromise between 'speed' and 'security'.

Using the pbkdf2 Encoder Security and Speed


显示 2 种不同加密方式如何影响速度的示例。

配置A:

# Login in 3.5s in my case
security:
    FOS\UserBundle\Model\UserInterface:

        # . Use `bcrypt` algorithm
        algorithm: bcrypt
        cost: 13

配置B:

# Login in 400ms in my case
security:
    FOS\UserBundle\Model\UserInterface:
    # . Use `pdkdf2` algorithm
    algorithm:            pbkdf2
    hash_algorithm:       sha512
    encode_as_base64:     true
    iterations:           1000
    key_length:           40

请注意,您必须在数据库中重新创建用户以测试不同的加密机制。


这说明:

... this route lights up quickly on my local machine but doesn't on my production machine. 
  • 我的本地机器有 Intel Core i7-7820HQ @ 2.90GHz
  • 我的生产机器有一个Intel Xeon E5-2620 v2 @ 2.10GHz