Question

An Android app (Java) needs to update the same database record periodically. It can be done every second or every minute. Regarding only battery life, Does it make any significant difference (like shortening the battery life to half) doing it every second v/s every minute?

As only CPU and memory are involved, I think it makes no difference, but I'm not sure. CPU and memory are still used by the running app & other system process, anyway.

Updating every second makes a simple app; caching and updating every minute (or waiting for certain condition) make code a little more complicated and error prone.

Was it helpful?

Solution 2

I agree with CommonsWare's answer - if you don't need to be doing something every second and can do it less frequently, then the best practice is to reduce the frequency as much as possible, as doing it more frequently will consume more energy.

However, to address the "significant" part of your question, especially in relation to other device operations, consider this following quote based on tests on the HTC Dream (G1) and Nexus One devices, from:

  • Aaron Carroll and Gernot Heiser, "An analysis of power consumption in a smartphone," presented at the Proceedings of the 2010 USENIX conference on USENIX annual technical conference, Boston, MA, 2010. http://www.nicta.com.au/pub?doc=3587

"The RAM, audio and flash subsystems consistently showed the lowest power consumption. While our micro-benchmarks showed that the peak power of the SD card could be substantial ( 50 mW), in practice the utilisation is low enough such that on average, negligible power is consumed. Even video playback, one of the more data-intensive uses of mobile devices, showed SD power well under 1 % of total power. RAM has similar characteristics; micro-benchmarks showed that RAM power can exceed CPU power in certain workloads, but in practical situations, CPU power overshadows RAM by a factor of two or more. Audio displayed a largely static power consumption in the range of 28–34 mW. Overall, RAM, audio and SD have little effect on the power consumption of the device, and therefore offer little potential for energy optimisation."

Keeping the CPU busy when it otherwise wouldn't be is likely the largest energy impact of continuously writing to the database every second, vs. writing every minute. Relatively, assuming normal usage, flash memory use in isolation consumes relatively little energy.

If you're interested in additional references and discussion, see: https://stackoverflow.com/a/13004377/937715

OTHER TIPS

Does it make any significant difference doing it every second v/s every minute?

Doing something every second consumes approximately 60x the power of doing something every minute.

As only CPU and memory are involved, I think it makes no difference, but I'm not sure.

Most people store their database on flash memory. Writing to flash memory consumes power.

CPU and memory are still used by the running app & other system process, anyway.

Performing work every second, rather than every minute, is more likely to keep CPU cores running when they otherwise would not be.

As only CPU and memory are involved, I think it makes no difference, but I'm not sure. CPU and memory are still used by the running app & other system process, anyway -->

Each time you try to update, one or more instructions are executed by the processor. and each instruction consumes power. So, yes updating every second consumes more power.

As everyone else has said, it’s best to minimize the use of the processor. The underlying reason is something called idle or C-states. In these idle states, parts of the processor are literally shut down.

The processor will drop down into one of these power saving C-states almost immediately after idle and into one of the deeper states after a few seconds. I don’t recall exactly how long the interval is but it’s definitely not more than a few seconds.

Also, if the processor has to wake up to do some computation, it doesn’t have to repeat the descent a second time; it’ll drop immediately into the lower state unless there is a significant need for it to raise its idle state. You can read more about it here “Power Management States: P-States, C-States and T-States”.

I know that you don’t have much choice in your update frequency, but the ideal is probably closer to 7 sec. Too much less and the processor won’t fall into the deeper and more energy conserving c-states. Longer than this, the processor is being woken up by a lot of other interrupts from other devices and processes, so one more wake up won’t make much difference.

Small chunk I/O operations consume power, mainly by keeping the processor busy and awake. Depending upon your compiler, runtime and VM, larger transfers may be via DMA which don’t directly involve the CPU. This will potentially help on energy efficiency.

PS Sean, thanks for the references.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top