Why is mysql_pconnect not faster for a remote server?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
akreider
Forum Commoner
Posts: 46
Joined: Mon May 22, 2006 3:54 pm
Location: USA

Why is mysql_pconnect not faster for a remote server?

Post by akreider »

I'm running a mysql server on a DSL connection (running as per the default WAMPserver installation - windows, apache, mysql, php, on a pentium 3). My shared-host website accesses the mysql database - and thus should have a ping time of an average of 50 ms between the shared-host website that serves up the page content and the database.

I try running 40 easy queries (find a name based on an ID match for a single indexed table).

I would expect that mysql_pconnect would be faster - however both it and the regular connect take the same time - around 3 seconds.

PHP is configured to allow persistent connections.

Why aren't persistent connections faster?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Why is mysql_pconnect not faster for a remote server?

Post by Christopher »

Persistent connections are only faster under some specific load conditions. And only the overhead of creating the connection is saved. PHP is already fairly smart about connections. There are other optimizations that are done at the MySQL server level with its caching, etc. Since your query is remote, most of the time is spent transporting the data. So you will probably see little difference.

On top of that, under many normal conditions, persistent connections are actually slower and as I recall it is generally recommended that you do not use them.
(#10850)
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Re: Why is mysql_pconnect not faster for a remote server?

Post by Kieran Huggins »

arborint wrote:On top of that, under many normal conditions, persistent connections are actually slower and as I recall it is generally recommended that you do not use them.
Really? Wow, I always assumed the opposite!

More info (but not the above warning) can be found here: http://ca.php.net/manual/en/features.pe ... ctions.php
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Why is mysql_pconnect not faster for a remote server?

Post by Christopher »

I regularly go though my clients scripts and take out pconnect's because they can take a server to its knees pretty quickly. My recollection is that fairly standard Apache and MySQL shared hosting settings are the ones that cause the problems that they warn about.
(#10850)
akreider
Forum Commoner
Posts: 46
Joined: Mon May 22, 2006 3:54 pm
Location: USA

Re: Why is mysql_pconnect not faster for a remote server?

Post by akreider »

The mysql server is going to be on a dedicated server (yes, I read many warnings about doing this if the server is on shared hosting). The client will be on shared hosting.

I figured there would be overhead since the client and server are 50 ms (and 1000 miles) apart. But apparently the overhead must have more to do with starting up mysql, or creating an apache process or something (I'm guessing here).

Using the client_compression flag did help for larger query results. I guess my main speed hurdle is my upload speed.
Post Reply