Web Worm
Web Worm

Reputation: 2066

xmlhttprequest vs jquery load();

i am trying to making php ajax based chat system....and i have developed it successfully...i am using jquery load() with setInterval to reload chat every 1 second and it works fine on my localhost....but when i uploaded it on my hosting server it also works fine ... but problem is that after few mintues of chat the server takes to much long gets heavy loaded so that my server goes and and site goes down...

my question is that, why it is happening so far...and what is the solution...should i use standard xmlhttprequest instead of load() or $.ajax() instead of load();

Upvotes: 0

Views: 786

Answers (4)

nickf
nickf

Reputation: 546503

Tatu is correct - think about what each request is returning and what is actually required. For example, are you returning the entire chat log, or just the new messages since the last poll? If there is no activity for a while, is there a need to poll every second? Consider increasing the poll time each time there's nothing new (and reset it back to 1 second when there is something new).

You could also take a look at COMET methods for applications which require "push" technology.

Upvotes: 1

Salman Arshad
Salman Arshad

Reputation: 272406

Try increasing the refresh interval from 1 second to, say, 10 seconds.

Upvotes: 1

Álvaro González
Álvaro González

Reputation: 146660

jQuery.load() and jQuery.ajax() are basically front-ends for XMLHttpRequest. If they add extra overload (which is possible) it would only affect the browser.

Are you sure your server can handle such load? One request per second means that one single user triggers a minimum of 3600 requests per hour of conversation and I presume each request involves at least a database lookup. Now, being a chat server you are expected to have many simultaneous users.

Things you can try:

  • Lower the refresh rate
  • Do no not send new requests while they're pending ones
  • Make sure the server-side script is lightning fast

Upvotes: 1

Tatu Ulmanen
Tatu Ulmanen

Reputation: 124878

The method you use to make the AJAX request doesn't matter, you have something else wrong in your code that is causing the slowing down.

Upvotes: 2

Related Questions