1

I am developing a website where client needs that any notification should reach as soon as it is created. so i am using setinterval function of jquery and using ajax requests to get the notifications. the time interval I set is 2 seconds. and its not the only ajax request which is going this way. there are following ajax request being done within interval of 2 sec

  1. get notifications
  2. get messages.
  3. get counts.
  4. some other checks

I am worried because i think sending this much request at very short time period may disturb the system. and worse if the number of users increase. Please tell me your opinions and solutions to this if this is wrong aproach

1 Answers1

1

I would recommend moving to websockets when possible, but until then, here are a few things to consider.

  1. Make sure you are collecting statistics on numbers of requests, and response times. While not an optimal situation, this could turn into a nightmare for you from a simple javascript error adding an additional 2 second call with each request, a single hung request, or a DDOS attack.
  2. @Traubenfuchs advice is solid. Use setTimeout and only schedule a call once you get a response.
  3. Unless there is a pressing reason, cache the results on the server side for a short period of time to prevent overwhelming your datastore.
  4. Combine all the calls into a single call is possible.