0

I am trying to figure out what kind of load the window function setInterval() places on a user's computer. I would like to place a setInterval() on a page that is viewable only by my company's employees that will be checking a basic text file every 5 seconds or so and then if there is something to display, it will throw up some html code dynamically on the screen.

Any thoughts? Any better, less intrusive way to do this?

jcsbrotha
  • 89
  • 2
  • 15
  • setInterval puts barely any load on your user's machine; what you DO once the interval hits is where it matters. You should measure the impact of reading the text file instead. – Mike Robinson May 01 '13 at 19:41
  • A single `setInterval()` would only bring down the absolute weakest computers ever made. – j08691 May 01 '13 at 19:42
  • i'm sure your machine can handle the task described. – dandavis May 01 '13 at 19:42
  • http://stackoverflow.com/questions/12554531/setinterval-performance http://stackoverflow.com/questions/13792501/is-setinterval-bad-for-performance http://stackoverflow.com/questions/5444454/javascript-setinterval-performance-benchmark http://stackoverflow.com/questions/16104014/how-does-setinterval-affect-performance http://stackoverflow.com/questions/8701754/just-disable-scroll-not-hide-it can you estimate the load duplicate question put on SO! ;) – Ejaz May 01 '13 at 19:43
  • I've once had an application which was firing hundreds of ajax requests per minute using setInterval. Close to no CPU usage or anything else, so there shouldn't be any problems with this... – Marcel Gwerder May 01 '13 at 19:44
  • Thanks all! I appreciate the information. – jcsbrotha May 01 '13 at 19:51
  • @Ejay believe it or not, I did actually try to search SO for the question, but probably did not look long or hard enough or did not use the right terminology. – jcsbrotha May 01 '13 at 19:56
  • How is the text file being read? You probably should just do a callback loop where you're only rechecking the text file after the previous check has finished. Otherwise you'll hit the server harder than you need to. – zzzzBov May 01 '13 at 19:59
  • Note that frequent polling will prevent the computer from going into low power states, which will shorten battery run time/waste electricity – Raymond Chen May 02 '13 at 01:15

2 Answers2

0

Appears it should not cause a problem, pending that the function setInterval() fires off is not heavy. Since I will only be reading a text file which should never be too large (text file will be overwritten about every minute by a completely separate job or bash script), the load should be minimal since it will be read in as a string, analyzed, and if necessary throw out a small amount of HTML code to the page.

jcsbrotha
  • 89
  • 2
  • 15
0

I agree with all the comments regarding a single, polling setInterval() to be trivial.

However, if you want alternatives:

Long Polling

The browser makes an Ajax-style request to the server, which is kept open until the server has new data to send to the browser, which is sent to the browser in a complete response.

Also see:

Web Sockets

WebSockets is an advanced technology that makes it possible to open an interactive communication session between the user's browser and a server. With this API, you can send messages to a server and receive event-driven responses without having to poll the server for a reply.

Community
  • 1
  • 1
Tim Medora
  • 51,363
  • 11
  • 111
  • 149