安卓:加快多个小文件下载 [英] Android : Speeding up multiple small file downloads

查看:263
本文介绍了安卓:加快多个小文件下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望就如何加快多个小文件在我的应用程序下载的一些建议。该应用程序下载300-400小(15KB)的文件。尽管总规模小的下载需要很长的时间,因为额外的握手时间为每个单独的文件。

我试图压缩文件时,下载并解​​压缩在设备上,但最终它比简单地下载他们都直接较慢(虽然这可能是由于低效的解压缩算法。)

任何人都可以就如何加快下载(可能要求在一个时间,而不是按顺序?下载3)一些建议,或者有code的高效解压缩片段他们不介意分享这将是AP preciated!


解决方案

  

即使总规模小的下载采取由于额外的握手时间为每个单独的文件很长的时间。


我不太肯定你是如何做出的决定。如果是通过Traceview,太棒了。如果没有,请考虑使用Traceview以确定究竟在何处减速的。

此外,我不太肯定你的握手时间的意思。如果你的意思是创建和拆除套接字连接,既 HttpURLConnection类的HttpClient 应该支持保持活动。前者拥有的Andr​​oid 2.1及更早版本一个bug;后者需要你重用你的的HttpClient 实例。

由于古普塔先生指出,并行运行几个请求是合理的举动。您可以使用的AsyncTask ,也许与你自己的线程池,这样你就可以管理并行的特点。

不过,再次使用Traceview来确定你真正的问题所在。

I am hoping for some advice on how to speed up the download of multiple small files in my app. The application downloads 300-400 small (15KB) files. Even though the total size is small the downloads take a long time because of the extra handshake time for each individual file..

I have tried to zip the file up, download it and unzip it on the device but in the end it was slower than simply downloading them all directly (though this could be due to an inefficient unzip algorithm..)

Can anyone give some advice on how to speed up the downloads (perhaps requesting to download 3 at a time rather than in sequence?) or have an efficient unzip snippet of code they don't mind sharing it would be appreciated!

解决方案

Even though the total size is small the downloads take a long time because of the extra handshake time for each individual file.

I am not quite certain how you made that determination. If it was via Traceview, great. If not, please consider using Traceview to determine exactly where slowdowns are.

Also, I am not quite certain what you mean by "handshake time". If you mean creating and tearing down socket connections, both HttpUrlConnection and HttpClient should support keep-alive. The former has a bug in Android 2.1 and earlier; the latter requires you to reuse your HttpClient instance.

As Mr. Gupta suggests, running a few requests in parallel is a reasonable move. You can use AsyncTask, perhaps with your own thread pool, so you can manage the parallel characteristics.

However, again, use Traceview to determine where your real problem lies.

这篇关于安卓:加快多个小文件下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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