Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Persistent vs non-Persistent - Which should I use?

Tags:

mysql

My site has always used persistent connections, based on my understanding of them there's no reason not to. Why close the connection when it can be reused? I have a site that in total accesses about 7 databases. It's not a huge traffic site, but it's big enough. What's your take on persistent, should I use them?

like image 903
Webnet Avatar asked Sep 22 '10 02:09

Webnet


1 Answers

With persistent connections:

  • You cannot build transaction processing effectively
  • impossible user sessions on the same connection
  • app are not scalable. With time you may need to extend it and it will require management/tracking of persistent connections
  • if the script, for whatever reason, could not release the lock on the table, then any following scripts will block indefinitely and one should restart the db server. Using transactions, transaction block will also pass to the next script (using the same connection) if script execution ends before the transaction block completes, etc.

Persistent connections do not bring anything you can do with non-persistent connections.
Then, why to use them, at all?
The only possible reason is performance, to use them when overhead of creating a link to your SQL Server is high. And this depends on many factors like:

  • database type
  • whether MySQl server is on the same machine and, if not, how far? might be out of your local network /domain?
  • how much overloaded by other processes the machine on which MySQL sits

One always can replace persistent connections with non-persistent connections. It might change the performance of the script, but not its behavior!

Commercial RDMS might be licensed by the number of concurrent opened connections and here the persistent connections can misserve

like image 177