开发者

Download speed connection varies - first time takes much longer - why?

my app needs to download some data (about 50k) on launch time. I'm currently evaluating download speeds und开发者_如何学Pythoner several circumstances, especially slow connection speeds.

I have some simple test code shown below. A button starts the download of the file and starts the measurement, the end of the measurement is when the download has finished (all this is running in the main thread btw).

The first time I push the button, the time to download is much longer than if I press the button subsequentially (like after 2s). If I wait 10 sec and push again, the time will be longer again.

Why is this? Does is cost that much time to make the initial connection? I know the code below is quite primitive. What would be the best way to get a connection quicker.

EDIT: I have a assumption that this definitely has to do with the way the ISP/phone company handles the Internet connection. Might it be, that the Internet connection of my ISP is kind of stripped down to a certain minimum when I'm not actively using the network? And then, when I download something, more 'channels' are added for better speed? I checked several SIM cards: the more expensive the data rate is, the more consistent is the behavior. Say, if I use a brand A SIM, if have the behavior described above, if I use brand B (premium), everything is fine.

Many thanks in advance


NSURL *url = [NSURL URLWithString:@"http://myServer/testFeed1.zip"];
NSData *urlData = [NSData dataWithContentsOfURL:url];

… save the file


Thanks for your input, but this behavior definitely came from the speed throttling of the ISP (mobile connection of course). It is definitely interesting to see how large the difference between deferent SIM-cards can be, even if the connection "looks" good (3G sign and good reception). I did use the uncached method, but it didn't change.


Maybe cached.. you could use this link to verify that: myServer/testFeed1.zip?< random-number >


I'm not sure, but I think dataWithContentsOfURL: implements some kind of caching. So, the longer time you measured would be the actual download time. You could find out if you tried the following:

NSError* error = nil;
NSData* data = [NSData dataWithContentsOfURL:yourURL options:NSDataReadingUncached error:&error];

If caching is the cause, the download should now always take longer. (I found that code snippet here.)

Update: If download time is an issue, you should consider doing an asynchronous download using NSURLConnection instead. It will greatly improve user experience. Also, you could measure the connection and download times separately. Here's a simple example on how to do that.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜