1 Mobile Software Development Framework: Adaptive Mobile Applications 10/23/2012 Y. Richard Yang
2 Outline r Admin r Mobile cloud services m Push notification service m Track service m Storage service
3 Admin. r HW3 r Project ideas
Recap: Example Mobile Cloud Services r Push notification service r Location based service, e.g., m Track service (supporting location based services) r Storage services, e.g., m iCloud, Google Drive, Dropbox r Proxy service, e.g., m Kindle Split Browser m Recognition/synthesis services 4
Recap: Push Notification Service r A single persistent connection between Push Notification Service (PNS) and Mobile Device r Authorization m App register with PNS m Device app registers with PNS and forwards registration to PNS m App can send only to registrations r Scalability, fault tolerance, generality m Send only notification, does not hold data 5
Recap: Track Service TC JoinTrackCollections (TC tCs[], bool removeDuplicates) TC SortTracks (TC tC, SortAttribute attr) TC TakeTracks(TC tC, int count) TC GetSimilarTracks (TC tC, Track refTrack, float simThreshold) TC GetPassByTracks (TC tC, Area[] areas) TC GetCommonSegments(TC tC, float freqThreshold) Manipulation Creation TC MakeCollection(GroupCriteria criteria, bool removeDuplicates) 6
API Usage: Ride-Sharing Application // get user’s most popular track in the morning TC myTC = MakeCollection(“name = Maya”, [ ], true); TC myPopTC = SortTracks(myTC, FREQ); Track track = GetTracks(myPopTC, 0, 1); // find tracks of all fellow employees TC msTC = MakeCollection(“name.Employer = MS”, [ ], true); // pick tracks from the community most similar to user’s popular track TC similarTC = GetSimilarTracks(msTC, track, 0.8); Track[] similarTracks = GetTracks(similarTC, 0, 20); // Verify if each track is frequently traveled by its respective owner User[] result = FindOwnersOfFrequentTracks(similarTracks);
Outline r Admin and recap r Mobile Cloud Services m Push notification service m Location based service m Storage service 8
Storage/Sync Service r Store content in cloud to be accessible by multiple selected devices r Deployed services, e.g., m iCloud m Google Drive android-uihttps://developers.google.com/drive/integrate- android-ui m DropBox 9
Storage/Sync Service Example: iCloud r Backend m Hosted by Windows Azure and Amazon AWS m Uses HTTPS to send to servers r Client storage models m Key Value Store m UIDocument m Core data r More details: see iCloud sessions m =209 10
11 Problems Caused by Mobile Storage r Read miss m stalls progress (user has to wait for data) r Synchronization/consistency m user may see outdated data m user modification may generate conflicts
12 Approaches r Read miss m explicit user file selection m automatic hoarding/prediction, e.g., CODA, SEER r Synchronization/consistency m keep modification logs and develop merge tools, e.g., Bayou m efficient file comparisons and merging, e.g., rsync, LBFS
Amazon Silk Split-Browser r Dynamic split browsing m Intelligently partition work between local and Amazon cloud 13
Outline r Admin and recap r Adaptive mobile applications 14
15 Adaptive Mobile App: Bigger Picture device in-net proxy in-net service On-device app/sys adaptation Service partition Device-aware service delivery
Outline r Admin and recap r Adaptive mobile applications m Client adaptation 16
Example: iphone
18 CPU Power Consumption Model r The power consumption rate P of a CMOS processor satisfies where k is a constant, C the capacitance of the circuit, f the CPU frequency, and V the voltage r When the supply voltage V is lower, charging/discharging time is longer; thus frequency should be lower => P ~ O(V 3 )
19 CPU Power Model Discussion: what voltage to operate on? throughput
20 Dynamic Voltage Scaling r Basic idea: determining voltage according to program response time requirement r For normal applications, give reasonable response time r For multimedia applications, use the deadline to determine voltage
21 Architecture CPU monitoring scheduling speed scaling demand distribution scheduler speed adaptor profiler multimedia applications requirements time constraint
22 Demand Prediction Online profiling and estimation: count number of cycles used by each job b 1 b 2 C min =b 0 b r =C max 1 b r-1 cumulative probability CDF F(x) = P [X x]
23 Observations Demand distribution is stable or changes slowly
24 CPU Resource Allocation How many cycles to allocate to a multimedia job? Application should meet percent of deadlines each job meets deadline with probability allocate C cycles, such that F (C ) =P [X C ] b 1 b 2 b 0 brbr 1 b r-1 cumulative probability F(x)F(x) C
25 How Fast to Run the CPU? Assume the strategy is to run job i at a fix (also called uniform) speed S i Assume it needs C i cycles during a time duration of P i Fact: since power is a convex function of frequency, if a job needs C cycles in a period P, then the optimal frequency is C/P, namely the lowest constant frequency.
26 Why Not Uniform Speed? Intuitively, uniform speed achieves - minimum energy if use the allocated exactly However, jobs use cycles statistically - often complete before using up the allocated - potential to save more energy stochastic DVS
27 Stochastic DVS For each job 1.find speed S x for each allocated cycle x time is 1/S x and energy is (1 - F(x))S 3 x such that
28 Example Speed Schedule 100 MHz200 MHz400 MHz cycle: speed: Job x10 6 cycles speed (MHz) Job x10 6 cycles Observation: speed up the processor with increasing clock cycles
29 DVS speed A1 B1 A1 execution speed up within job context switch 1.Store speed for switched-out 2.New speed for switched-in switch back A2
30 Implementation Hardware: HP N5470 laptop –Athlon CPU (300, 500, 600, 700, 800, 1000MHz) round speed schedule to upper bound process control block standard Linux scheduler DVS modules PowerNow speed scaling Soft real-time scheduling system call Extension to Linux kernel lines of C code
31 Reduces power consumption However, limited due to few speed options Evaluation: Normalized Energy
32 Odyssey: An Example Client Architecture r Application indicates resource capabilities in its request to service r Operating system maintains/monitors available resources m no need to have each application re-implement the monitoring r An application registers a resource descriptor and an upcall event handler with the OS r OS notifies the application upon detecting resource changes r Application adjusts requests to the server
33 Client System Model
Outline r Admin and recap r Adaptive mobile applications m Client adaptation m Server adaptation 34
35 Server/Content Adaptation: Examples Objective: automating adaptation
36 Example: Adapting Audio Content r Send a lower resolution stream as the redundant information, e.g. nominal stream at 64 kbps and redundant stream at 13 kbps (such as GSM) 2 3
37 Example: Adapting Fidelity of Video/Image Content? r Potentially many dimensions m frame rate (for video) m image size m quality of image r Usage: e.g., data acceleration offered by many carriers
38 Frame Encoding: Block Transform Encoding DCT Zig-zag Quantize Run-length Code Huffman Code
39 Discrete Cosine Transform F[u,v] = 4C(u)C(v) n2n2 n-1 j=0 k=0 f(j,k) cos (2j+1)u 2n (2k+1)v 2n cos where C(w) = 1 2 1 for w=0 for w=1,2,…,n-1 DCT is better at reducing redundancy than Discrete Fourier Transform but it is more computationally expensive
40 Basis Functions of DCT - An image is a superposition of basis functions - DCT computes the contribution of each basis function - F[u,v]: for the basis function at position [u, v] more detail
41 Example: MPEG Block Encoding original image DCT DC component AC components Quantize zigzag run-length and Huffman encoding of the stream coded bitstream < 10 bits (0.55 bits/pixel) Discussion: how to generate different encoding rates?
42 Examples Uncompressed (262 KB) Compressed (22 KB, 12:1) Compressed (6 KB, 43:1)
Outline r Admin and recap r Adaptive mobile applications m Client adaptation m Server adaptation m Proxy and job partition 43
Example Benefit of Cloud (RTT -> Server) 44
Example: MAUI 45 Maui server Smartphone Application Client Proxy Profiler Solver Maui Runtime Server Proxy Profiler Solver Maui Runtime Application RPC Maui Controller
How Does a Programmer Use MAUI? r Goal: make it dead-simple to MAUI-ify apps m Build app as a standalone phone app m Add.NET attributes to indicate “remoteable” m Follow a simple set of rules
Maui server Smartphone Application Client Proxy Profiler Solver Maui Runtime Server Proxy Profiler Solver Maui Runtime Application RPC Maui Controller Intercepts Application Calls Synchronizes State Chooses local or remote Handles Errors Provides runtime information
Profiler Callgraph Execution Time State size Network Latency Network Bandwidth Device Profile CPU Cycles Network Power Cost Network Delay Computational Delay Computational Power Cost Computational Delay Annotated Callgraph
B 900 mJ 15ms C 5000 mJ 3000 ms 1000mJ mJ D mJ ms mJ A Computation energy and delay for execution Energy and delay for state transfer A sample callgraph
FindMatch 900 mJ InitializeFace Recognizer 5000 mJ 1000mJ mJ DetectAndExtract Faces mJ mJ User Interface Cheaper to do local
FindMatch 900 mJ InitializeFace Recognizer 5000 mJ 1000mJ mJ DetectAndExtract Faces mJ mJ User Interface Cheaper to do local
FindMatch InitializeFace Recognizer 1000mJ DetectAndExtract Faces User Interface 20900mJ Cheaper to offload
MAUI Implementation r Platform m Windows Mobile 6.5 m.NET Framework 3.5 m HTC Fuze Smartphone m Monsoon power monitor r Applications m Chess m Face Recognition m Arcade Game m Voice-based translator
Questions r How much can MAUI reduce energy consumption? r How much can MAUI improve performance? r Can MAUI Run Resource-Intensive Applications?
Big savings even on 3G An order of magnitude improvement on Wi-Fi Face Recognizer
Improvement of around an order of magnitude Face Recognizer
Up to 40% energy savings on Wi-Fi Solver would decide not to offload Arcade Game
CPU Intensive even on a Core 2 Duo PC Can be run on the phone with MAUI Translator
DoLevel HandleMissiles DoFrame HandleEnemies HandleBonuses 11KB + missiles missiles *Missiles take around 60 bytes each 11KB + missiles Required state is smaller Complexity increases with # of missiles
DoLevel HandleMissiles DoFrame HandleEnemies HandleBonuses *Missiles take around 60 bytes each Zero Missiles Low latency (RTT < 10ms) Computation cost is close to zero Offload starting at DoLevel
DoLevel HandleMissiles DoFrame HandleEnemies HandleBonuses *Missiles take around 60 bytes each 5 Missiles Some latency (RTT = 50ms) Most of the computation cost Very expensive to offload everything Little state to offload Only offload Handle Missiles
62
Adapt to: Network Bandwidth/Latency Changes Variability on method’s computational requirements Experiment: Modified off the shelf arcade game application Physics Modeling (homing missiles) Evaluated under different latency settings
64
65 The CODA system assumes that modifications are kept as logs (CML) a user sends the logs to the servers to update If the storage of a client is limited, it may not be able to save logs then upon reconnection, the cache manager needs to find the difference between the stored file and its local cached copy same problem exists for the rsync tool ! Question: how to efficiently compare the differences of two remote files (when the network connection is slow)?
66 Break Files into chunks and transfer only modified chunks Fixed chunk size does not work well why?
67 Compute hash value of every 48 byte block if the hash value equals to a magic value, it is a chunk boundary
68 Bayou: Managing Update Conflicts r Basic idea: application specific conflict detection and update r Two mechanisms for automatic conflict detection and resolution m dependency check m merge procedure df