Ajax XMLHttpRequestObject not ready - server or client too slow?

N

NickPick

I'm currently working on a site that will generate a lot of traffic
for the server. It refreshes certain text items every second with a
XMLHttpRequest Object (as seen below). The javascript getData function
is called every second (it is called every second for every object).
My question is, how can I optimize the performance. It happens from
time to time that the object are not ready yet before they are called
again (i.e. no "200" reply), which results in no refresh. Is this
performance problem likely on the server side or could it be a client
problem as well? Would it be more efficient to use only one object
that refreshes a lot of data rather than many objects that refresh
little data only?

Any advice is appreciated






<script type="text/javascript">

var XMLHttpRequestObject = new Array();

for (var x=0;x<=20;x=x+1) {
XMLHttpRequestObject[x] = false;
if (window.XMLHttpRequest) {
XMLHttpRequestObject[x] = new XMLHttpRequest();
} else if (window.ActiveXObject) {
XMLHttpRequestObject[x] = new ActiveXObject("Microsoft.XMLHTTP");
}
}


function getData(dataSource, divID, objNo)
{
if(XMLHttpRequestObject[objNo]) {
var obj = document.getElementById(divID);
XMLHttpRequestObject[objNo].open("GET", dataSource);
XMLHttpRequestObject[objNo].onreadystatechange = function()
{
if (XMLHttpRequestObject[objNo].readyState == 4 &&
XMLHttpRequestObject[objNo].status == 200) {
obj.innerHTML = XMLHttpRequestObject[objNo].responseText;
}
}
XMLHttpRequestObject[objNo].send(null);
}
}
</script>
 
D

David Mark

I'm currently working on a site that will generate a lot of traffic for the server.

It is good to be optimistic.
It refreshes certain text items every second with a
XMLHttpRequest Object (as seen below).

I see. Not so good to be mad.
The javascript getData function
is called every second (it is called every second for every object).

And there are multiple objects?
My question is, how can I optimize the performance. It happens from
time to time that the object are not ready  yet before they are called
again (i.e. no "200" reply), which results in no refresh. Is this
performance problem likely on the server side or could it be a client
problem as well? Would it be more efficient to use only one object
that refreshes a lot of data rather than many objects that refresh
little data only?

Any advice is appreciated

Scale back your first effort.

[snip]
 
N

NickPick

I'm currently working on a site that will generate a lot of traffic forthe server.

It is good to be optimistic.
It refreshes certain text items every second with a
XMLHttpRequest Object (as seen below).

I see.  Not so good to be mad.
The javascript getData function
is called every second (it is called every second for every object).

And there are multiple objects?
My question is, how can I optimize the performance. It happens from
time to time that the object are not ready  yet before they are called
again (i.e. no "200" reply), which results in no refresh. Is this
performance problem likely on the server side or could it be a client
problem as well? Would it be more efficient to use only one object
that refreshes a lot of data rather than many objects that refresh
little data only?
Any advice is appreciated

Scale back your first effort.

[snip]

I was hoping for a more useful post. Thanks
 
N

NickPick

I'm currently working on a site that will generate a lot of trafficfor the server.
It is good to be optimistic.
It refreshes certain text items every second with a
XMLHttpRequest Object (as seen below).
I see.  Not so good to be mad.
The javascript getData function
is called every second (it is called every second for every object)..
And there are multiple objects?
My question is, how can I optimize the performance. It happens from
time to time that the object are not ready  yet before they are called
again (i.e. no "200" reply), which results in no refresh. Is this
performance problem likely on the server side or could it be a client
problem as well? Would it be more efficient to use only one object
that refreshes a lot of data rather than many objects that refresh
little data only?
Any advice is appreciated
Scale back your first effort.
[snip]
I was hoping for a more useful post. Thanks

Make of it what you will.  I've read your recent half dozen posts and
the best is advice is a reality check.

All right, and what's your advice regarding the XMLHttpRequestObject?
 
R

rf

NickPick said:
I'm currently working on a site that will generate a lot of traffic
for the server.

It is good to be optimistic.
It refreshes certain text items every second with a
XMLHttpRequest Object (as seen below).

I see. Not so good to be mad.
The javascript getData function
is called every second (it is called every second for every object).

And there are multiple objects?
My question is, how can I optimize the performance. It happens from
time to time that the object are not ready yet before they are
called
again (i.e. no "200" reply), which results in no refresh. Is this
performance problem likely on the server side or could it be a
client
problem as well? Would it be more efficient to use only one object
that refreshes a lot of data rather than many objects that refresh
little data only?
Any advice is appreciated

Scale back your first effort.

[snip]

I was hoping for a more useful post. Thanks

Like for example "some people pay per byte for their internet bandwidth. If
you sit there using up some of it every second they thay are going to run
far far away."?
 
R

rf

NickPick said:
On Mar 29, 7:36 pm, David Mark <[email protected]> wrote:
On Mar 29, 2:29 pm, NickPick <[email protected]> wrote:
I'm currently working on a site that will generate a lot of
traffic for the server.
It is good to be optimistic.
It refreshes certain text items every second with a
XMLHttpRequest Object (as seen below).
I see. Not so good to be mad.
The javascript getData function
is called every second (it is called every second for every
object).
And there are multiple objects?
My question is, how can I optimize the performance. It happens
from
time to time that the object are not ready yet before they are
called
again (i.e. no "200" reply), which results in no refresh. Is this
performance problem likely on the server side or could it be a
client
problem as well? Would it be more efficient to use only one object
that refreshes a lot of data rather than many objects that refresh
little data only?
Any advice is appreciated
Scale back your first effort.

I was hoping for a more useful post. Thanks

Make of it what you will. I've read your recent half dozen posts and
the best is advice is a reality check.

All right, and what's your advice regarding the XMLHttpRequestObject?

Use it (with a suitable fallback when JavaScript is not available) when the
user interacts in some way with your page and you need to present further
information.

Do *not* use it to poll the server, expecially not every second and very
especially not multiple times per second. That is *not* what it was designed
for. In fact that is not what the HTTP protocol was designed for.

There was a case a few months ago where someboty from .nl did this,
downloading 5KB every second. Now, 5KB doesn't seem that big but when it
happens every second it mounts up. I worked out that he would have used up
my entire months bandwidth allocation (at the time) in just a few hours.
After I used my allocation I got charged twenty cents per megabyte.
 
N

NickPick

NickPick said:
I'm currently working on a site that will generate a lot of traffic
for the server.
It is good to be optimistic.
It refreshes certain text items every second with a
XMLHttpRequest Object (as seen below).
I see. Not so good to be mad.
The javascript getData function
is called every second (it is called every second for every object).
And there are multiple objects?
My question is, how can I optimize the performance. It happens from
time to time that the object are not ready yet before they are
called
again (i.e. no "200" reply), which results in no refresh. Is this
performance problem likely on the server side or could it be a
client
problem as well? Would it be more efficient to use only one object
that refreshes a lot of data rather than many objects that refresh
little data only?
Any advice is appreciated
Scale back your first effort.
[snip]
I was hoping for a more useful post. Thanks

Like for example "some people pay per byte for their internet bandwidth. If
you sit there using up some of it every second they thay are going to run
far far away."?

I'll show you what I'm during towards the end of the week and I'm
grateful if you could give me some more advice. It's a penny-auction
site where auctions last less than 5 minutes and the user needs to be
updated every second how long the auction still lasts and whether
somebody else has made a bid.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top