Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd noticed for ages that a MySQL database connection over my LAN was significantly slower than a database connection over the Internet.

I'm running Windows 7 32bit and I'm connected to a switch using an Ethernet cable. The switch is connected to a modem/router which is where my Internet connection arrives in the building. I am not using WiFi.

I ran the following code:

//store current time
$start = microtime(true);

//connect to database outside my LAN
$c1 = mysql_connect("", "user1", "pass1");
mysql_select_db("database1", $c1);

//print out the time taken in seconds
echo microtime(true) - $start, "<br>";

//close the database connection

//store current time
$start2 = microtime(true);
//connect to database on my LAN
$c2 = mysql_connect("", "user2", "pass2");
mysql_select_db("database2", $c2);

//print out time taken in seconds
echo microtime(true) - $start2, "<br>";

//close database connection

three times which returned the following times:

External WAN database: 0.054498910903931, 0.055356025695801, 0.05623197555542

Internal LAN database: 5.0052859783173, 5.0053160190582, 5.005627155304

The LAN file transfer speed (using Samba to share the drive on the Ubuntu machine) is approx 30MB/s and my broadband connection speed is 35Mbps down and 7Mbps up.

Anecdotally, logging into the local server using SSH is quite laggy.

I don't know what other information you might need, so please ask for more, I'm stumped as to why a local connection is so much slower!

share|improve this question
So ssh and database connections are slow to this machine, so this is a network issue rather than a database issue? I'd check the routing table and a mismatch between the physical speed of the interface and the switch port first. – Paul Jan 20 '12 at 13:06
@Paul thanks - managed to track down the issue thanks to Wireshark, Google and Ubuntu's bug tracking website – Jon Jan 20 '12 at 13:13
up vote 2 down vote accepted

I used Wireshark to inspect the connection traffic, and found a number of MDNS requests that seemed to be failing.

Subsequently I came across this bug with the Ubuntu Name Service Switch Configuration and changed the /etc/nsswitch.conf file to use mDNS as a last resort as described on the Ubuntu Server Network Configuration page.

Restarting the required services (MySQL, SSH) sped everything up like magic!

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .