Fresh server has weird serve delay

April 29, 2015 889 views
Apache DigitalOcean LAMP Stack PHP Frameworks PHP CentOS

So I am switching our website from AWS to Digital Ocean for cost reasons and so I got the 160 option from Digital Ocean which is about 40% larger than our current server. Setup Apache, Composer, Laravel and httpd.conf files exactly how my main server is setup. However whenever going to any webpage the new Digital Ocean server has a weird 0.5-1 second delay. I would normally just chalk it up to performance but If i go to our about page (no images, loads almost instantly etc) from the AWS server it loads instantly. From the digital ocean server it has a noticeable 0.5-1 second delay. However I do not think this is necessarily CPU/RAM related. I also have a function that takes 1-2 seconds on the AWS server and it takes 1.5-3 seconds. I feel like I might be missing some sort of apache config setting or something. Anyone know what would cause this delay?

As for the obvious questions, CPU / Memory load are at about 1-2% since i'm the only one on the site. Restarting apache seems to have no effect. Both are connected to a remote sql server.

If nothing else maybe you guys could point me in the direction of some httpd.conf files that are optimized for laravel.

Edit:: Note it is not just php files, I tried loading an image that was on both servers, the AWS server responded within 190-220 ms 10/10 times. Whereas Digital Ocean was about 350-440

3 Answers

This is just a guess but I have seen similar issues in the past both on DO and on other hosts. Apache is often configured to perform a reverse DNS lookup on IPs making requests. This DNS request, if the response is slow can cause this type of delay. I would recommend changing the DNS severs listed in /etc/resolv.conf to another public resolver like opendns or google's DNS servers and see if this changes things. If it does, you can consider sticking with different resolvers or turn off reverse DNS lookups.

So I checked that out and it was already set to googles DNS so I do not think I am having any issues there. I messed around with my apache config as I realized I was missing a few modules and I figured out how to fix the mystery lag. However When I run a side by side comparison of loading pages amazon is still outperforming my new DO server by quite a bit even on a t1 Micro. So I have a t1.micro instance which has 1 cpu and about 600 mb of ram. When both of them request a page the micro takes 2.27S and the Digital Ocean takes 3.27S. Then I tested with a simple image load, 80ms from the micro aws and 130 from Digital ocean. This makes me realize that it is not so much the server but my location. I am physically a lot closer to the AWS servers. This timeline pretty much confirms that suspicion as you can see the orange line on digital ocean is my initial connection time http://puu.sh/hwk71/76a762bb91.png . So this lead me to realize that the reason the rest of the site is probably running slowly is that my RDS is still at AWS so every query is now running from San Francisco -> Oregon AWS -> San Francisco -> back to me. Does this seem like a logical explanation for the slowness? If so do you think moving my database to the local digital ocean install would help?

Update! For anyone else out there with anything like this switching from AWS to Digital Ocean. Make sure your database is either on the same server as apache or at least close. I migrated from amazon RDS to local miradb install and it is blowing Amazon out of the water. Thanks for the help.

Have another answer? Share your knowledge.