Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Advanced Networking

Mobile Flock
September 14, 2019

Advanced Networking

Some advanced networking protocols and URLSession APIs that we can use to improve the connectivity of our mobile application.

Mobile Flock

September 14, 2019
Tweet

More Decks by Mobile Flock

Other Decks in Technology

Transcript

  1. Why a New Protocol? SMTP WebSocket UDP POP3 Bonjour LDAP

    TCP SSH QUAKE3 FTP HTTP DHCP Telnet VoIP ICMP
  2. HTTP/1.1 HTTP/2 Multiple TCP connections Head-of-line blocking FIFO restrictions Textual

    protocol overhead No header compression Only one TCP connection Fully multiplexed Requests have priorities Binary Header compression (HPACK)
  3. HTTP/1.1 Latency App URLSession Server Time GET index.html index.html Response

    GET style.css style.css Response GET background.jpg background.jpg Response
  4. HTTP/2 Server Push Latency App URLSession Server Time GET index.html

    index.html Response PUSH 2, 3, n GET Response style.css GET Response background.jpg
  5. Wi-Fi Assist Triggered by · Marginal Wi-Fi “Fittest Wins Out”

    contest between Wi-Fi and Cell · Wi-Fi has head start over Cell · On a flow by flow basis, at flow setup time
  6. Multipath TCP · Built on top of TCP - Reliability

    - Congestion control · Seamless handover from Wi-Fi to Cell · Chooses optimal interface for latency-sensitive flows
  7. Multipath TCP MPTCP schedules traffic across the interfaces One “TCP

    subflow” per interface MPTCP creates/destroys subflows URLSession MPTCP Stack TCP subflow
 over Wi-Fi TCP subflow
 over Cellular
  8. Multipath TCP Implemented since iOS 7 for Siri User feedback

    (time to first word) 
 20% faster in the 95th percentile 5x reduction in network failures
  9. ```````` Add Capability “Multipath” in Xcode Exposed as URLSessionConfiguration property

    var multipathServiceType: URLSessionConfiguration.MultipathServiceType
 
 none = 0 handover = 1 interactive = 2 Multipath TCP URLSession
  10. URLSession and Connectivity URLSession with defaultSessionConfiguration fetches or fails Lack

    of connectivity causes URLSessionTasks to immediately fail
 with errors · NSURLErrorNotConnectedToInternet · NSURLErrorCannotConnectToHost
  11. Only cellular connectivity, but allowsCellularAccess prohibits cellular Unsatisfactory Connectivity Examples

    No Ethernet cable, not connected to Wi-Fi network, no cellular signal Device in Airplane Mode VPN not connected
  12. Current Solutions Each app must manually retry URLSessionTasks once connectivity

    
 is satisfactory When is that? · Monitor conditions with SCNetworkReachability API · Polling/manual retry
  13. Wouldn’t it be easier to say… “Please fetch me this

    resource when the network is available.”
  14. Indicates URLSession should monitor network conditions 
 and wait to

    start tasks Begins network load once connectivity is satisfactory 
 instead of delivering errors · No longer a need to monitor connectivity and 
 manually retry requests New URLSessionConfiguration property var waitsForConnectivity: Bool URLSession Adaptable Connectivity API Built-in connectivity monitoring
  15. URLSession Adaptable Connectivity API Insufficient connectivity notification Notification that a

    URLSessionTask is waiting for connectivity Opportunity to alter app behaviour or indicate status New URLSessionTaskDelegate method · Optional—not required to take advantage of adaptable 
 connectivity functionality · Called at most one time for each URLSessionTask urlSession(_:taskIsWaitingForConnectivity:)
  16. Always enable waitsForConnectivity URLSession Adaptable Connectivity API When to enable

    it No downside—if connectivity is available, tasks will start right away General recommendation Exception Requests that must be completed immediately, or not at all for example, “Fill or Kill” stock trading transaction
  17. Low Data Mode User preference to minimise data usage ·

    Explicit signal to reduce network data use · Per Wi-Fi and Cellular network System policy · Discretionary tasks deferred · Background App Refresh disabled
  18. Application Adoption Reduce image quality Reduce pre-fetching Synchronise less often

    Mark tasks discretionary Disable auto-play Do not block user-initiated work
  19. URLSession · Try large/prefetch with allowsConstrainedNetworkAccess = false · On

    failure with error.networkUnavailableReason == .constrained try Low Data Mode alternative Low Data Mode APIs
  20. QUIC Quick UDP Internet Connection Experimental Much faster than TCP

    based protocols Proposed to become the basis for HTTP/3