-1

Example: If the first request took about 1.32s, the subsequent requests will take approx 1.18s to 1.2s.

From my research, the first request can be improve by setting the StartServers, MinSpareThreads and MaxSpareThreads in the apache\conf\extra\httpd-mpm.conf

However, there is no guidelines mention that what numbers can really help to increase the first request speed.

Also, some advise that to have a page at the server that keep refreshing on the webpage using the following script:

<html>
<head>

<script>
setTimeout(function(){
   window.location.reload(1);
}, 2000);

</script>

</head>
<body>
<iframe name="iframe" id="iframe" src="http://mywebsite:8080"></iframe> 

</body>
</html>

This page although keep apache busy but it increase the apache log faster.

So, may I know what actions can I do so that I can have the first request to have the same response time or even faster response time than the subsequent request?

Below is the scenario of a first request and subsequent requests:

10:00:01 AM Access URL http://mywebsite.com (Response time: 1.32s - First Request)

10:00:07 AM Access URL http://mywebsite.com (Response time: 1.2s - 2nd Request)

10:00:37 AM Access URL http://mywebsite.com (Response time: 1.19s - 3rd Request)

10:01:07 AM Access URL http://mywebsite.com (Response time: 1.21s - 4th Request)

10:35:35 AM Access URL http://mywebsite.com (Response time: 1.35s - First Request)

10:35:48 AM Access URL http://mywebsite.com (Response time: 1.2s - 2nd Request)

10:51:08 AM Access URL http://mywebsite.com (Response time: 1.36s - First Request)

10:51:13 AM Access URL http://mywebsite.com (Response time: 1.2s - 2nd Request)

10:51:38 AM Access URL http://mywebsite.com (Response time: 1.19s - 3rd Request)

10:52:07 AM Access URL http://mywebsite.com (Response time: 1.23s - 4th Request)

Notice that after a short duration of inactivity, a first request is made and the response time get delayed. However, a subsequent request made within a minute or so does not have that delay.

Thank you.

user275517
  • 101
  • 2
  • This site is not really for writing tutorials. An interesting reference is Ilya Grogorik's [High performance Browser Networking](http://chimera.labs.oreilly.com/books/1230000000545/index.html). – HBruijn May 21 '14 at 07:52
  • this site is for giving answers to people questions. period. full stop. no where does this suggest that questions cannot be elaborative or complex. alot of people just post links to websites which fully answer the question, or a link to another answer somewhere else on the site. in my opinion, the plagiarism. however, it's not up to me to decide what constitutes an answer, nor is it up for you to decide; I have seen people say that this is not a forum. in fact, has any body ever looked up what the definition of a forum is? it may not be one in the traditional sense of the net, but it still is – RapidWebs Jun 05 '14 at 17:17

2 Answers2

3

First: Define first time. First time since when?

Beside that, this can have many reason, most of them normal and no reason to worry about:

  • Files are read from the disk the first time, and from the cache on subsequent requests
  • In case of e.g. PHP files, they are cached by APC etc. and don't need to be compiled again

Again, this is normal and expected and no reason to try to work around in most cases.

As for StartServers etc: The values you need depend on the load of the site but all you have to accomplish is that a client doesn't have to wait for a new process or thread to be forked. For very low-volume sites that could mean as few as one thread/process to be available.

Sven
  • 97,248
  • 13
  • 177
  • 225
  • 1
    Taking your question on 'Define first time' into my question. Thanks. – user275517 May 21 '14 at 08:05
  • This is most likely the disk cache effect. No need to worry. – Sven May 21 '14 at 08:10
  • Are there ways to reduce such effect. This is because if the page is returning much bigger load of data, the delay for the first request will look more severe. (e.g. First request took 4s while subsequent request took 3.6s) – user275517 May 21 '14 at 08:22
  • 1
    Really, why do you think this is such a problem? Yes, there are ways around most of this effects, depending on your specific situation but why does it matter if a site that is used once in half an hour loads the page in 1.2 or 1.3 seconds (or 3.6 instead 4 seconds)? Both is very long anyway, it took my browser ~250ms to load this page, and [SF] is quite database-heavy. – Sven May 21 '14 at 08:42
  • pingdom reports that websites which load around 3.5 seconds loads 50% faster than all sites tested. using a basic ratio comparision, you could easily apply the knowledge gained (learning how to decrease load times) against your website once it becomes more user/CGI/database heavy. i would assume server fault relies upon a CDN for quick load times, therefore your comment is out of the scope of this scenario. – RapidWebs May 28 '14 at 03:06
-2

the server will usually need to go through different stages of processing, each of which might take time to "spin up"

from my general understanding, im not sure if its even possible to have the first request ever be faster than the latter... what is the use case for such reasoning? looking at your code, and your question, you do not reference MySQL or PHP (which can usually be the leading contributor to spin up times on any web server).

leaving out the above: generally, as traffic pours into your webserver/website, your page will tend to load faster. this is because Apache has the ability to get threads in a waiting state, to service the next request. moreover, the operating system will do some caching of file handles and whatnot. as time passes, it will release these, and things will return to normal.

if you receive too much traffic, you will obviously notice a slow down, due to connections being back logged, threads or processes competing for resources, or disk swapping.

From my research, the first request can be improve by setting the StartServers, MinSpareThreads and MaxSpareThreads in the apache\conf\extra\httpd-mpm.conf

again, from what I understand, StartServers, MinSpareThreads and MaxSpareThreads will only help increase load time under peak load times.

generally, you should have StartServers & MinSpareThreads set to a number that meets the demands of your average load requirements on the daily basis.

MaxSpareThreads should be used as a sort of "buffer zone" for holding open threads during times of high load.

To address your issue in particular :

You could possibly use Apache's Disk Caching module, or Memory Caching module, or File Caching module to potentially decrease the time it takes to spin up and serve static content.

RapidWebs
  • 571
  • 4
  • 13
  • May I know the downvote for this answer because I want to know if it is related to my sentence - `From my research, the first request can be improve by setting the StartServers, MinSpareThreads and MaxSpareThreads in the apache\conf\extra\httpd-mpm.conf` – user275517 May 21 '14 at 08:36
  • i would like to know too... it seems that writing a thorough answer that directly addresses your issue and explains the reasoning behind the answer is sufficient for down a down vote. i've been trying to get some reputation in order to gain accesses to some of the different functions on this website. but down-voting, without a comment as to why, makes it harder for people like me to get started. a comment would at-least let me know what i need to improve upon in my next answer. – RapidWebs May 22 '14 at 00:50