I am building new features for a small embedded device with built in web server. It has a basic web based interface with Javascript AJAX. I came across a problem today where I had a setInterval call an AJAX polling function every 500ms, but in Firebug on the XHR monitoring I'd see "aborted" quite a lot. The web UI did not seem to reliably update when things changed on the embedded side. I noticed also in Firebug that the XHR load would take close to 500 ms. I changed the AJAX polling frequency to 1000ms and that solved the problem. But if my analysis is correct, the problem could reoccur if the embedded side starts taking close to 1000ms to load.
So my question is, is there a way to determine optimal polling frequency; where you'd like to have the UI update as frequently as possible, but don't want to overload the server (which is quite slow and limited in my case). Also what does "aborted" actually mean in the Firebug XHR network view?
Thanks, Fred
I am building new features for a small embedded device with built in web server. It has a basic web based interface with Javascript AJAX. I came across a problem today where I had a setInterval call an AJAX polling function every 500ms, but in Firebug on the XHR monitoring I'd see "aborted" quite a lot. The web UI did not seem to reliably update when things changed on the embedded side. I noticed also in Firebug that the XHR load would take close to 500 ms. I changed the AJAX polling frequency to 1000ms and that solved the problem. But if my analysis is correct, the problem could reoccur if the embedded side starts taking close to 1000ms to load.
So my question is, is there a way to determine optimal polling frequency; where you'd like to have the UI update as frequently as possible, but don't want to overload the server (which is quite slow and limited in my case). Also what does "aborted" actually mean in the Firebug XHR network view?
Thanks, Fred
Share edited Jan 3, 2011 at 2:08 fred basset asked Jan 2, 2011 at 21:03 fred bassetfred basset 10.1k29 gold badges93 silver badges140 bronze badges2 Answers
Reset to default 5Don't use setInterval, initiate another request with setTimeout after you get the response back.
500ms is too often. Try 2 seconds and work backwards once it works. Also, you might want to do something like start with 2 seconds, and if doesn't work after some number of tries, increase to 5 seconds (or whatever). I see that a lot.
Note, having to poll sucks. If you have a modest user base of 100 concurrent users, and they are all using the work flow that requires polling, your application can be flooded with hundreds of requests every second. In other words, polling doesn't scale very well, unless you have the resources to stand up servers horizontally. Depending on your use-case, it might be better to just submit the initial request to start the long running process asynchronously, and tell the user to check back after 2 minutes.
Let me ask this: how long should it take for the task for which you poll to be pleted?
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744950273a4602877.html
评论列表(0条)