如何优化android Volley中的networking队列? (Volley Google IO 2013)

以下是图像请求的Volley日志的快照。 渲染时间的几乎一半是由于networking队列。 另一个是更高的,大部分时间在networking队列。 如何优化networking队列速度? 什么决定(除了线程优先级,映像请求是默认的低优先级请求),networking队列的速度?

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

08-07 11:01:09.560: D/Volley(938): [1] MarkerLog.finish: (3662 ms) [ ] http://img.androidcookie.com/android/photo_unavailable.png 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://img.androidcookie.com/android/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 

Solutions Collecting From Web of "如何优化android Volley中的networking队列? (Volley Google IO 2013)"

networking队列需要花费时间,因为你有大量的请求运行。 如果你有(默认情况下)4个线程运行,8个请求,说所有的第一个请求需要500毫秒,那么其余请求的networking队列将是500毫秒,因为它等待500毫秒,以获得一个点在队列中。

你可以通过创build一个比DEFAULT_NETWORK_THREAD_POOL_SIZE更高的RequestQueue来“消除”它,但是请记住默认值是有原因的。 例如,如果您同时下载20个图像,则可能会遇到OOM条件。 但是,如果你有大量的低内存和延迟请求,增加它应该可以帮助你的性能,而不会冒险的条件。