1

I'm trying to optimize battery usage when networking. If I hold all my http requests in an array for example, then I send them all (just empty out the array at once (for loop)), will the antenna turn on once to perform the 10 requests, or will it turn on and off n times? (I'm using NSURLRequest)

Is there a way to batch send requests at once? Or is this basically "batch" sending requests.

William Falcon
  • 9,813
  • 14
  • 67
  • 110
  • You might want to check AFNetworking and look at [this thread](http://stackoverflow.com/questions/19414486/how-to-batch-request-with-afnetworking-2). – rdurand Aug 01 '14 at 12:35
  • I'm aware of AFNetworking (and use it for other projects), but we don't need anything that heavy so we rolled out our own lightweight version. – William Falcon Aug 01 '14 at 12:41
  • I'm sure it's not specified, and is (somewhat) subject to change. Of course, you can always batch stuff together into a single HTTP request (if the server can handle it), rather than sending multiple requests, and batching into a single request would be a hair more battery-efficient in any case. – Hot Licks Aug 01 '14 at 15:40

2 Answers2

1

The documentation says nothing about how iDevice's hardware handles multiple NSURLRequests. It can be that handling on one model or OS version is different than on another one (e.g. iPhone 4 vs iPhone 5).

You will have to use Instruments and research it on your own using Energy Diagnostics. However, this is rather simple. Here is a short plan how to do it:

  1. Connect the device to your development system.
  2. Launch Xcode or Instruments.
  3. On the device, choose Settings > Developer and turn on power logging.
  4. Disconnect the device and perform the desired tests.
  5. Reconnect the device.
  6. In Instruments, open the Energy Diagnostics template.
  7. Choose File > Import Energy Diagnostics from Device.

Moreover, have a look at Analyzing CPU Usage in Your App

Rafał Sroka
  • 39,540
  • 23
  • 113
  • 143
0

The energy optimisation performed by the OS is not publicly known.

The exact handling for a particular interface depends on the interface, so some interfaces have very low set up/tear down costs ( e.g. Bluetooth LE), and others are quite cheap to run, but take time to set up and tear down ( e.g. 2G).

You generally have to take a course that gives the OS the best options possible, and then let it do what it can.

We can say a few things. It is unlikely that the connection is being powered up/down for individual packets, so the connection will be powered up when there is data to send, and kept up as long as you're trying to receive. The OS may be able to run at a lower power when it is just waiting, as it doesn't need to ACK packets, but it won't be able to power off completely.

Bottom line, if you send your requests sequentially, I believe that the OS is unlikely to cycle power in between requests, if you send them in parallel, it almost certainly won't.

Is this a worthwhile optimisation? Depends how much of it you're doing.

Possibly of interest: background downloads whereby the OS times your fetch when it knows it is going to do some other network activity anyway.

Gordon Dove
  • 2,537
  • 1
  • 22
  • 23