QNetworkAccessManager的替代 [英] Alternative for QNetworkAccessManager

查看:308
本文介绍了QNetworkAccessManager的替代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在BB10中绘制地图.该地图分为图块.开始时,用户给出经度,纬度和缩放级别,并且地图以该坐标显示.通过使用QNetworkAccessManager进行http请求,我得到了一个图块.首先下载7x5的图块.但是问题是,当用户真正快速开始在屏幕中平移并继续这样做时,有时在用户停止平移之后,瓷砖的下载就会延迟很长时间.每次用户平移时,都会下载一些新的图块以显示在屏幕上.现在,由于用户继续平移了一段时间,因此QNetworkAccessManager发出了太多不必要的网络请求.我的猜测是,这就是为什么图块下载缓慢的原因.我尝试对不必要的请求使用abort()方法中止QNetworkAccessManager的QNetoworkReply.但是它仍然真的很慢.是否有其他替代方法可以实现我正在尝试的功能?谢谢.

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.

推荐答案

我个人认为问题在于您建立了太多不必要的连接.

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

通常,HTTP被认为是权重较高的协议.它基于TCP,因此需要3次握手来建立,而4次握手要终止,而不用考虑生成和解析这些HTTP标头的时间.

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.

还要考虑服务器的负载.小型的普通Web服务器每秒可处理约100个请求.如果您的客户正在执行如此频繁的请求,恐怕服务器不会太乐意欢迎您的应用程序.

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.

这篇关于QNetworkAccessManager的替代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆