Sessions Performance Issue (php7.1, CI 3.1.5) |
Currently, within the Session library when using file - we see `CI_Session_files_driver::read` taking up to 20s to process. We have tried using Redis, and see the same thing on `CI_Session_files_driver::_lock`.
I've done the following: 1) Add `session_write_close();` to Sessions.php anytime I touch the session object before returning 2) Added `php_value session.gc_probability 10 php_value session.gc_divisor 100` to my `.htaccess` to kick off garabage collection. 3) Use my own folder for `session_save`, and put it outside the web directory, and gave `www-data` access as the owner. Sessions are pouring in, and getting removed so I know GC is working, but I see still see these performance issues on requests tracked in NewRelic where it takes 13-20s at some times to read the file (open it for lock). An `ls -l` shows the following on the sessions folder: drwxrwxrwx 2 www-data root 1126400 Aug 23 04:34 session I assume this is a IO issue, where the file is being written and read from the same time, but 1) should address this. Anytime a session is touched (read or write) I add `session_write_close();`. I applied this on: - `public function sess_destroy()` - `public function userdata($key = NULL)` - `public function set_userdata($data, $value = NULL)` - `public function unset_userdata($key)` All these function do a `session_write_close()` before return. Any other ideas on performance issues or this is a bug?
This solved my problems - wish this would be documented better with CI: https://ma.ttias.be/php-session-locking-...-requests/
It's been documented all over the forums here but maybe it should be pinned some place.
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
(08-23-2017, 10:10 PM)gregavola Wrote: This solved my problems - wish this would be documented better with CI: https://ma.ttias.be/php-session-locking-...-requests/ https://www.codeigniter.com/user_guide/l...oncurrency Quote:A note about concurrency
I just want to point out while the documentation it simply does not work. There are tons of articles and documentation, but a clear answer:
According to CI docs you should do this: Long story short - call session_write_close() once you no longer need anything to do with session variables. However, adding this to the Session Lib doesn't work, where are they supposed to go?
(09-21-2017, 11:29 AM)gregavola Wrote: I just want to point out while the documentation it simply does not work. There are tons of articles and documentation, but a clear answer: eg. PHP Code: class Musterclass extends CI_Controller {
You can read from sessions after calling session_write_close( ); but you can't write to them. In every controller method either call this first inside your method or immediately after the last session write call. This is assuming you're auto-loading the session library. If you aren't you can call close in the places you do use sessions after you're done writing to them.
I have the following code below and even in the view method, it can still get locked (With redis or database driver). I want to be able to run the view method parallel. It doesn't seem to do this all the time.
Code: <?php |
Welcome Guest, Not a member yet? Register Sign In |