Friday, August 26, 2011

Mobile Woes: Working on a large-scale Android application

Engineering the ICM Mobile Agent this summer, I encountered a number of challenges which were both exciting and nerve-wrecking at the same time. Working on a mobile platform and application places one in a unique situation because one does not have access to unlimited resources and power, and various code libraries. As a result, one needs to be mindful of various run-time quirks that can significantly reduce the efficiency and usability of the app. In this post I am going to retrace my path through the course of the summer and highlight three significant hiccups that I faced.

1. Cost of cryptography
Most networked applications make use of cryptography in one form or the other. Important among these are encryption and authentication. For both, one has the option of using either public or private key cryptography. Though the end-goal might be the same, the algorithmic differences between the two can have major performance differences. For example, in one instance RSA public encryption/decryption of a 20 byte String took 5987/4471 ms, respectively. In contrast, AES secret key encryption/decryption took 22/13 ms, respectively. Clearly, the latter is many orders of magnitude faster than the former. In an application which encrypts every communication message, the choice of the encryption algorithm can make a major performance difference.

2. Task repetition
As an integral work horse of the ICM, the mobile agent runs connectivity tests for every monitored website and service. The periodicity of these tests can take its toll on the battery time. Naively running these tests one after the other will drain the battery in no time. Therefore, it is important to be aware of some of functional aspects of your application and how to optimize them. Selecting a good periodicity interval using manual profiling can help to conserve the battery.

3. Communication frequency
The frequency with which your application communicates with other entities in the network can also affect battery consumption. Therefore, a communication model in which the mobile client initiates communication by consuming a RESTful webservice API in a request/response model is the most efficient for two major reasons: 1) It puts the client in charge of the communication by allowing it to start communication if and when required without any polling cost, 2) It pushes the computational cost of some intensive tasks from the client to the server.

No comments:

Post a Comment