gpt4 book ai didi

android - 如何在 android Volley 中优化 network-queue-take? ( Volley 谷歌 IO 2013)

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:34:51 27 4
gpt4 key购买 nike

下面是图像请求的 Volley 日志的快照。几乎一半的渲染时间是由于 network-queue-take。另一个甚至更高,大部分时间都在网络队列中。如何对其进行优化以使网络队列接收速度更快?什么决定了(除了线程优先级,图像请求默认是低优先级请求)网络队列的速度?

注意:我在 Samsung Galaxy S4 上运行了这个。

08-07 11:01:09.560: D/Volley(938): [1] MarkerLog.finish: (3662 ms) [ ]    http://farm6.static.flickr.com/5487/9452149004_c4ba6d2d97_t.jpg 0x8da7e4ac LOW 84
08-07 11:01:09.560: D/Volley(938): [1] MarkerLog.finish: (+0 ) [ 1] add-to-queue
08-07 11:01:09.565: D/Volley(938): [1] MarkerLog.finish: (+0 ) [12239] cache-queue-take
08-07 11:01:09.565: D/Volley(938): [1] MarkerLog.finish: (+0 ) [12239] cache-miss
08-07 11:01:09.570: D/Volley(938): [1] MarkerLog.finish: (+1694) [12243] network-queue-take
08-07 11:01:09.570: D/Volley(938): [1] MarkerLog.finish: (+1852) [12243] network-http-complete
08-07 11:01:09.570: D/Volley(938): [1] MarkerLog.finish: (+50 ) [12243] network-parse-complete
08-07 11:01:09.575: D/Volley(938): [1] MarkerLog.finish: (+21 ) [12243] network-cache-written
08-07 11:01:09.575: D/Volley(938): [1] MarkerLog.finish: (+0 ) [12243] post-response
08-07 11:01:09.580: D/Volley(938): [1] MarkerLog.finish: (+45 ) [ 1] done

这是另一个需要更长的时间:

08-07 11:01:09.845: D/Volley(938): [1] MarkerLog.finish: (3871 ms) [ ] http://farm3.static.flickr.com/2827/9451437485_921584cdea_t.jpg 0x24a8bf69 LOW 85
08-07 11:01:09.860: D/Volley(938): [1] MarkerLog.finish: (+0 ) [ 1] add-to-queue
08-07 11:01:09.865: D/Volley(938): [1] MarkerLog.finish: (+1 ) [12239] cache-queue-take
08-07 11:01:09.870: D/Volley(938): [1] MarkerLog.finish: (+0 ) [12239] cache-miss
08-07 11:01:09.870: D/Volley(938): [1] MarkerLog.finish: (+2543) [12242] network-queue-take
08-07 11:01:09.875: D/Volley(938): [1] MarkerLog.finish: (+1280) [12242] network-http-complete
08-07 11:01:09.880: D/Volley(938): [1] MarkerLog.finish: (+26 ) [12242] network-parse-complete
08-07 11:01:09.885: D/Volley(938): [1] MarkerLog.finish: (+14 ) [12242] network-cache-written
08-07 11:01:09.885: D/Volley(938): [1] MarkerLog.finish: (+0 ) [12242] post-response
08-07 11:01:09.890: D/Volley(938): [1] MarkerLog.finish: (+7 ) [ 1] done
08-07 11:01:09.905: D/dalvikvm(938): GC_CONCURRENT freed 973K, 11% free 14796K/16583K, paused 12ms+6ms, total 56ms

最佳答案

network-queue-take 需要时间,因为您有大量请求正在运行。如果您(默认情况下)有 4 个线程在运行,并且有 8 个请求,假设所有第一个请求正好需要 500 毫秒,那么剩余请求的网络队列需要 500 毫秒,因为它等待 500 毫秒才能在队列中找到一个位置。

您可以通过创建一个高于默认 DEFAULT_NETWORK_THREAD_POOL_SIZE 的 RequestQueue 来“消除”它,但请记住默认是有原因的。例如,如果您同时下载 20 张图片,您可能会遇到 OOM 情况。但是,如果您有大量低内存和不良延迟请求,增加它应该有助于您的性能,而不会冒 oom 条件的风险。

关于android - 如何在 android Volley 中优化 network-queue-take? ( Volley 谷歌 IO 2013),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18110581/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com