Any one having any ideas where should I start to fix this issue, the first handshake take sometimes up to 20s, but refreshes after that takes only 0.9s.

The setup,

100/10 Mbps
Windows OS
Intel Core 2 @ 3.0 GHz
And 7200 RPM HDD

Apache 2.4
Mod_Security Enabled
Mod_Deflate Enabled
Mod_Expires Enabled
Mod_ReWrite Enabled
PHP & MySQL on same machine.

I have seen much slower machines preforming better, therefor I think my problem is ony an optimization issue.

  • Couple of questions: Is it a production machine? Is it under load? Have you tried to look at the output of mod_status? How are you performing these tests? Using ab (apache benchmark) are you able to replicate the problem and get some specific metrics?
    – Khai
    Jun 18 '12 at 1:50
  • The server isn't under load, it runs a very lightweight client management system with up to 300 connections at the same time. I'll check the status mod. Jun 18 '12 at 2:32
  • 300 connections could be a lot. Do you mean 300 simultaneously TCP connections that are sending or receiving traffic most of the time? Jun 18 '12 at 2:41
  • Not always, but yes it gets up to 300 TCP connections. (Many users are working on the system at the same time). Jun 18 '12 at 2:45

It seems that you have activated DNS resolving inside apache. This allow you to have hostnames instead of IPs in your apache logs.

If it is not the case, then best way to test is to analyze the network traffic. This can be done with:

  • a network sniffer like WireShark
  • a HTTP proxy/analyzer like Fiddler2
  • a browser plugin like FireBug

You can also start the investigation by running:

curl --trace-time -vI www.example.org

Where www.exmaple.org is your site. Please add this output to your question.

  • I've already tested Firebug, For the first connection that takes 10s, 9.5s is used to resolve the domain and get the initial respons. 0.5s for recieving page conent. So the content is well optimized. Jun 18 '12 at 2:51
  • Than you have a DNS issue. Check if your first DNS server is reachable. Jun 18 '12 at 2:53
  • To rule out that your DNS is, or is not the problem, addd an entry into etc/hosts file with your server_IP followed by your server FQDN. Jun 18 '12 at 2:55
  • What is the output of: nslookup -q=any www.example.com Jun 18 '12 at 2:59
  • If you use WireShark, you will be able to see that the first DNS request will time out. Jun 18 '12 at 3:00

Starting in Windows 6.1 (Server 2008 R2 and Windows 7), Windows has stopped using the hosts file to resolve localhost and now uses it's own DNS resolver which is slow.

Two ways to fix this:

a) You can find and replace every instance of "localhost" to "" in your web applications (database connections), httpd.conf, httpd-vhosts.conf, php.ini and anywhere else you can think of.


b) In the file hosts located here: "C:\Windows\System32\Drivers\etc"

Uncomment the last two lines.

# localhost name resolution is handled within DNS itself.
#       localhost
#   ::1             localhost

This specific problem was caused by mod_bw whitch I'm using on the server to limit traffic usage. It was limiting for all files and caused even the HTML files to get some delay. After configuring this correctly, everything is working just fine.

This site is temporarily in read only mode and not accepting new answers.

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