Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ideal Chunk Size for Writing Streamed Content to Disk on iPhone

I am writing an app that caches streaming content from the web on the iPhone. Right now, I'm saving data to disk as it arrives (in chunk sizes ranging from 1KB to about 60KB), but application response is somewhat sluggish (better than I was expecting, but still pretty bad).

My question is: does anyone have a rule of thumb for how frequent and large writes to the device memory should be to maximize performance?

I realize this seems application-specific, and I intend to do performance tuning for my scenario, but this applies generally to any app on the iPhone downloading a lot of data because there is probably a sweet spot (given sufficient incoming data availability) for write frequency/size.

These are the resources I've already read related to the issue, but no one addresses the specific issue of how much data to accumulate before dumping:

Best way to download large files from web to iPhone for writing to disk
The Joy in Discovering You are an Idiot

like image 350
warrenm Avatar asked Mar 07 '10 23:03

warrenm


1 Answers

One year later, I finally got around to writing a test harness to test chunking performance of streaming downloads.

Here's the set-up: Use an iPhone 4 to download a large file over a Wi-Fi connection* with an asynchronous NSURLConnection. Periodically flush downloaded data to disk (atomically), whenever the amount of data downloaded exceeds a threshold.

And the results: It doesn't make a difference. The performance difference between using 32kB and 512kB chunks (and several sizes in-between) is smaller than the variance between runs using the same chunking size. The file download time, as expected, is comprised almost entirely of time spent waiting on the network.

*Average throughput was approximately 8Mbps.

like image 110
warrenm Avatar answered Oct 13 '22 08:10

warrenm