iPhone应用程序使用网络服务如何避免性能损失?
我有一个 iPhone 应用程序,可以从不同来源获取 XML 格式的信息。例如,我有一个 UITableView 显示信息,在解析后以 xml 格式,从像这样的 url http://mysite.com/posts.php?top=100 ->返回这样的帖子信息
<postsList><post><title>test1</title><pubDate>..</pubdate></item><post><title>test1</title><pubDate>..</pubdate></item></postsList>
,因此我只有一个请求,即显示包含帖子的表格。当我单击一个单元格时,我必须对三个不同的源进行三次调用,以收集我想要在单元格的详细信息中显示的数据。
我正在考虑编写一些 ASP.NET C# Web 服务,当调用时,它会收集我需要的所有信息,并在显示初始 UITableView 时返回一个响应(因此我发出一个请求)。
xml 响应的最大长度为 10-15kb,包含所有数据。根据我的经验,从性能角度来看,iPhone 上的网络访问(无线或 3G)非常昂贵,如果可能的话,如果没有必要,我希望避免使用它。
所以问题是:从单个请求中获取尽可能多的数据是一个好主意,还是仅在需要数据时(在本例中是显示单元格时)才发出请求更好?
I have an iPhone app that grabs information from different sources in XML format. For example i have a UITableView displaying information, in xml format after being parsed, from an url like this one http://mysite.com/posts.php?top=100 -> returns posts information like this
<postsList><post><title>test1</title><pubDate>..</pubdate></item><post><title>test1</title><pubDate>..</pubdate></item></postsList>
so i have one request only for showing the table with posts. when i click on a cell i have to make three calls to three different sources to gather the data i want to show in the details of the cell.
I was thinking to write some ASP.NET C# webservices that, when called, gather all the info i need and return a single response(so i make one request) when i show the initial UITableView.
The xml response will have 10-15kb max with all the data included. From my experience network access(wireless or 3g) is expensive on the iphone from the performance point of view and if possible i would like to avoid it if it's not necessary.
So the question is: is it a good idea to get as much data as possible from a single request or is it better to make requests only when data is needed(in this case when a cell is displayed)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您的蜂窝连接速度较慢,那么延迟对您的伤害将比有限的带宽更大。这意味着由于延迟,建立连接将花费大量时间。
如果您谈论的是 10-15 kb,我会立即获取所有数据(当然,您应该异步执行)
假设您使用的是 GPRS 连接,速度为 384kbps(至少在我们国家)。延迟约为 500 毫秒,因此建立 HTTP 连接可能需要大约 1 秒(最佳情况)。传输速度约为40KB/s。
使用单次下载:
使用 10 个小下载:
这是这不是一个科学测试,但它只是告诉你应该如何处理这类决定。
If you're on a slow cellular connection, the latency will hurt you more than the limited bandwidth. This means that setting up a connection will take a lot of time because of the latency.
If you're talking about 10-15 kb, I would get all the data at once (of course, you should do that asynchronously)
Let's say you're on a GPRS connection, which is 384kbps (in our country at least). The latency is in the order of 500ms, so setting up a HTTP connection could take about 1 second (best case). Transfer speed is about 40KB/s.
Using a single download:
Using 10 small downloads:
This is not a scientific test, but it simply shows how you should tackle these kind of decisions.
我在当前的项目中经常处理这些问题。它更多地与 3G 性能和延迟有关,而不是实际的 iPhone 本身。即使数据量较大,一次下载所有数据也会更有效。
所以我同意菲利普的观点。
I have been dealing with these issues alot on my current project. It has more to do with the 3G performance and latency then the actual iphone itself. Even with larger amounts of data it would be more efficient to download it all in one hit.
So i would agree with Philippe.