Slide 1

Slide 1 text

Confidential ©2008-15 New Relic, Inc. All rights reserved. 1

Slide 2

Slide 2 text

2 ©2008-15 New Relic, Inc. All rights reserved. What this talk is about Mobile is everywhere! Network-related performance problems affect customer experience. Nobody wants 
 to get 1-star 
 app reviews. Covers network 
 request best 
 practices in 
 mobile.

Slide 3

Slide 3 text

©2008-15 New Relic, Inc. All rights reserved. 3 App Network Backend Web Server The Three Pillars of App Blame

Slide 4

Slide 4 text

©2008-15 New Relic, Inc. All rights reserved. Blame the app. 4

Slide 5

Slide 5 text

©2008-15 New Relic, Inc. All rights reserved. 5 "App is unresponsive." ★ ★ ★ ★ ★ "Pages are slow to reload.” ★★★★★ "It takes forever when I tap login." ★★★★★ "The app freezes all the time." ★ ★ ★ ★ ★ Reviews you might read...

Slide 6

Slide 6 text

Confidential ©2008-15 New Relic, Inc. All rights reserved. 6 ▪ Don't block the main thread Lesson #1: CC A ND https://www.flickr.com/photos/buechertiger/6499330057

Slide 7

Slide 7 text

©2008-15 New Relic, Inc. All rights reserved. 7 Introducing... the world's slowest viewDidLoad: - (void) viewDidLoad { // Sync Example #1 NSHTTPURLResponse *response = nil; NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"https://nr/api/v1/data"]; cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:5.0]; NSData *conn = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; // Sync Example #2 NSData *data = [NSData dataWithContentsOfURL:@"http://nr/api/data"]; // Sync Example #3 cell.photo.image = [UIImage imageWithData: [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://nr/bar.png"]]]; }

Slide 8

Slide 8 text

©2008-15 New Relic, Inc. All rights reserved. Main Thread Blocking Checklist No synchronous network calls happen on the main thread. Use a decent open-source networking library that does the threading for you. If the UI stutters or scrolling performance seems degraded, start looking for code that's blocking the main (UI) thread. 8 ▪ ▪ ▪

Slide 9

Slide 9 text

Confidential ©2008-15 New Relic, Inc. All rights reserved. 9 ▪ Do go chasing waterfalls Lesson #2: CC A ND https://www.flickr.com/photos/salford_ian/3053537527

Slide 10

Slide 10 text

©2008-15 New Relic, Inc. All rights reserved. Waterfalls are for mobile, too! 10

Slide 11

Slide 11 text

©2008-15 New Relic, Inc. All rights reserved. How many parallel requests are too many? • Per-host limit on iOS and Android. Fuzzy documentation. • Generally you'll get limited to 4-5 depending on OS version, library or SDK (NSURLSession vs NSURLConnection). • Rule: just bundle requests and don't flood hosts. 11

Slide 12

Slide 12 text

©2008-15 New Relic, Inc. All rights reserved. API Client Request Best Practices Issue network requests in parallel (with limits). Have a single API request per screen. HTTP cache headers are your friend and API clients 
 can use them intelligently. Pay attention to request size (and gzip compression). 12 ▪ ▪ ▪ ▪

Slide 13

Slide 13 text

©2008-15 New Relic, Inc. All rights reserved. Blame the network. 13

Slide 14

Slide 14 text

©2008-15 New Relic, Inc. All rights reserved. Reviews you might read... 14 "Bonjour. Your app is slow on Orange 3G." ★ ★ ★ ★ ★ "Takes 15 seconds to login in Singapore." ★ ★ ★ ★ ★ "App is slow when not on WiFi." ★★ ★ ★ ★ "不正なアプリケーション" ★ ★ ★ ★ ★

Slide 15

Slide 15 text

Confidential ©2008-15 New Relic, Inc. All rights reserved. ▪ 15 Never trust the network Lesson #3: CC A ND https://www.flickr.com/photos/ian1231/33443537527

Slide 16

Slide 16 text

©2008-15 New Relic, Inc. All rights reserved. Information can't travel faster than the speed of light 16 CC0 Problem: 
 your datacenter is in Virginia and customers are in Singapore. Advanced: 
 Consider implementing CDN caching of API requests 
 as well. Content-delivery networks (CDNs) can move your static content physically closer to customers.

Slide 17

Slide 17 text

©2008-15 New Relic, Inc. All rights reserved. Unreliable Network Best Practices Always test your app in airplane mode. Pay attention to user experience differences across 
 different regions, countries, and providers. Re-create bad networks locally using open-source tools 
 (i.e. augmented-traffic-control, Network Link Conditioner) 17 ▪ ▪ ▪

Slide 18

Slide 18 text

©2008-15 New Relic, Inc. All rights reserved. Blame the backend. 18

Slide 19

Slide 19 text

©2008-15 New Relic, Inc. All rights reserved. Reviews you might read... 19 "Search takes foooooorever." ★ ★ ★ ★ ★ "The progress indicator keeps spinning." ★ ★ ★ ★ ★ "Keeps saying operation can't be completed." ★★ ★ ★ ★ "I get weird error messages about parsing JSON." ★ ★ ★ ★ ★

Slide 20

Slide 20 text

Confidential ©2008-15 New Relic, Inc. All rights reserved. 20 ▪ "Mobile APIs are forever" (credit: @alperkomen) Lesson #4: CC A ND https://www.flickr.com/photos/torkildr/3462607995

Slide 21

Slide 21 text

©2008-15 New Relic, Inc. All rights reserved. "This is clear to anyone who uses this API" 21 curl -H "a_token=aea22f80344147c4" http:// api.bad-api.horse/mobile/create/user?name=Bob {"status": "fail"} 200 OK Request

Slide 22

Slide 22 text

©2008-15 New Relic, Inc. All rights reserved. 22 API Design for Mobile Best Practices Have clear, consistent documentation. Make mobile clients uniquely identifiable by the 
 User-Agent HTTP header. Return standard error codes (200s, 400s, and 500s). Consider versioned APIs ("mobile is forever"). ▪ ▪ ▪ ▪

Slide 23

Slide 23 text

©2008-15 New Relic, Inc. All rights reserved. 23 Good idea Pay attention to the network

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

No content