Symfony 3 - 登录时的防火墙侦听器性能
Symfony 3 - Firewall Listener Performance at Login
回复了我自己的问题,贴在这里供大家参考。
设置
我的应用开箱即用,运行ning:
Symfony 3
与 Doctrine2
PHP 5.6.*
将 CGI/FastCGI
作为 PHP 处理程序(甚至 php 7)
mySQL 5.6.*
然后,进一步优化:
Zend OpCache
通过操作码缓存和优化获得更快的 PHP 执行速度
Memcached
将 user sessions
存储在 memcached 中
Memcached
作为 metadata cache driver
和 query cache driver
作为 doctrine 2
瓶颈
但是,当我通过登录表单进行身份验证时,有一条路线非常慢,那就是 fos_user_security_check
路线。
它显示 Symfony\Bundle\SecurityBundle\EventListener\FirewallListener
作为罪魁祸首 - 虽然我不确定为什么会这样,因为这条路线在我的本地机器上快速亮起但在我的生产机器上没有。
我尝试过的事情
- [x] 使用 Memcached 缓存 PHP 个会话 -> 无差异
- [x] 使用 Memcached 来缓存 Doctrine 的东西 -> 没有区别
- [x] 到 运行 mysql 与
skip-name-resolve
-> 没有区别
我看过的相关帖子
What is the Symfony Firewall doing that takes so long?
两个字!! "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
回复了我自己的问题,贴在这里供大家参考。
设置
我的应用开箱即用,运行ning:
Symfony 3
与Doctrine2
PHP 5.6.*
将CGI/FastCGI
作为 PHP 处理程序(甚至 php 7)mySQL 5.6.*
然后,进一步优化:
Zend OpCache
通过操作码缓存和优化获得更快的 PHP 执行速度Memcached
将user sessions
存储在 memcached 中
Memcached
作为metadata cache driver
和query cache driver
作为doctrine 2
瓶颈
但是,当我通过登录表单进行身份验证时,有一条路线非常慢,那就是 fos_user_security_check
路线。
Symfony\Bundle\SecurityBundle\EventListener\FirewallListener
作为罪魁祸首 - 虽然我不确定为什么会这样,因为这条路线在我的本地机器上快速亮起但在我的生产机器上没有。
我尝试过的事情
- [x] 使用 Memcached 缓存 PHP 个会话 -> 无差异
- [x] 使用 Memcached 来缓存 Doctrine 的东西 -> 没有区别
- [x] 到 运行 mysql 与
skip-name-resolve
-> 没有区别
我看过的相关帖子
What is the Symfony Firewall doing that takes so long?
两个字!! "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