1 mobile software development framework: mobile-cloud service 10/18/2012 y. richard yang

62
1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

Upload: calvin-waters

Post on 12-Jan-2016

218 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

1

Mobile Software Development Framework: Mobile-Cloud Service

10/18/2012

Y. Richard Yang

Page 2: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

2

Outline

Admin Mobile cloud service

Push notification service Storage service Track service Split service

Page 3: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

3

Admin.

HW3 posted

Page 4: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

Recap: Accessing Data in Cloud A typical design pattern is that a device updates/receives data in the cloud Cloud as a rendezvous point

Challenge: How do you keep data on a device fresh?

4

Page 5: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

Recap: Solution Space

Mobile poll

Cloud push Each app push Shared (infrastructure) push

5

Page 6: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

Shared Push Service

A single persistent connection from device to a cloud push service provider

Multiple application providers push to the service provider

Service provider pushes to a device using the persistent connection

Two examples Apple Push Notification Service (APNS) Google Cloud Messaging (GCM)

6

Page 7: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

Design Requirements of a Shared Push Service

Security/Authorization Do not allow arbitrary app to push to a device

Scalability A large scale system may have millions of clients

Fault tolerance Client/device, push servers all can fail

Generality Can be used by diverse applications

7

Page 8: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

Design Point: Authorization

8

App Device

Registration(DEV_ID, App_ID)Design 2: App query registered devices;

Multicast

Design 3: Device notifies registration ID to its server;

Design 1: App does not know registered devices. Broadcast to all.

Page 9: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

Design Point: What to Push?

Option 1: Just push signal (data available) to devices and then devices fetch from app servers

Option 2: push app data

9

App Device

Page 10: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

Design Point: Reliability (What Can Go Wrong)

10

App Device

RegID=Registration(DEV_ID, App_ID)App sends to

regIDs

Device notifies regID to its server;

Page 11: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

Soft State Design

State at the third party is soft state if the the entity who sets up the state does not refresh it, the state will be pruned at the 3rd party

11

Page 12: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

Apple Push Notification Service

12

iOS device maintains a persistent TCP connection to an Apple Push Notification Server(APNS)

A push notification from a provider to a client application

Multi-providers to multiple devices

Page 13: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

APNS Authorization: Device Token

13

Device token Contains information that enables APNs to locate the device Client app needs to provide the token to its app provider Device token should be requested and passed to providers every time your application launches

Page 14: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

Apple Push Notification Data Each push notification carries a payload 256 bytes maximum Best effort delivery

App provider provides a JSON dictionary object, which contains another dictionary identified by the key aps

aps specifies the following actions• An alert message to display to the user• A number to badge the application icon with• A sound to play

14

Page 15: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

APNS Example: Client

15

1. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

2. {3. // Let the device know we want to receive push notifications4. [[UIApplication sharedApplication] registerForRemoteNotificationTypes:5. (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound

| UIRemoteNotificationTypeAlert)];6. 7. return YES;8. }

9. - (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo

10. {//userInfo contains the notification11. NSLog(@"Received notification: %@", userInfo);12. }

13. - (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken

14. {15. NSLog(@"My token is: %@", deviceToken);16. }

Page 16: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

APNS Example: Server

16

1. $devicetoken ='f05571e4be60a4e11524d76e4366862128f430522fb470c46fc6810fffb07af7’;2. // Put your private key's passphrase here:3. $passphrase = 'PushChat';4. // Put your alert message here:5. $message = ’CS434: my first push notification!';

1. $ctx = stream_context_create();2. Stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');3. stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);

4. // Open a connection to the APNS server5. $fp = stream_socket_client(6. 'ssl://gateway.sandbox.push.apple.com:2195', $err,7. $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);

8. if (!$fp)9. exit("Failed to connect: $err $errstr" . PHP_EOL);

10. echo 'Connected to APNS' . PHP_EOL;

Page 17: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

APNS Example: Server (cont’)

17

16. // Create the payload body17. $body['aps'] = array(18. 'alert' => $message,19. 'sound' => 'default'20. );

21. // Encode the payload as JSON22. $payload = json_encode($body);

23. // Build the binary notification24. $msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;

25. // Send it to the server26. $result = fwrite($fp, $msg, strlen($msg));

27. if (!$result)28. echo 'Message not delivered' . PHP_EOL;29. else30. echo 'Message successfully delivered' . PHP_EOL;

31. // Close the connection to the server32. fclose($fp);

Page 18: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

Google Cloud Messaging

Very similar to APNS

18

GCM Servers

See http://developer.android.com/guide/google/gcm/gs.htmlfor detailed steps

Page 19: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

GCM Flow: App Developer Registration App developer registers a project at Google

Open API console: https://code.google.com/apis/console/

After Create project

19

Project ID; Sender ID

Page 20: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

GCM Flow: Device App Registration Enable cloud to device messaging in your app Add permissions in Manifest App (on device) registers with Google to get registration ID

20

Page 21: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

Device App Handle Events

21

The GCMBroadcastReceiver (defined in GCM library) handles the broadcast messages, and calls methods defined in .GCMIntentService, if you define this service

<receiver android:name="com.google.android.gcm.GCMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND" > <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <action android:name="com.google.android.c2dm.intent.REGISTRATION" /> <category android:name="my_app_package" /> </intent-filter></receiver>

Page 22: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

GCMIntentService

22

// called after GCM library finishes registration// you need to send regId to your serveronRegistered(Context context, String regId);

onUnregistered(Context context, String regId);

// called after your server sends a msg to GCM, and// GCM sends to this deviceonMessage(Context context, Intent intent);

onError(Context context, String errorId);onRecoverableError(Context context, String errorId)

Page 23: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

App Server If you use GCM server library

23

import com.google.android.gcm.server.*;

Sender sender = new Sender(myApiKey);Message message = new Message.Builder().build();MulticastResult result = sender.send(message, devices, 5);

Page 24: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

Summary: GCM Flow Enabling cloud to device messaging

App (on device) registers with Google to get registration ID

App sends registration ID to its App Server Per message

App Server sends (authenticated) message to Google

Google sends message to device, which sends to app

Disabling cloud to device messaging App can unregister ID, e.g., when user no longer wants push

24

Page 25: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

Additional Details See Thialfi: A Client Notification Service for Internet-Scale Applications, by Atul Adya, Gregory Cooper, Daniel Myers, Michael Piatek, ACM SOSP 2011.

25

Page 26: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

Discussion: Mobile Cloud Services We have discussed push notification service. What other services can you think of?

26

Page 27: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

Example Mobile Cloud Services Push notification service Storage and sync

Syncing and storage service (iCloud) Location based service

Track service (supporting location based services)

Proxy service (Kindle Split Browser) Recognition services

Speech to text/text to speech service Natural language processing service (open Siri API for 3rd party applications in the future)

27

Page 28: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

Apple iCloud

Store content in cloud and sync to all registered devices Hosted by Windows Azure and

Amazon AWS iCloud Storage APIs support third-party app document syncing

28

Page 29: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

29

Outline

Admin Mobile cloud service

Push notification service Track service

• StarTrack Next Generation: A Scalable Infrastructure for Track-Based Applications, by Maya Haridasan, Iqbal Mohomed, Doug Terry, Chandramohan A. Thekkath, and Li Zhang, in OSDI 2010.

Page 30: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

Location-Based Applications

Many phones already have the ability to determine their own location GPS, cell tower triangulation, or proximity to WiFi hotspots

Many mobile applications use location information

Courtesy: Maya et al.

Page 31: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

A Common Abstraction: TrackTime-ordered sequence of location readings

Latitude: 37.4013Longitude: -122.0730

Time: 07/08/10 08:46:45.125

Latitude: 37.4013Longitude: -122.0730

Time: 07/08/10 08:46:45.125

Page 32: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

Application: Personalized Driving Directions

Goal: Find directions to new gym

32Courtesy: Maya et al.

Page 33: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

A Taxonomy of Applications

Class of applications enabled by StarTrack

33

Page 34: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

StarTrack System

ST Client

Insertion Application

Location Manage

r

• Retrieval• Manipulation• Comparison

Application

ST Client

• InsertionST Server

ST Server

ST Server

34

Page 35: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

System Challenges

1. Handling error-prone tracks

2. Flexible programming interface

3. Efficient implementation of operations on tracks

4. Scalability and fault tolerance

35

Page 36: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

Challenges of Using Raw Tracks

Advantages of Canonicalization: More efficient retrieval and comparison operations

Enables StarTrack to maintain a list of non-duplicate tracks 36

Page 37: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

StarTrack API: Track Collections

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) TC MakeCollection(GroupCriteria criteria, bool removeDuplicates)

37

Page 38: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

API Usage: Ride-Sharing Application

// get user’s most popular track in the morningTC myTC = MakeCollection(“name = Maya”, [0800 1000], true);TC myPopTC = SortTracks(myTC, FREQ);Track track = GetTracks(myPopTC, 0, 1);

// find tracks of all fellow employeesTC msTC = MakeCollection(“name.Employer = MS”, [0800 1000], true);

// pick tracks from the community most similar to user’s popular trackTC similarTC = GetSimilarTracks(msTC, track, 0.8);Track[] similarTracks = GetTracks(similarTC, 0, 20);

// Verify if each track is frequently traveled by its respective ownerUser[] result = FindOwnersOfFrequentTracks(similarTracks);

Page 39: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

Track Similarity

S1-4

S5 S6-7

Tracks A, B

s1

s2

s3

s4

s5

Track D

s8

s9

Track C

s6 s7

Page 40: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

Summary

The Track abstraction is simple but quite interesting

Think about abstractions in your project

40

Page 41: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

Amazon Silk Split-Browser

Accelerates web access Learns user behavior and precache

Intelligently partion work between local and Amazon cloud

41http://www.extremetech.com/mobile/97587-amazon-silk-bridging-the-gap-between-desktop-and-tablet-web-browsers

Page 42: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

Example Benefit of Cloud (RTT -> Server)

42

Page 43: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

Generalization: mCloud

Basic questions What architecture best supports mcloud?• What resources at where

What programming model best support mcloud?

43

Page 44: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

Example: MAUI

44

Maui serverSmartphone

Application

Client Proxy

Profiler

Solver

Maui Runtime

Server Proxy

Profiler

Solver

Maui Runtime

Application

RPC

RPC

Maui Controller

Page 45: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

How Does a Programmer Use MAUI?

Goal: make it dead-simple to MAUI-ify apps Build app as a standalone phone app Add .NET attributes to indicate “remoteable”

Follow a simple set of rules

Page 46: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

Maui serverSmartphone

Application

Client Proxy

Profiler

Solver

Maui Runtime

Server Proxy

Profiler

Solver

Maui Runtime

Application

RPC

RPC

Maui Controller

Intercepts Application CallsSynchronizes State

Chooses local or remote

Handles Errors

Provides runtime information

Page 47: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

Profiler

ProfilerCallgraphCallgraph

Execution TimeExecution Time

State sizeState size

Network LatencyNetwork Latency

Network BandwidthNetwork Bandwidth

Device ProfileDevice ProfileCPU CyclesCPU Cycles

Network Power CostNetwork DelayComputational Delay

Computational Power Cost

Computational Delay

Annotated

Callgraph

Page 48: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

B900 mJ15ms

C5000 mJ3000 ms

1000mJ25000 m

J D15000 mJ12000 ms

1000

0 m

J

A

Computation energy and delay for execution

Energy and delay for state transfer

A sample callgraph

Page 49: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

FindMatch

900 mJ

InitializeFace

Recognizer5000 mJ

1000mJ25000 m

J DetectAndExtract Faces15000 mJ

1000

0 m

J

UserInterfa

ceCheaper to do local

Page 50: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

FindMatch

900 mJ

InitializeFace

Recognizer5000 mJ

1000mJ25000 m

J DetectAndExtract Faces15000 mJ

1000

0 m

J

UserInterfa

ce

Cheaper to do local

Cheaper to do local

Page 51: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

FindMatch

InitializeFace

Recognizer

1000mJ

DetectAndExtract Faces

UserInterfa

ce20900mJ

Cheaper to offload

Page 52: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

MAUI Implementation

Platform Windows Mobile 6.5 .NET Framework 3.5 HTC Fuze Smartphone Monsoon power monitor

Applications Chess Face Recognition Arcade Game Voice-based translator

Page 53: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

Questions

How much can MAUI reduce energy consumption?

How much can MAUI improve performance?

Can MAUI Run Resource-Intensive Applications?

Page 54: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

Big savings even on 3G

An order of magnitude

improvement on Wi-Fi

Face Recognizer

Page 55: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

Improvement of around an order of

magnitude

Face Recognizer

Page 56: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

Up to 40% energy savings on Wi-Fi

Solver would decide not to

offload

Arcade Game

Page 57: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

CPU Intensive even on a Core 2 Duo PC

Can be run on the phone with MAUI

Translator

Page 58: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

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

Page 59: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

DoLevel

HandleMissilesHandleMissiles

DoFrame

HandleEnemies

HandleBonuses

11KB + missiles

11KB +

missiles

missil

es

*Missiles take around 60 bytes each

11KB + missiles

Required state is smaller

Complexity increases with # of missiles

Page 60: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

DoLevel

HandleMissiles

DoFrame

HandleEnemies

HandleBonuses

*Missiles take around 60 bytes each

Zero MissilesLow latency (RTT < 10ms)

Computation cost is close to zero

Offload starting at DoLevel

Page 61: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

DoLevel

HandleMissiles

DoFrame

HandleEnemies

HandleBonuses

*Missiles take around 60 bytes each

5 MissilesSome latency (RTT = 50ms)

Most of the computation cost

Very expensive to offload everything

Little state to offload

Only offload Handle Missiles

Page 62: 1 Mobile Software Development Framework: Mobile-Cloud Service 10/18/2012 Y. Richard Yang

Roadmap

Motivation MAUI system design

MAUI proxy MAUI profiler MAUI solver

Evaluation Conclusion