![]() |
Sessions Performance Issue (php7.1, CI 3.1.5) - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6) +--- Forum: CodeIgniter 3.x (https://forum.codeigniter.com/forumdisplay.php?fid=17) +--- Thread: Sessions Performance Issue (php7.1, CI 3.1.5) (/showthread.php?tid=68765) |
Sessions Performance Issue (php7.1, CI 3.1.5) - gregavola - 08-22-2017 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? RE: Sessions Performance Issue (php7.1, CI 3.1.5) - gregavola - 08-23-2017 This solved my problems - wish this would be documented better with CI: https://ma.ttias.be/php-session-locking-prevent-sessions-blocking-in-requests/ RE: Sessions Performance Issue (php7.1, CI 3.1.5) - InsiteFX - 08-24-2017 It's been documented all over the forums here but maybe it should be pinned some place. RE: Sessions Performance Issue (php7.1, CI 3.1.5) - Paradinight - 08-24-2017 (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-prevent-sessions-blocking-in-requests/ https://www.codeigniter.com/user_guide/libraries/sessions.html?#a-note-about-concurrency Quote:A note about concurrency RE: Sessions Performance Issue (php7.1, CI 3.1.5) - gregavola - 09-21-2017 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? RE: Sessions Performance Issue (php7.1, CI 3.1.5) - Paradinight - 09-21-2017 (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 { RE: Sessions Performance Issue (php7.1, CI 3.1.5) - spjonez - 09-22-2017 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. RE: Sessions Performance Issue (php7.1, CI 3.1.5) - blasto333 - 12-11-2019 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 |