Is there anything I can do to decrease waiting time for my static http requests (in chrome's network panel)?

5,968

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.

Share:
5,968

Related videos on Youtube

Salvador Dali
Author by

Salvador Dali

I am a Software Engineer in the Google Search Growth team. I use Tensorflow and TFX to analyze search data and Go to write data pipelines. This is my personal profile which has absolutely nothing to do with my employer.

Updated on September 18, 2022

Comments

  • Salvador Dali
    Salvador Dali almost 2 years

    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.

    • AidenAndrews
      AidenAndrews about 10 years
      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.
    • Salvador Dali
      Salvador Dali about 10 years
      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.
    • Drew Khoury
      Drew Khoury about 10 years
      Why not try a CDN, like CloudFront? Statics would be served from there, and the wait time might be less.
    • Giacomo1968
      Giacomo1968 about 10 years
      “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
      Giacomo1968 about 10 years
      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. serverfault.com/questions/551727/…
    • Salvador Dali
      Salvador Dali about 10 years
      @JakeGould thanks for the link. There are some good points regarding keep-alive.
    • Giacomo1968
      Giacomo1968 about 10 years
      @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.
    • Salvador Dali
      Salvador Dali about 10 years
      @JakeGould can you please point me where can I change these parameters?
    • Giacomo1968
      Giacomo1968 about 10 years
      @SalvadorDali /etc/apache2/apache2.conf
    • Brian
      Brian about 10 years
      Do a ping to check how long round trip traffic is taking. This number is the minimum you can get waiting down to.
    • Marcel
      Marcel about 10 years
      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.
  • Giacomo1968
    Giacomo1968 about 10 years
    “This is a hard disk problem.” Not necessarily. You can tune Apache to perform better & make better use of resources.
  • Salvador Dali
    Salvador Dali about 10 years
    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
    Salvador Dali about 10 years
    I updated my question with more detailed info about my project. I am running micro instance. Thank your for your suggestions.
  • ObiwanKeTobi
    ObiwanKeTobi about 10 years
    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.
  • Lothar
    Lothar about 10 years
    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
    Lothar about 10 years
    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
    Lothar about 10 years