Question

I'm developing a small app using Ajax and http requests. Currently i'm sending one request each second to server for checking if there are updates, and if there are, to get them and download data.

This timing profile is modified when a user interact with the app, but it's negligible.

I'm just wondering.. i could send an infinite loop of requests to the server. more the requests are often, more the app will be speedy. but then doesn't server get too many requests?

but how much is the right time from a request to another one?

I've read something about tokens, but i can't understand which is the better way to check if servers have some updates. thanks in advance

Was it helpful?

Solution

Long polling is one of the main options here. You should look into the server and see that there is good support for persistent HTTP connections if you expect to have a large number of users persistently connected.

For example, Apache webserver on its own opens a thread per connection, that can be a notable challenge with regard to many users with persistent connections, you end up with lots of threads (there are approaches to address it in Apache which you can research further if need be). Jetty, a java based web server (among my personal favorites), uses a more advanced network library that scales connections to threads much more logarithmically and efficiently, essentially putting connections to sleep until traffic in/out is detected.

Here are a few link:

http://en.wikipedia.org/wiki/Push_technology

http://en.wikipedia.org/wiki/Comet_(programming)

http://www.einfobuzz.com/2011/09/reverse-ajax-comet-server-push.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top