CodeIgniter Forums
how to optimize SESSION on codeigniter ? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=11)
+--- Thread: how to optimize SESSION on codeigniter ? (/showthread.php?tid=74073)



how to optimize SESSION on codeigniter ? - oujisama - 07-19-2019

hello folks

i have mid-range web application that serve at least 40.000 traffic per day ( based on google analytics ) 

i want to know whether you guys that already develop a mid or hi range kind of application also face this kind of problem like mine or not ?

i got an issue with CI session always taking so much resource in our database and sometimes causing a dead lock also 

currently we are using MYSQL database from AWS RDS

[Image: BJ983dp.png]


as you can see, there always a time when the session spiking and causing slow ( sometimes until deadlock ) in our web apps

and for your information

i also comment this line of code before to prevent session being locked cause if not it will become worse, our application will become super slow

[Image: ckxwQez.png]


please kindly share me a guidance on how to optimize CI Session using database

thank you


RE: how to optimize SESSION on codeigniter ? - jreklund - 07-19-2019

Make sure your ci_sessions table are InnoDB as MyISAM can't be read and updated at the same time.
Does your ID column have an index?


RE: how to optimize SESSION on codeigniter ? - oujisama - 07-19-2019

Thanks for the reply,

Yes i already implement indexing on ID as well as on the timestamp also
But once again the problem still occur due to the high traffic.


RE: how to optimize SESSION on codeigniter ? - hc-innov - 07-21-2019

(07-19-2019, 10:39 PM)oujisama Wrote: Thanks for the reply,

Yes i already implement indexing on ID as well as on the timestamp also
But once again the problem still occur due to the high traffic.

Maybe the documentation can help you: performance issues with sessions


RE: how to optimize SESSION on codeigniter ? - includebeer - 07-24-2019

Hc-innov is right. Read this page carefully! It clearly says to NOT remove the lock and what to do instead:

Quote:you may conclude that locking is the issue and therefore look into how to remove the locks …

DO NOT DO THAT! Removing locks would be wrong and it will cause you more problems!

Locking is not the issue, it is a solution.
...
Long story short - call session_write_close() once you no longer need anything to do with session variables.