开发者

Is xmlHttpRequest imlementation optimized enough to send thousands of requests without page reload?

开发者 https://www.devze.com 2023-02-12 23:00 出处:网络
We need to develop a client application that has to update some values (about 10-20 integers) each second, over HTTP protocol (however, the HTTP server is running the same machine, so requesting \'loc

We need to develop a client application that has to update some values (about 10-20 integers) each second, over HTTP protocol (however, the HTTP server is running the same machine, so requesting 'localhost' is fast). Since the UI must be easily modified, the decision was made to develop simply a HTML website and update the values using xmlHttpRequest (actually, using jQuery).

The problem is that the client is supposed to work continuously a whole year with no restart... This gives 3600 requests per hour, 86 400 per day, finally 30 758 400 requests per year. I'm very afraid how the browser will deal with such amount of requests... Has anyone any experience with "stresstest开发者_开发知识库" of AJAX requests? Would reloading the page once a day help the browser with cleaning up memory?


First issue: Javascript runtime performance varies from browser to browser. You'd be better off finding a fast, stable browser than worrying about jQuery's AJAX performance. I'd be much more worried about keeping an instance of a browser rendering and executing for a whole year.

Second issue: javascript in the browser isn't a timing-precise language. setInterval and setTimeout are unreliable and do not guarantee timing. jQuery's author wrote this article on Javascript time issues, so Javascript might lead to some problems if you need that really precise timing.

Third issue: if your client needs to run for 365 days without restarting, then aren't the sacrifices you're making by choosing to build an HTML/JS frontend somewhat silly for the loft goal of "easily editable?"


Make sure they're not using IE and you'll be off to a flying start.


xmlHttpRequest is able to handle that much queries (short-polling fw like comet does this), but ... lots of queries may have an impact on the browser's responding capabilities depending on the browser. You can easily scale down the number of queries by a 10-20 factor just by requesting all integers together (using json data structure for example). You may have a look at short-polling as well as it is designed for that kind of purpose.

0

精彩评论

暂无评论...
验证码 换一张
取 消