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

Annunci

6 pensieri su “A bad way to use ajax

  1. 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.

Rispondi

Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:

Logo WordPress.com

Stai commentando usando il tuo account WordPress.com. Chiudi sessione / Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione / Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione / Modifica )

Google+ photo

Stai commentando usando il tuo account Google+. Chiudi sessione / Modifica )

Connessione a %s...