开发者

Mobile : one single request or multiple smaller requests?

On an iPhone app (or mobile in general) that constantly needs to send requests to a Web Service, is it better to work with one single requests that will fetch a large amount of data or multiple (possibly simultaneous) requests for each element with smaller amount of data fetched.

Example

I want to load a list of elements in a node. I have the node's ID. The 2 ways I can fetch the elements are the following :

  • send a single request with the node ID and get all the information about the n first elements in the node in a single response ;
  • send a first request with the node ID to get the IDs of the n first elements in the node, then for each one send another request to have one response per element.

I'm balanced between about that.

  • the heavyweight single response may cause more lag and timeouts because of the very unstable and slow mobile internet connection ;
  • the phone may have trouble handling too many responses at the same 开发者_StackOverflowtime.

What's your opinion ?


Since there is overhead for every request, one large request is generally faster than several small ones of the same size. This applies to high speed networks too, but in mobile networks the ratio between transfer speed and latency is even bigger.


I don't think the phone will have any problem handling the responses, so the multiple requests approach seems better for large requests/answers. However, depending on the size of your requests/responses, it may actually be faster to do it in a single request, in order to reduce the delay associated with multiple requests. The single request approach will also need to transfer slightly less data than the multiple request one.


Every call will have its overhead (i.e. network load), the number of connections might also be limited.

You might or might not be able to update your user interface during download, depending on how often your callbacks are called - you may be able to process partial data as it arrives.

If your data is easy to compress (typically text data), then using a single call might even reduce your total network usage footprint even more.

If the chunks of data are large, I'd go with several individual ones. This will also make things easier in case of network errors. Bottom line for me is to just get the right balance - make the packets reasonable sized and don't flood the server.


This is depend upon the situation. If you don't want to bother your user to waiting everytime throughout the app then you can use single request to load all the data at a time.

If you don't mind to let user wait then you can use multiple request on demand. For example if you just want to show title in tableview and detail when user tap on any title. So you can first get the title only and then when user tap you can get details for that title by ID. so that would be pretty good way to request on demand only.


Sometimes the situation merits use for only single requests for say a certain category. Say you have a twitter app and the tweets are seperated out into categories. Someone who has the app but only cares about sports may only look at the sports section which could be a single ajax call. Another user may only be intersted in two categories out of 15 categories. This means the user doesn't have to load unneccessary data. The important thing you need to determine is this.

Does all of the data need to be loaded all at once for the app to work correctly and are your users generally going to want all that data in the first place.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜