5 secs fixed latency on cgi/perl connect


we are experiencing a 5 seconds latency while connecting to a mySQL server DB (windows) through a perl script running on an apache server (linux).

Both www and db server are almost in idle status and they are connected throug a switched gb lan and are on the same subnet.

Addressing between the two is based on IPs to avoid dns resolution latency.

We get same delay using php directly.
We tryed to connect to different DBs but we always receive 5 secs of delay.
We get no errors in connection, just delay.

Here is the script we are using:

#! /usr/bin/perl -w

print “Content-Type: text/plain\n\n”;

Connect to the database.

eval {
require DBI;
my $dbh = DBI->connect("DBI:mysql:database=xxxxxxx;host=xxx.xxx.xxx.xxx ",
“xxxxxxx”, “xxxxxx”, {‘PrintError’ => 1,‘RaiseError’ => 1});
print “error: $@”;

Any help would be really appreciated!

Is there some relevant reason why you are running the MySQL DBMS on Windows instead of Linux like with your web server?

And do you have a firewall between the DB and the Apache server?

The reason why I’m asking is that I have many times noticed that Windows does some fishy stuff in the background to try to establish credentials of the host it is connecting to/from by connecting to TCP ports 445 and 139.

So if you are dropping packets to these ports in the firewall or something like that you can get similar effects.

It could be something like this that causes what you are experiencing now.

My best suggestion is that you use Linux as DB server also.

We are running our application in hosting through our ISP…
If it was for me: Unix forever…

Anyway www and DB are both in the same subnet in DMZ, no firewall between them.

The DNS in properly configured and works fine.

We obtain this delay (always 5 secs) only in connect, every subsequent operation works fine.

Yes and that could be the Windows credential check.

Because whenever a windows server receives a new TCP connection it tries to authenticate the other server.
So it starts with trying to connect to the other server and in the end if the other server is not answering it continues anyway.

I read about someone that solved it by installaing Samba on the Linux server which means that the windows credential check actually gets a response.

Best tip I can give.


installing Samba server has solved the problem!!!

Thanks again.

Greate, it’s always nice to know when your tips pay off. )

Another possible solution:
In your my.ini:

[B]nateh wrote on Wed, 13 February 2008 21:16[/B]
Another possible solution: In your [B]my.ini[/B]:
Except that that has absolutely nothing to do to this specific problem since this was about windows checking credentials and not a DNS issue.

And even if you do want to tinker with that setting I would say that you can leave name resolve on.
Because usually you only have very few hosts (couple of web servers for example) that connect to the DB and then all these hosts will be available in the host_cache in mysql, which means that the performance impact is marginal at best. And that means that you might as well keep it.

Unless you have really screwed up your DNS settings and then I think you should fix the DNS settings instead.