Forum Moderators: phranque

Message Too Old, No Replies

Page loading process

Client page loading and server request processing

         

alexcazacu

12:40 am on Nov 14, 2007 (gmt 0)

10+ Year Member



Hello there!

I have a problem with a site that i'm currently doing maintenance for.

A bit of an intro:

Over the years i used several hosting solutions, which gradually got better and better (hardware and bandwidth wise). However, over the past few months, the performance durring high traffic hours has gotten horrible: incredibly long load times, very high server load, etc.

Even though the site engine is quite old and outdated(a much needed upgrade is now underway), i cannot explain the recent performance drop. Visitor count is about the same, server hardware and bandwidth are better, no major feature or modification was recently added/made to the current engine...

The only modification i can think of is the various JS code written in the templates for ads, traffic counters and various external content written in the site.

Now i noticed that when the page loads, when it gets to a piece of JS code that draws content from an external server, it executes it and waits for a response. If the external server takes too long to respond or doesn't respond at all, the page stops loading at that exact point where the js is being executed. I haven't studied the process to see exactly how it works (that's why i joined this community which is btw great...a lot of answers here :) ) but what happens to the server in this interval? Does it keeps working on the request made by the client until the js code executes?

To be more explicit, ill describe the process as i see it in two steps:

1.client sends http request to server
2.server receives request from client, generates the page and sends response back to the client

What i don't understand is what exactly happens at step 2.
I would think that the page is fully generated and then delivered to the client, the request is considered processed and "closed".
Or is it more like the page is being delivered the the client as it is being generated thus keeping the request "open" until the client's browser is finished loading? (in this last case i can attribute the astronomical server load figures to the js that is running in the page...)

If the above explanations are unclear, my apologies are in order as i'm not familiar with this at all. I read the apache docs on this topic but i haven't found an answer there...

Note: as mentioned earlier, the web server is apache 2.2 and the content generator is php

Thank you for your time!

jdMorgan

3:14 am on Nov 14, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



JavaScript is processed client-side --i.e. by the browser and its CPU-- and has nothing to do with your server load unless it (the JS) is requesting objects (e.g. images, etc.) from your server.

Jim

vincevincevince

3:29 am on Nov 14, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



First, move all your external javascript, wherever possible, to just before the </body> tag. Don't put it in the HEAD or earlier in the BODY. That will make a big difference.

What you describe is correct, the browser will not wish to render content before the javascript included at that point has been downloaded.

You can reduce these problems by not using a table-based layout. Even better, copy the external javascripts to your server and reference them there.

alexcazacu

2:32 pm on Nov 14, 2007 (gmt 0)

10+ Year Member



Thanks for the replies!

Here's what i did:

I placed all the ad codes in separate files and loaded them into the main page with iframes. Now the difference is that when the page loads, it gradually renders it with initially empty iframes. This way even if the response from the external server is slow, the main body finishes the loading process, thus completing the request, ads and external content is rendered independently without stalling the page load process.

I talked to the IT guys today and they explained to me that the worker is kept busy until the main page is loaded (i think i got it right...seems pretty logic to me)...i didn't get the chance to see how this works out in high traffic hours as the first peak has already passed, according to statistics i should see this working in about 5 hours or so when the traffic reaches a peak. Anyway, i checked the parse time on several pages and once i made this modification it dropped from ~4000ms to ~500ms. I would say quite an improvement!

Ill post back here in a couple of hours (after traffic peak) to let you know hot it worked out. Maybe someone else will find this useful.

Alex