extreme slowness with a remote database in Drupal

Solution 1:

It seems your connections to the DB are slow due to some other reason. How fast is a simple command line connection? (ie, non-php)

My prime suspect would be failing (= timing out) dns lookups on the remote or local server; both forward and reverse lookups.

From this page: start mysqld with --skip-name-resolve

If that doesn't help, I would start analyzing the tcp connections (tcpdump/wireshark) to isolate the problem. (on top of my head: local dns lookups, firewall issues (overloaded NAT box somewhere?), packetloss on the link somewhere, ..)

When this problem is solved, you probably also want to make sure you have persistent DB connections in PHP.

Solution 2:

The reason could be added delays when using name resolving in the MySQL server. For every connection, mysql checks the DNS name of the client, which will dramatically increase latency.

You can check if this is the case for you if you have the line skip-name-resolve in your my.cnf. If it is not there, add this line, restart the server and try again.