Symfony2: Intermittent High Response Time/Slow SessionHandlerProxy::read() completion

馋奶兔 提交于 2019-12-23 15:02:02

问题


I'm seeing very strange behavior coming from the Symfony2 Session manager component. In particular, the SessionHandlerProxy::read() function is occasionally very slow in my production environment.

Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy::read

I'm using Apache2, on an Amazon EC2 running Ubuntu, with default Symfony2 session storage (not Redis, or something similar), though I'm wondering if I should be. I have NewRelic installed to trace my transactions which reports the following:

The slow responses are intermittent and I haven't noticed any marked correlation between requests/min and slow session read times. I'm stumped, any ideas what I might try?


回答1:


I ran into something similar on a project. I identified it when we switched to redis for session handling (we've switched back to the default file system handler for PHP, problem still occurs intermittently).

What's likely happening is the SessionHandlerProxy::read() method is locked out of the session and the process is waiting for the session to unlock.

Session locking is a good thing, as it prevents race conditions in php. So what is likely happening is that another request is currently accessing the session and not releasing it as immediate as it can. The solution I found via my google fu skills calls the $session->save() handler as soon as you are finished with the session, which intern calls session_write_close() (this unlocks the session for the next request).

I hope this helps out!

Symfony API Documentation for Session:Save()

Here is the original stack overflow question (albeit 5 years ago).



来源:https://stackoverflow.com/questions/37425786/symfony2-intermittent-high-response-time-slow-sessionhandlerproxyread-compl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!