I notice that WordPress is using the mysql_connect() function to establish a new database connection on every page. The mysql_pconnect() function uses the exact same API, but has built-in connection pooling to keep connections alive between requests. Generally, using mysql_pconnect() improves performance because your PHP application doesn’t have to wait for a new connection to be made, and reduces the number of connections that need to be open to the database.
I’ve been doing some very informal benchmarking on my server. Once I exceed ~70 simultaneous requests, WordPress is unable to establish more connections to the database, and I receive a lot of errors. (We’re talking like an 80% failure rate with 200 simultaneous requests.) When I switch the mysql_connect() function to mysql_pconnect(), the failure rate drops noticeably (down to about 0.5%). There’s no noticeable adverse affect on resource usage or .
Does anyone know if there was a deliberate design decision *not* to use persistent connections? If not, does anyone have a reason why I *shouldn’t* submit a bug or a patch to switch to the mysql_pconnect() function?
- The topic ‘MySQL and Persistent Connections’ is closed to new replies.