Alternative for QNetworkAccessManager

陌路散爱 提交于 2019-12-13 16:11:50

问题


I am drawing map in BB10. The map is divided into tiles. At start user gives a longitude, latitude and zoom level and the map is shown at that co-ordinate. I get a single tile by doing a http request with QNetworkAccessManager. At first 7x5 tiles are downloaded. But the problem is when user starts panning in the screen really fast and continues to do so for sometimes then after user stopped panning the tiles are downloaded with a big delay. Each time user does panning some new tiles are downloaded to show in the screen. Now because user continues panning for awhile there are so many unnecessary network requests with QNetworkAccessManager. And my guess is thats why tile downloading is slow. I tried aborting the QNetoworkReply of the QNetworkAccessManager using abort() method for the unnecessary requests. But still its really slow. Is there any alternate way to achieve what I am trying? Thanks.


回答1:


I personally think that the problem is you're making too many unnecessary connections.

Generally, HTTP is considered as a somewhat heavy-weighted protocol. It's built upon TCP, so it requires 3-way handshake to establish and 4-way handshake to terminate, not considering the time to generate and parse those HTTP headers.

Also consider the load of the server. A small ordinary web server handles ~100 requests per second. If your client are performing such frequent request, I'm afraid the server won't be too happy to welcome your application.

So consider limit the request density manually, either by sending requests only when the panning speed is lower than a threshold, or keep a fixed-size queue of pending request and making new requests only when the queue is not full. Just avoid flooding with requests. It does no good to either low-bandwidth clients or to any not-so-idle servers, whatever optimizations you have.



来源:https://stackoverflow.com/questions/14827212/alternative-for-qnetworkaccessmanager

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!