Ideal Chunk Size for Writing Streamed Content to Disk on iPhone

纵然是瞬间 提交于 2019-12-23 10:11:54

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/2398406/ideal-chunk-size-for-writing-streamed-content-to-disk-on-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!