A bad way to use ajax
A friend of mine ask me about using ajax to create a small counter for his site, he wanted to update the counter every xx seconds to show how many users are visiting his site at the same time.
The idea is nice but after a 10 second thinking I’ve stopped him to implement such feature.
Why? Think about to use a small file (1kb) where you save the counter value.
Now, select as refresh time 5 seconds, every minutes a user will receive 12 refresh of the counter element (=12kb).
This isn’t a real problem for a single user but if the site has more than 100 users online? Every minutes the script will use quite 1Mb of server bandwith…
Do you see the path? If you use an ajax counter like this in a community forum with 100 different browser session, and is not rare that a user opens more than one session to read different posts, always online you’ll waste 60Mb/h => 1,4Gb day!!!
A good use of ajax should be very usefull, but a bad use will surely kill your servers…
ciuaz
6 comments so far
Rispondi



I Fulloly agree with you.
He can do what Apple and Google have done, and make a Guesstimate based on an initial value and an estimation of visitors-per-second.
ITunes counter walkthrough
[...] RTOC è una piccola applicazione ajax per tracciare le visite (ed i visitatori) di un blog.. casualmente il server su cui è ospitato il servizio sta registrando un certo sovraccarico… [...]
I’ve translated this text in Italian.
You can see it here:
http://gigasoft.altervista.org/blog/archive-read-1146944953
Um, I can see your point mate, but you might want to check your math.
100 x 1kb is not a megabyte, it’s 100k
you’ve followed this error though on your calculations, so your numbers are all 10 times bigger than they should be.
The point remains though. High traffic sites this method could cause you to bleed.
ehm the right count is 1k x 12 req/min x 100 users = 1200k