8

I am running amazon aws ec2 micro instance on Ubuntu 14.04 with apache 2.4.9. The reason for having this instance is just to test and to solve some bugs before rolling up the project. Currently there are only few people (< 10) who are using the project irregularly (< 20 times per day). In my project I am using minification, so I have only few static content there: like 1 css file and may be 3 js files. They are not really big and the sum of all files is below 300Kb.

Reviewing the waterfall diagram, from loading of my project, enter image description here

I have noticed that was amount of time is spent on waiting phase (if I will remove it, most probably the web-site will be loaded more than 2 times faster). Also I known what each of these phases corresponds to (I even answered highly relevant question here), I do not know what exactly can I do to decrease waiting time. In my case big waiting time is added for static resources like css/js/img, so it has nothing to do with writing more efficient code.

I also found another highly relevant question here (which is actually the same question I have) and tried to follow the advice by switching of HostnameLookups Off but it has not changed anything at all.

I do not have /etc/httpd/conf/httpd.conf, therefore I added it into /etc/apache2/sites-available/000-default.conf. Also I do not have anything like LogFormat in my config, therefore I skipped this part.

So is there anything I can do to reduce this time? When I review the same diagram collected from the location of the server, I see small improvement in waiting time, but the situation is still the same.

I do understand that I can move to a better server, with better HDD/RAM/CPU, but this is obvious. Knowing that there are so many configuration parameters for apache, I think that may be there is something there for tuning.

P.S. thanks to JakeGould I looked into apache2.conf and modified it (not 000-default.conf as I mentioned before). I also modified KeepAliveTimeOut to 3 and MaxKeepAliveRequests to 20 which is more suited to my site.

Salvador Dali
  • 925
  • 6
  • 19
  • 31
  • Have you considered using a caching system if it's purely static contest you could try optimized code using html tidy etc . Personally my site runs WordPress so I use w3 total cache with php-apc , nginx, cloudflare and varnish which running a gtmetrix test turned my site from 8 seconds load speed to 1 second it will advise you I'd code changes are required aswell for free. – AidenAndrews May 05 '14 at 22:53
  • I think it is more suited for a comment, not an answer. Moreover optimizing html has nothing to do with `waiting time`. It will reduce `receiving time` because it decreases size of file. Php-apc has also nothing to do with this because this is js/css/img files. – Salvador Dali May 05 '14 at 23:12
  • Why not try a CDN, like CloudFront? Statics would be served from there, and the wait time might be less. – Drew Khoury May 06 '14 at 11:45
  • “I do not have `/etc/httpd/conf/httpd.conf`, therefore I added it into `/etc/apache2/sites-available/000-default.conf`.” Wrong place to tune. It should be in `/etc/apache2/apache2.conf`. That is where it is in Ubuntu 12.04. – Giacomo1968 May 11 '14 at 05:14
  • 1
    Also, I wrote an answer that addresses the multiple issues that can cause web server slowness here. The general message is you need to performance tune MySQL & Apache to get things working nicely. http://serverfault.com/questions/551727/how-much-free-memory-should-i-have-on-my-webserver/551734#551734 – Giacomo1968 May 11 '14 at 05:21
  • @JakeGould thanks for the link. There are some good points regarding keep-alive. – Salvador Dali May 11 '14 at 05:57
  • @SalvadorDali You’re welcome. Also, be sure to throttle down the connections—which are about 255 by default—to something realistic to your site’s traffic. I have worked on high traffic sites that get 80-120 connections per seconds on a good day. By adjusting that you get an instant performance boost. – Giacomo1968 May 11 '14 at 06:29
  • @JakeGould can you please point me where can I change these parameters? – Salvador Dali May 11 '14 at 06:39
  • 1
    @SalvadorDali `/etc/apache2/apache2.conf` – Giacomo1968 May 11 '14 at 06:40
  • 1
    Do a `ping` to check how long round trip traffic is taking. This number is the minimum you can get waiting down to. – Brian May 11 '14 at 10:13
  • Micro instances sucks. You need an instance with higher network performance, because you're trying to fix something impossible at the VPS/server level. Time to first byte depends heavily on network topology and number of hops until your instance. – Marcel May 13 '14 at 13:48

2 Answers2

3

According to the Chrome documentation, the waiting time is "Time spent waiting for the initial response." - but you already knew that.

There doesn't seem to be any further explanation available, but according to the timeline below, the "waiting" stage would logically appear to be either network latency or web server processing - i.e. the time between sending the request for the resource and receiving the first byte of the response.

Chrome timing detail

You've said you're using Amazon EC2, but you haven't said which instance type you're using. Amazon instances are absolutely not created equal, and some have lower storage priority than others, likewise for CPU and network traffic, so you would do well to analyse your bottlenecks - your disk doesn't have to be being thrashed for it to be a bottleneck. You can try moving to an SSD-backed instance such as the m3.medium or m3.large.

To measure your iowait, use the iostat command (contained within the sysstat package on Ubuntu) with a suitable time period while you're making your test requests.

One other contentious resource could be RAM. Linux is usually pretty good with caching files in memory, but if you don't have enough 'free' RAM, Apache will be going to disk for all of the files.

Craig Watson
  • 9,370
  • 3
  • 30
  • 46
  • I updated my question with more detailed info about my project. I am running `micro` instance. Thank your for your suggestions. – Salvador Dali May 11 '14 at 09:42
  • A micro instance would almost certainly be your bottleneck. They are extremely low priority for all resources. You will get much better performance with an m3.medium instance. – Craig Watson May 11 '14 at 10:08
-1

This is a hard disk problem. Most likely the disk you run on is under heavy load and it just takes time to get the data from the disk.

I don't think there is a way to control this on Amazon. You can try to keep the most important content in cache maybe by creating a small ramdisk with the most important static content.

But the best advise for any problems on Amazon EC2 is to get the fuck out there and use your own dedicated own server. It's bad quality (remember the crashs - cloud my arse amazon), it's unsave, it's CIA+NSA accessible and it's very expensive.

Lothar
  • 791
  • 1
  • 5
  • 15
  • “This is a hard disk problem.” Not necessarily. You can tune Apache to perform better & make better use of resources. – Giacomo1968 May 11 '14 at 05:17
  • 1
    The disk is not even close to being under a heavy load, because I just rolled a testing server to check for bugs in my small project. So basically no one except me is using it. I agree about expensiveness and crashes. – Salvador Dali May 11 '14 at 05:58
  • With huge crashs in 2011 and 2012 even killing many terabyte of data ("a cloud is not a backup" Amazon Statement) your comment is just ROTFL. – Lothar May 12 '14 at 00:48
  • I don't know how the disks are attached. Maybe each has its own local disk but i think it's more reasonable that its on a NAS. Did you check this, are you able to extract the disk data to be sure. – Lothar May 12 '14 at 00:54
  • http://www.nydailynews.com/news/national/amazon-cloud-service-crashes-services-article-1.1189704 – Lothar May 12 '14 at 00:56