I’m trying to decide what would be the most efficient way to communicate between client device (mobile) and server.
Currently I have a generic web service that uses reflection to pass requests in specific directions. I have found area where I can re-use code, but it would result in sending more parameters in the request.
Would it be more efficient to:
a) Send the parameters and re-use code .
or
b) Send the minimum number of parameters to the server and create separate methods for each different request.
This is my first time creating a mobile application and thought it would be nice to know the most efficient means of comms, under these circumstances.
Any reply is greatly appreciated.
The exact answer depends mostly on bandwidth and latency. Though the two are related they are not identical.
Consider the extremes: if your link is capable of gigabyte-per-second bandwidth but every packet takes 40 minutes, you would obviously do best to minimize dialogs and send more data than you need to in every packet, just to reduce the number of round-trips it takes.
If you’ve got a 110 baud serial link but latency is 0.001 seconds, then sending as little data as possible and performing dialogs to ask for and receive only the information requested makes the most sense.
The decision is almost never this obvious: mostly we have reasonable bandwidth and reasonable-enough latency, so the decision is harder to make. In my experience, mobile applications feel like they have pretty poor latency (my phone just now returned ping times between 4000 and 200 milliseconds to three different sites; 300 ms was average) which is one reason why “mobile webpages” that break a page into more than one page are so horrible to read — you can spend more time waiting for content to arrive than actually reading on some sites.
But once the transfers get going, they feel quick enough — downloading megabytes for images doesn’t seem so bad, at least not for something I hold in my hand and runs on batteries for nearly a week without re-charging.
Without knowing the exact numbers you’re talking about, I’d recommend erring towards fewer packets sending more data — avoid round-trip pauses wherever you can. If all else fails, measure — find the average latency, calculate the packet sizes you’re thinking about, and do the math on how long it would take to carry out the “conversations” with the different parameters.