Highperformancebrowsernetworking
How prepared are you when it comes to building network-enabled applications? This book provides what every web developer should know about the network - from fundamental limitations that affect performance to major innovations for building even more powerful browser apps. By understanding what the bHigh-Performance BrowserNetworkingIlya grigoriO'REILLYBei ing. Cambridge: Farnham·kaln· Sebastopol· TokyoHigh-Performance browser Networkingy llya GrigoriCopyright O 2013 Ilya Grigorik. All rights reservedPrinted in the United States of americaPublished by o reilly media, InC, 1005 Gravenstein Highway North, Sebastopol, CA95472O Reilly books may be purchased for educational, business, or sales promotional use Online editions arealsoavailableformosttitles(http://my.safaribooksonline.com).fOrmoreinformation,contactourcorporateinstitutionalsalesdepartment800-998-9938orcorporate@oreilly.comEditor: Courtney NashCover Designer: Randy ComerProduction Editor: Melanie YarbroughInterior Designer: David FutatoProofreader: Julie Van Keurenllustrator: Kara ebrahimIndexer: Word Co Indexing Serviceseptember 2013: First EditionRevision History for the First Edition:2013-09-09 First releaseSeehttp://oreilly.com/catalog/errata.csp?isbn=9781449344764forreleasedetailsNutshell Handbook, the Nutshell Handbook logo, and the O Reilly logo are registered trademarks ofO ReillyMedia, Inc. High-Performance Browser Networking, the image of a Madagascar harrier, and related tradedress are trademarks of o reilly media, IncMany of the designations used by manufacturers and sellers to distinguish their products are claimed astrademarks. Where those designations appear in this book, and O Reilly Media, Inc, was aware of a trademark claim, the designations have been printed in caps or initial capsWhile every precaution has been taken in the preparation of this book, the publisher and author assume noresponsibility for errors or omissions, or for damages resulting from the use of the information containedhereinISBN:978-1-449-34476-4Table of contentsForewordPrefacePart I. Networking 101Primer on latency and bandwidthSpeed is a featureThe Many Components of LatencySpeed of light and Propagation LatencyLast-Mile Latency334689Bandwidth in core networksBandwidth at the network edge10Delivering Higher Bandwidth and Lower latencies112. Building blocks of TCPThree-Way handshake14Congestion Avoidance and Control16Flow Control17Slow-Start19Congestion Avoidance26Bandwidth-Delay product28Head-of-Line BlockingOptimizing for TCP32Tuning server connguration32Tuning Application Behavior34Performance Checklist343. Building blocks of UDP35Null Protocol services36UDP and Network Address Translators38Connection -State Timeout39NAT Traversal40STUN, TURN, and iCe41Optimizing for UDP4. Transport Layer Security (TLS).........Encryption, Authentication, and Integrity48TLS Handshake50Application Layer Protocol Negotiation(ALPN)53Server Name Indication (SNI)54TLS Session Resumption55Session IdentifiersSession tickets57Chain of trust and Certificate Authorities57Certificate Revocation61Certificate Revocation List(CRL)61Online Certificate Status Protocol(OCSP)TLS Record Protocol62Optimizing for TlS63Computational CostsEarly Termination65Session Caching and Stateless Resumption67TLS Record Size68TLS CompressionCertificate-Chain Length70OCSP Stapling71Http Strict Transport Security(hsts72Performance ChecklistTesting and Verification73Part ll. performance of wireless networks5. Introduction to Wireless Networks79Ubiquitous Connectivity79Types of Wireless NetworksPerformance Fundamentals of wireless Networks81Bandwidth82Signal powerModulation86iv Table of ContentsMeasuring Real-World Wireless Performance876. WiFi89From ethernet to a wireless lan89WiFi Standards and Features91Measuring and optimizing wiFi Performance92Packet Loss in wiFi Networks94Optimizing for wiFi Network5Leverage Unmetered Bandwidth95Adapt to variable bandwidth96Adapt to Variable Latency977. Mobile networks99Brief History of the gsFirst data services with 2G1003GPP and 3GPP2 Partnerships101Evolution of 3G Technologies103IMT-Advanced 4G Requirements105Long term Evolution (lte)106HSPA+ is Leading Worldwide 4G Adoption107Building for the Multigeneration Future109Device Features and capabilities111User Equipment CategoryRadio Resource Controller(rrc)1133G, 4G, and WiFi Power Requirements115LTE RRC State MachineHSPA and HSPA+(UMTS) RRC State Machine119EV-DO(CDMA) RRC State Machine120Inefficiency of Periodic Transfers121End-to-End Carrier Architecture123Radio Access Network(RAN)123Core Network(CN)125Backhaul capacity and latency128Packet flow in a mobile network129Initiating a Request129Inbound data flow132Heterogeneous Networks(HetNets133Real-World 3G, 4G, and wiFi Performance1358. Optimizing for Mobile NetworkS.... ................... 139Preserve Battery power140Eliminate periodic and inefficient Data Transfers142Table of contentEliminate Unnecessary Application KeepalivesAnticipate Network latency overhead145Account for rrc state Transitions146Decouple user Interactions from Network Communication146Design for Variable Network Interface Availability147Burst Your data and return to idleOffload to wiFi Networks150Apply Protocol and Application Best Practices150Part l. Http9. Brief History of Http.155Http 0.9: The One-line Protocol155Http 1.0: Rapid growth and Informational rfc157Http 1.1: Internet Standard159Http 2.0: Improving Transport Performance16110. Primer on Web performance165Hypertext, Web Pages, and Web Applications166Anatomy of a Modern Web application168Speed, Performance, and Human Perception170analyzing the resource waterfallPerformance Pillars: Computing, Rendering, Networking176More Bandwidth doesnt Matter(Much)176Latency as a Performance Bottleneck177Synthetic and Real-User Performance Measurement179Browser optimization18311.http1.x,187Benefits of Keepalive Connections189Http Pipelining192Using Multiple TCP Connections196Sharingg198Measuring and Controlling Protocol Overhead200Concatenation and Spriting201Resource Inlining2042.HTTP2.0.207History and relationship to SPDy208Theroadtohttp2.0209Design and Technical goals211vi Table of ContentsBinary Framing Layer211Streams, Messages, and Frames212Request and Response Multiplexing214Request prioritization215One Connection Per Origin217Flow Control218Server push219Header Compression222Efficient Http 2.0 Upgrade and Discovery224Brief Introduction to Binary Framing226Initiating a New stream229Sending Application Data230Analyzing Http 2.0 Frame Data Flow23013. Optimizing Application Delivery.233Evergreen Performance Best Practices235Cache Resources on the client236Compress Transferred Data237Eliminate Unnecessary request bytes238Parallelize Request and Response Processing239Optimizingforhttp1.x241Optimizingforhttp2.0241Removing 1. x Optimizations242Dual-Protocol Application Strategies244Translating 1. x to 2.0 and back245Evaluating Server Quality and performance247Speaking 2.0 with and without TLS247Load Balancers, Proxies, and Application Servers248Part v. browser apls and protocols14. Primer on Browser Networking.253Connection Management and Optimization254Network Security and Sandboxing256Resource and Client State Caching257Application aPis and protocols25815. XmLHttp reQuest.261Brief History of XHR262Cross-Origin Resource Sharing(CORS263Downloading data with XHR266Table of contents|ⅶiUploading data with XHR268Monitoring Download and Upload Progress269Streaming Data with XHR271Real-Time Notifications and delivery27Polling with XHR274Long-Polling with XHR276XHR Use Cases and Performance27816. Server-Sent Events(SSE)279Event Source api279Event stream protocol282SSE USe Cases and Performance28517. WebSocket鲁。。。非。,287Web Socket api288WS and wSS URL Schemes289RText and Binary data290Sending Text and Binary data291Subprotocol negotiation293Web Socket protocol294Binary Framing layer295PoI Exte297Http Upgrade Negotiation298Web Socket Use Cases and performance301Request and Response Streaming302Message Overhead303Data Efficiency and Compression304Custom Application Protocols304Deploying Web Socket Infrastructure305Performance Checklist30718. Webrto309Standards and development of webrto310Audio and Video Engines311Acquiring Audio and Video with get UserMedia312Real-Time Network Transports315Brief Introduction to RTCPeer Connection API317Establishing a peer-to-Peer Connection319Signaling and Session Negotiation320Session Description Protocol (SDP)322Interactive Connectivity Establishment(ICe)325Incremental Provisioning(Trickle ICE)328I Table of Contents
用户评论