1
End-to-End Performance Analytics For Mobile Apps
Lenin Ravindranath, Jitu Padhye, Ratul MahajanMicrosoft Research
2
“Slower than a snail.”
“Slow and unresponsive like mud”
“Consistently 3 seconds behind where I touch.”
“So slow. Did an intern write this app??”
“Very very slow compared to even browsing web.”
“Sluggish and freezes my HTC phone.”
Apps are Slow
3
CloudServices
MobileApps
Most Mobile Apps talk to the Cloud
4
Cloud Service
Location
Restaurants
5
AppInsight
App
AppInstrumented
Instrumenter
ClickHandler() { [Instrument] LocationStart(LocationCallback);}
LocationCallback(location) { [Instrument] url = GetRequestUrl(location); [Instrument] WebRequest(url, WebResponseCallback);}
WebResponseCallback(data) { [Instrument] list = ParseData(data); [Instrument] UIDispatch(Display, list);}
Display(list){ [Instrument] UIListBox.DataContext = list;}
Automatic Instrumentation
6
AppInsight
User click
Web Request Web Response
Web Requestdelay
User Perceived Delay
GPSdelay
Parsing and Renderingdelay
7
AppInsight
User click
Web Request Web Response
User Perceived Delay
Where is the bottleneck?
Network? Server?DB?Uplink? Downlink?
8
End-to-End Insight
User click
Web Request Web Response
User Perceived Delay
Server
Uplinkdelay
Downlinkdelay
Serverdelay
Query Processingdelay
DB
GPSdelay
Parsing and Renderingdelay
9
EndInsight
• Joint App and Server Instrumentation– Windows Phone Apps, ASP .NET Services– Automatic Instrumentation– Zero developer effort– Binary Instrumentation
• Readily deployable– No changes to the OS, runtime or platform
• Low overhead
10
App
App Instrument
er
InstrumentedApp
Service Instrumente
r
Service
InstrumentedService
Developer
Cloud
App Store
Analysis Server
Developer Feedback
Traces
Traces
Downloads
11
App Instrumentation
User click
Web Request Web Response
Web RequestdelayGPS
delayParsing and Rendering
delay
Using AppInsight
12
AppInsight Recap• Track User Transactions– From user click to UI rendering
• Across asynchronous thread boundaries
• Automatically track– UI manipulation– Threads, asynchronous calls– Web calls, Sensor APIs– UI update (dispatcher events)
User request UI Update
UI Thread
Background thread
GPS fix Callback
UI dispatch
Background thread
Web Request
Response Callback
App
GPS Start
13
Server Instrumentation• Automatic Instrumentation of .NET binaries• Azure services– Web APIs, ASPX pages, MVC, WCF
• Automatically track– Request-Response entry points– DB queries– Network calls
• Across asynchronous boundaries– Similar to app instrumentation
class AroundMeController: ApiController{
public Result Get(type, location) { [Instrument] return GetList(type, location); [Instrument]}
public Result GetList(type, location) { [Instrument] result = DBQuery(type, location); [Instrument] return result;}
}
14
Server InstrumentationServerdelay
Query Processingdelay
DB
Request Response
Request Processing Delay
15
Putting them together?
Serverdelay
Query Processingdelay
DB
Request Response
Web Request Web Response
App Performance
Server Performance
16
Matching App and Server Traces
• Pass a Unique Id from App to Server• Add a new HTTP header in web requests– x-EndInsight-Id
• App Instrumentation– Instrument HTTP request calls– Generate unique Id when app makes a web request– Add x-EndInsight-Id header in web requests
• Server Instrumentation– Log the unique id and remove the extra header at the request
entry point
17
Matching App and Server Traces
User click
Web Request Web Response
Server
DB
Add header[x-EndInsight-Id] = “59bc73e4-9251-4618-97a7-41ac86c6c039”
Log and Remove header[x-EndInsight-Id]
18
DB
Request Response
Web Request Web Response
Finding Network Delays
Server Request Processing Delay
App Web Request Delay
Network Delay = [App Web Request Delay] – [Server Request Processing Delay]
19
Separating Uplink and Downlink Delays
Server
Uplinkdelay
Downlinkdelay
DB
Requires knowing the clock offset and driftbetween Client and Server
Different Clocks
Timestamp
Timestamp
20
Finding Clock Offset and DriftNTP-like TechniqueProbes from client timestamped by the server
Timestamp ts Timestamp te
Timestamp s
Clock Offset = s – ((ts + te) / 2) Clock Drift = Slope of linear regression of many such probes
More probes, better estimate
21
• Automatic Instrumentation of App– To send periodic probes to server
• Automatic Instrumentation of Server– Open up API to timestamp probes
Probing
• Efficient technique for probing– Aware of the radio state and traffic– Minimal extra delays– Energy efficient
22
Network Delays• Uplink– DNS– Connection setup
• Downlink
Analysis
App Delays• App processing• Sensor processing• Parsing/Rendering• Radio wakeup• Disk access
Server Delays• Server Processing• Query Processing
Automatic analysis of end-to-end transaction delays
23
Critical Path Analysis
24
Group similar transactions
• Outliers– Points to corner cases
• Highlight common critical paths– Focus development effort
• Root causes of Performance Variability– Highlight factors affecting performance
Aggregate Analysis
25
Web based Interface
Developer Feedback
26
Compute NetworkMemory Battery
low2% 4%<0.1%
• Impact on app and server performance is minimal• Low resource consumption
EndInsight Overhead
27
Timecard: Controlling End-to-End Delays
28
Servers Control Variability in Response Times
Request Response
• Fixed deadlines• Trade-off quality for response time– More time to compute, better quality results– Flexible Services
Deadline
Server processing
29
The elephant is outside the room
Request Response
Server processing
30
The elephant is outside the room
User click
Server processing
App App
ServerRequest Response
Uplink Downlink
31
• Unaware of end-to-end delays• Clients with non-trivial external delays– Poor end-to-end response times
• Client with minimal external delays– Do not produce the best quality result
• Could adapt differently for different users
Servers have no visibility into delays outside
32
TimecardGetElapsedTime(); PredictDownstreamTime
(responseSize);
Time elapsed since user request
Predicted downlink + app processing delay
App App
Server
33
Timecard
App App
Server
Desired end-to-end delay
App
GetElapsedTime(); PredictDownstreamTime(responseSize);
Adapt Processing Time
34
Timecard
App
Server
Desired end-to-end delay
AppApp
GetElapsedTime(); PredictDownstreamTime(responseSize);
Adapt Response
35
Timecard
App
Server
Desired end-to-end delay
App
GetElapsedTime(); PredictDownstreamTime(responseSize);
36
• Online Transaction Tracking• Time Synchronization• Downstream Delay Predictor– Downlink delay– App processing delay
Timecard
37
Timecard Implementation
App App
Server
Transaction Tracking
Transaction Tracking
Logging
Predictor
Time Sync
Data Collection
Automatic Instrumentation• WP Apps• ASP .NET services APIs