Why does PHP Symfony sfSessionStorage :: initialize sometimes take a really (really) long time?

We have different PHP applications, both in symfony 1.4 and symfony 2, and all of them, at some point, have queries in which sfSessionStorage :: initialize takes a lot of time.

I am talking about a few minutes to download. Take this new relief, for example:

enter image description here

Here you can see sfSessionStorage :: initialize took 185 seconds . We have been debugging this for several days, until we succeed. We examined the settings of the GC, the event tried to establish where the sessions are stored in the file system in RamDisk, without effect.

What could be the reason for this? Have you ever faced the same problem? Any help is much appreciated, thanks!

+5
source share
3 answers

Thanks to a comment by @SomeHelpingDude pointing to this thread: https://forums.powweb.com/showthread.php?t=77977 , the possibility of implementing your own session handler ( http://www.php.net/manual/en/ was mentioned function.session-set-save-handler.php ).

We did this and implemented a session handler that uses memcached. Now the problem is gone.

I assume that the native session processing method (file system) ultimately suffers from deadlocks and other performance issues that can be avoided without using the file system at all.

I am still puzzled by why ramdisk did not fix this in the first place, so if someone can explain it, I will change the accepted answer. Thanks!

+1
source

strace can shed light on what is happening.

Assuming you cannot reproduce the problem using cli, I would recommend limiting the number of processes to 1 (MaxRequestWorkers for mod_php and max_children for php_fpm), bind strace to the process and check where it hangs.

For example, in the case of php_fpm:

  • open /etc/php5/fpm/pool.d/www.conf and make sure the settings

     pm = static pm.max_children = 1 
  • restart php_fpm and nginx

  • grep aux | php grep aux | php to find out the process id
  • sudo strace -p followed by the process id
  • try to reproduce the problem.

If it is stored for several minutes with a single system call, you will clearly see the blocker directly in stdout strace. If there is no single blocker, but rather a long cycle of repeated system calls, you probably need to write it to a file and parse it later. For instance. sudo strace -p {pid} | tee /tmp/strace.log sudo strace -p {pid} | tee /tmp/strace.log .

If the problem does not reproduce with a single worker, try increasing the number of workers and fixing strace for all processes.

+3
source

Not sure if this will help, but check.

If you process the session manually, then you should do Turning Off sessions, in frontend/config/factories.yml

 all: storage: class: sfSessionStorage param: auto_start: false 

You should see Deactivating unused features to improve performance.

Another assumption:

Sessions are file dependent. Therefore, check that your system is capable of making so many files open for sessions. Or there is a problem with creating files.

+2
source

Source: https://habr.com/ru/post/1235930/


All Articles