Software efficiency : know your enemy — case study on mobile data

Software ecodesign and efficiency is good sense. But a good sense if you know what to optimize and how your framework is running. We go also go on how the hardware is stimulate by the software.

For example, send data over the air is simple. With your favourite framework, you can send a file, a stream, a image… in one line. But what happen in the metal of your smartphone ?

Supposing your 3G radio cell is sleeping, the cell will be wake to be in a state of higher activity and higher energy consumption (The ramp phase). After, data will be send (the transfer phase). Once the transfer done, the cell will not go in the initial step (the sleep) but will stay in an intermediate state : the tail. This state have an energy consumption which is lower than the transfer step but higher than the sleep state. This state permit to have a better latency. Indeed, if a transfer happen after the first transfer, the cell will be ready to send the data (no ramp step to process).

Energy chart of 3g (From Energy Consumption in Mobile Phones: A Measurement
Study and Implications for Network Applications)

The tail step depend of the network provider but is between 1s and 10s. This step impact more the battery than the transfer step. Indeed, if transfers are intermittent and frequents, cell be more in the tail step than in the transfer step. According to the study Energy Consumption in Mobile Phones: A Measurement
Study and Implications for Network Applications
, the average tail
energy is 80% of the total energy consumption in HTC phones.

Bluetooth Energy Consumption (Measuring Bluetooth® Low Energy Power Consumption from TI)

You can see on the following graph, it is the same thing for the bluetooth… and for a lot of radio protocol. And also for GPS.

What it give on a real application ? The university of Perdue have study some apps. And tail have a big impact.

Fine Grained Energy Accounting on Smartphones with Eprof

For Angry Birds, 50% of the energy is from Net and GPS Tail. Moreover, Net and GPS is for ads and tracking…

What to do in your app and website to decrease this impact ? Leave your radio cells in sleep mode ! So it mean that it is better to regroup data writing. If you send data every 10s, the cell will be every time in tail state. It is more difficult because it’s easier to send data when it is generate (when you algorithm create the data).

Asynchronous mechanisms, batch sending, buffering… A lot of mechanisms can be apply. Prefetching for example is a good practices to regroup data downloading of big file (video …). The other advantage will be that radio cell will be ready to send the data and processing of sending will be faster.

Google explains :

Prefetching data is an effective way to reduce the number of independent data transfer sessions. Prefetching allows you to download all the data you are likely to need for a given time period in a single burst, over a single connection, at full capacity.

For example, with Volley on Android you can use the requestQueue (Source Android) :

RequestQueue mRequestQueue;

// Instantiate the cache
Cache cache = new DiskBasedCache(getCacheDir(), 1024 * 1024); // 1MB cap

// Set up the network to use HttpURLConnection as the HTTP client.
Network network = new BasicNetwork(new HurlStack());

// Instantiate the RequestQueue with the cache and network.
mRequestQueue = new RequestQueue(cache, network);

// Start the queue
mRequestQueue.start();

String url =”http://www.example.com";

// Formulate the request and handle the response.
StringRequest stringRequest = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() { @Override public void onResponse(String response) { // Do something with the response }
}, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { // Handle error }
});

// Add the request to the RequestQueue.
mRequestQueue.add(stringRequest);

In summary, if we understand the hardware mechanisms, it is easy to integrate software mechanism to reduce the energy consumption. Know your enemy. For mobile data transfer, it is the energy waste during the tail state. Make it your friend by gathering a maximum of data transfer.

References

Application Note AN092 — Measuring Bluetooth® Low Energy Power Consumption — By Sandeep Kamath & Joakim Lindh TI

Energy Consumption in Mobile Phones: A Measurement
Study and Implications for Network Applications
— Aruna Balasubramanian — University of Massachusetts Amherst

Fine Grained Energy Accounting on Smartphones with Eprof — Purdue University

Optimizing Downloads for Efficient Network Access — Android Developers

Greenspector Best pratices

--

--

Olivier Philippot
Eco-design of software by Greenspector

CTO of @green_spector efficiency and eco-design of software #greenit #ecodesign