title: MYSQL optimize for a lot of GET_LOCK and high number of connections (Codeigniter Sessions)
body: <p>I use Codeigniter 3 with database-backed sessions. It uses <code>SELECT GET_LOCK("$SESSION_ID", 300)</code> to prevent concurrent requests causing issue with session data.</p>
  
  <p>This works fine until I have a ton of traffic causing a bunch of open connections all calling this function and waiting for the lock to be released</p>
  
  <p>It sometimes brings the application to a halt for a couple of minutes. It never reaches my max number of connections in mysql and CPU and RAM usages are fine, but performance is slow for all users of that database server. (Not sure why it doesn't perform ok). I do use pt-kill to remove any queries taking longer than 15 seconds.</p>
  
  <p>I already tried using the redis driver that had its own performance issues so I am back to the database sessions.</p>
  
  <p>So my questions are:</p>
  
  <p>How do I optimize my application to perform well when I get a ton of traffic and cases GET_LOCK queries to pile up and open connections to mysql. I was thinking I could use persistent connection; but not sure if that is a good idea as most people never recommend this</p>