Wednesday, 25 March 2015

How to Effectively Test mobile applications To Optimize Energy Consumption

Why energy is the key factor for mobility

Smartphones and tablets allow people to carry around more computational power in their hands than most had on their desktops just a few years ago. However, the usability of these devices is strongly defined by the energy consumption of mobile applications, and user reviews of applications reveal many customer complaints related to energy usage

A modern mobile application brings increasingly complex functionality into mobile devices that are rapidly overtaking personal computer as a primary computing. Because of the battery/energy constraints of mobile devices, energy efficiency fitting an energy budget and maximizing the utility of applications under given battery constraints has become an important software design and maintenance consideration. Traditionally concerned with performance and memory usage optimization, perfective maintenance now has to address the challenges of optimizing energy consumption, with existing perfective maintenance techniques being mostly inapplicable

Key factors contribute mobile handset energy consumption

The main factor of mobile application energy consumption is the mobile network itself. Not like ordinary desktop applications, Mobile handsets use wireless state machine to manage network calls. Behaviour of the wireless state machine is totally depending on the network profile. For example the way that 3G network data calls utilize energy is not the way that 4G/LTE data calls utilize energy.

How 3G wireless state machine consumes energy

In 3G wireless state machine, it has three states.  They are IDEL State, CELL-DCH state (High Power Mode) and CELL FACH (Low Power Mode). CELL-DCH state requires 800mW and CELL FACH require 460mW per second.


When mobile application wants to initiate 3G data call, first it has to open a 3G network connection. According to 3G profile, opening connection is taking 2 seconds [1]. When opening a 3G connection our handset moves from IDEL state to CELL-DECH state [2]. Then connection will be established and request will be send to backend and handset is waiting for the response [A]. Mobile device remains in DCH for 5 seconds for the response. Sometimes response [B] takes more than 5 second and this idle time of 5 seconds is called the DCH tail. If no more data arrives, the wireless state machine switches to a CELL_FACH state [3]. The FACH state can handle signaling packets, but if more data comes in [C], the radio switches back to the DCH state. If no packets arrive after 12 seconds in the FACH state, the radio returns to the IDLE state and turns off.
With using above factors we can calculate actual energy requirement for each mobile transaction by adding actual time spent for DCH, FACH, IDELà DCH and FACHàDCH. Following is a sample of such calculation.
3G Energy Consumption

RCC State
Energy Consumption (in Joules)
DCH Active
xxxx
FACH Active
xxxx
IDELà DCH
xxxx
FACHà DCH
xxxx
Total Energy
xxxx
  

How LTE wireless state machine consumes energy

LTE wireless state machine has only two states. They are RCC CONNECTED state and RCC IDEL state.  RCC CONNECTED state is the high power mode and it require 1000 to 3500mW and RCC IDEL requires less than 15mW. There are two sub sates in LTE state machine with in RCC CONNECTED state. They are called Short DRX and Long DRX Both of these modes has a parent mode call Continuous Transmission state.

The RCC CONNECTED state that the wireless state machine uses when it is actively transferring data. This high power and high bandwidth state is what gives LTE its speed.


While in RCC CONNECTED state the wireless state machine creates the connection [1}. Then it initiates the request and waits for its response [A].  When data transmission is completed, the radio moves to the Short DRX state, but is still using high power while it waits for more data. If more data arrives, the wireless state machine returns to the Continuous Transmission state, and if not, it moves to the Long DRX state. While in the Long DRX state, the wireless state machine prepares to switch to the IDLE state, but is still using high power and waiting for data. If more data arrives, the wireless state machine returns to the Continuous Transmission state, otherwise it goes to low power IDLE state and turns off.
Using above facts we can calculate LTE energy consumption and following is the sample of LTE energy consumption calculation.

LTE energy consumption

RCC State
Energy Consumption (in Joules)
IDELà Continues reception
xxxx
Continues reception
xxxx
Continues reception Trail
xxxx
Short DRX
xxxx
Long DRX
xxxx
IDEL
xxxx
Total Energy

xxxx

Deferent between 3G and LTE State machines energy consumption

In the 3G state machine, the power drain in the DCH state is basically constant for all files. In LTE, the power drain in the Continuous Reception state varies depending on the throughput. Small files keep the power low, but as the throughput increases, the power gets even higher. Therefor LTE state machine drain slightly more power than 3G, because the tail states (Short DRX and Long DRX) stay at the higher base power, while much of the 3G tail is in the FACH state which uses half power.
Modem end uses expectation of a mobile application response id less than 3 second. This will make usage of LTE more. But LTE requires more energy than 3G. This requires QA professions to effectively test there AUT on 3G and LTE and calculate energy consumption effectively and find ways of optimizing.

 Best Practice Recommendation

Test for insufficiency due to scattered data transfers

In many mobile applications, files/data are requested with large gaps. Because of this actual data transfer through state machine will be through scatted way. Please note following diagram.


QA should be able determine the gap between scatted data transfer so development teams can make sure scatted data are tightly grouped. This will enable less time consumption in 3G or LTE sate machine.

Test for insufficiencies from delaying closing connections

In case open connections are not closed properly and effectively, 3G and LTE state machines are assuming some more data are on the way and they are in receiving modes.
Please refer to above diagram. Actual data burst was completed in 315th second and developer actually closing the connection in 320th second. Because of this, state machines waits unnecessarily in receiving mode for 5 secounds and it will utilize energy depending on the type of the connection (3G or LTE). Assume that end user travels to this page/screen for 3 times during his usage actual energy waste is three times as your calculation.

Test for content insufficiencies

Mobile screens are comes with different sizes and resolutions. Images use for each screen size and resolutions are needs to optimize. Otherwise this will cause unnecessary data transfer and require more energy.


Image on the left side of above takes 43 seconds to download. Next image looks identical but takes 3.5 second to download. This significant gain achieved simply by reducing the image resolution.  3G or LTE sate machines do not require additional time to download the second image and this will result low energy consumption.

Test For periodic transfers

Periodic transfers are specific packets that are sent repeatedly by a server over an infinite time horizon. They typically occur at regular intervals.



Periodic transfers ([P1] [P2] …. [P6]) trying keep the connection for long time but actually state machine after its time out disable the connection and again create a new connection ([1] [2] [3] and [4]). This will require additional 2secound time to create the connection and it use 2 into 800mW of energy. Therefore Periodic transfers needs to be optimized to minimize no of connections and QA needs to monitor them effectively to determine following

  1. Best timing for Periodic transfer so that application uses as long a period as possible between transfers.
  2. Feasibility of combine Periodic transfer with other data.
  3. Feasibility of bundle as much data as possible into a single message.

Test for duplicate content

If mobile applications calling for same content form the back-end over and over then it should be cached. By doing this we can stop unnecessary data download and save energy.

Test for uncompressed file transfer

If mobile applications use file transfers then it has to be compressed. By doing this we can stop unnecessary bandwidth usage and save energy.