Mobile : one single request or multiple smaller requests?
Asked Answered
N

5

7

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 time.

What's your opinion ?

Neolatin answered 1/7, 2011 at 13:58 Comment(0)
E
6

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.

Evacuation answered 1/7, 2011 at 14:38 Comment(2)
But hasn't a big request/response a tendency to cause more network errors ?Neolatin
I'm not sure about that. But of course, if you're downloading huge amounts of data, you'll need a way to resume an interrupted download. But better try a big download first and make a new request if it fails (and then request only the data you didn't get in the first request). Remember that bandwidth is quite good on mobile networks, but latency is terrible.Evacuation
S
1

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.

Sacring answered 1/7, 2011 at 14:14 Comment(0)
S
1

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.

Shaunteshave answered 1/7, 2011 at 14:27 Comment(0)
H
0

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.

Hawes answered 1/7, 2011 at 14:17 Comment(4)
I'm really concerned by performance here. Let's say the data I need to fetch is for a single TableView but I can whether fetch the data for all the cells at once, or fetch the data for every cell separately.Neolatin
So for this If you have more than 50 records then you should load 20 per request and make Load more button in the UITableview footer. If you are looking for performance then you should load all the data once. So you need to worry about throughout app and is it needed to load data all the time ? May be you can load it at first time and give option to user to load manually or option to load every seven days, Monthly or Manually. I did for one of my app because they 10000s records. Just a thought.Hawes
I can't possibly load all data on launch, my app needs to be talking to the web service all the time. I'm already loading lists of elements by chunks of 20, but the response is still quite big (the UITableView cells need a lot of data to display)Neolatin
Hmmmm Then you should continue current procedure and load data in chunks. That would be better.Hawes
S
0

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.

Safeguard answered 1/7, 2011 at 15:3 Comment(1)
I'm talking about data that will eventually be displayed, yes. According to my example, the user selected the node and wants to display the elements that are in there, but even 20 elements are quite big.Neolatin

© 2022 - 2024 — McMap. All rights reserved.