1

my app needs to download some data (about 50k) on launch time. I'm currently evaluating download speeds under 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

2
  • Is it possible the downloaded file is cached somewhere? Jul 29, 2011 at 9:51
  • Could be cached on a transparent ISP run HTTP proxy or some such too.
    – ewanm89
    Jul 29, 2011 at 11:03

3 Answers 3

1

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.

0

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

1
  • I just tried this: I copied the file 9 times, renamed it, and then downloaded the files. It appears that the first download again takes long (8seconds), the following ones are quicker (1.5 seconds). Would that also be the case with caching? I guess not, right?
    – brainray
    Jul 29, 2011 at 13:41
0

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.

1
  • Thanks you, I'll definitely will.
    – brainray
    Jul 29, 2011 at 15:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.