SPDYãæµè¡ã£ã¦ãã¦ï¼è¤æ°ã®TCPã³ãã¯ã·ã§ã³ã1ã¤ã«ã¾ã¨ãã¦é«éåãå³ããããã¨ãããã¨ã¯ç¥ã£ã¦ããï¼
ãããï¼åã«TCPã®ã³ãã¯ã·ã§ã³æ°ãæããã ããªãHTTP 1.1ã®Keep Aliveãpipeliningã使ãã°ãããï¼æ¢åæè¡ã®ã©ããåé¡ã§SPDYã¯ã©ã解決ãã¦ããã®ãã調ã¹ã¦ã¿ãï¼
SPDYã®äººã§ãWebæ¨æºã®äººã§ããªãã§ããªãã®ã§ï¼ééããå¤åå«ã¾ãã¦ãã¾ãï¼
並åTCPã³ãã¯ã·ã§ã³
並åã«TCPã³ãã¯ã·ã§ã³ãå¼µãç¶æ³ã¨ãã¦ï¼Webã®ä¸çã«ããã¦ã¯ä»¥ä¸ã®2ã¤ãæãã¤ãï¼
- ãã©ã¦ã¶ããããã¼ã¸ããã¼ããã¦ï¼ãã®ãã¼ã¸ã«è¤æ°ã®ç»åãã¡ã¤ã«ãå«ã¾ãã¦ããï¼ããããåæã«åå¾ããããã«ä¸¦åã«TCPã³ãã¯ã·ã§ã³ãå¼µãï¼HTTPãªã¯ã¨ã¹ããæããï¼
- JSã§éåæã«è¤æ°ã®HTTPãªã¯ã¨ã¹ããæããï¼1åã®ãªã¯ã¨ã¹ããæããã¨ãã«1åã®TCPã³ãã¯ã·ã§ã³ãå¼µãï¼
並åTCPã³ãã¯ã·ã§ã³ã®åé¡ç¹
SPDYã®ãã©ãã( SPDY Protocol - Draft 3 - The Chromium Projects SPDY Protocol - Draft 3 日本語訳 )ãèªãã¨ï¼
One of the bottlenecks of HTTP implementations is that HTTP relies on multiple connections for concurrency.
SPDY Protocol Draft 3 - 1. Overview
HTTP å®è£ ã®ããã«ããã¯ã®1ã¤ã«ã並åå¦çã®ããã«è¤æ°ã³ãã¯ã·ã§ã³ãå¿ è¦ã¨ãããã¨ãããã¾ãã
ã¨ããï¼ããããªãããã«ããã¯ã¨ãªããã¨ããã¨
This causes several problems, including additional round trips for connection setup, slow-start delays, and connection rationing by the client, where it tries to avoid opening too many connections to any single server.
SPDY Protocol Draft 3 - 1. Overview
ããã¯ãæ¥ç¶ç¢ºç«ã®ããã«è¿½å ã§çºçããã©ã¦ã³ãããªããããã¹ãã¼ã¹ã¿ã¼ãã«ããé 延ãããã¦1ã¤ã®ãµã¼ãã¼ã«å¯¾ãã¦è¤æ°ã®æ¥ç¶ããããªããã¨ãé¿ããããã®ã¯ã©ã¤ã¢ã³ãã«ããã³ãã¯ã·ã§ã³ã®å²ãå½ã¦ãã¨ãã£ãããã¤ãã®åé¡ãå¼ãèµ·ããã¾ãã
ã¨ããï¼
â æåã®"additional round trips for connection setup"ã¨ã¯ï¼TCPæ¥ç¶ã確ç«ããããã«è¡ã3-wayãã³ãã·ã§ã¤ã¯ã®ããã®ãã±ããã®å¾å¾©ã®ãã¨ã§ããï¼
並åã«ã³ãã¯ã·ã§ã³ã確ç«ããå ´åã¯ï¼3-wayãã³ãã·ã§ã¤ã¯ã並åã«å®è¡ãããã¨ã«ãªãï¼ãã1ã³ãã¯ã·ã§ã³ã«ã¾ã¨ãã¦ããã°ï¼è¿½å ã®3-wayãã³ãã·ã§ã¤ã¯ã¯å¿ è¦ãªããªãï¼ããã¯ã¬ã¤ãã³ã·ã®åé¡ã¨ããããï¼(2016/03/23 ä¿®æ£ï¼ã¬ã¤ãã³ã·ã®ã»ãããããåé¡ï¼) ãµã¼ãã®è² è·ã¨ã¤ã³ã¿ã¼ãããä¸ãæµããç¡é§ãªãã±ãããå¢ãã¦ãã¾ãã¨ãããã¨ãåé¡ãªæ°ãããï¼â¡ 次ã®"slow-start delays"ã¨ã¯ï¼TCPã®ã¦ã£ã³ãã¦ãµã¤ãºã大ãããªãã¾ã§ã®é 延æéã®ãã¨ã§ããï¼
TCPã§ã¯ãããã¯ã¼ã¯ã®è¼»è¼³ãåé¿ããããã«ï¼å¾ã ã«ã¦ã£ã³ãã¦ãµã¤ãºï¼åæã«éä¿¡ãããã±ããæ°ï¼ãå¢å ãããï¼
ã¦ã£ã³ãã¦ãµã¤ãºãå¢å ããã°åºæ¬çã«ã¯ã¹ã«ã¼ãããã¯åä¸ããï¼
åä¸ã®TCPã³ãã¯ã·ã§ã³ã使ãåãã°ï¼ãããã¯ã¼ã¯ã輻輳ãã¦ããªãéãã¦ã£ã³ãã¦ãµã¤ãºã¯ãã±ãããå¾å¾©ãããã³ã«ææ°é¢æ°çã«å¢å ãã¦ããï¼
ãããï¼ä¸¦åã«TCPã³ãã¯ã·ã§ã³ãå¼µã£ã¦ãã¾ãã¨ï¼ããããã®ã³ãã¯ã·ã§ã³ã«ãããã¦ã£ã³ãã¦ãµã¤ãºã大ãããªãåã«ãã¼ã¿ã®éä¿¡ãå®äºãã¦ãã¾ãï¼
è¦ããã«ï¼åä¸ã®TCPã³ãã¯ã·ã§ã³ã«ããï¼ã¦ã£ã³ãã¦ãµã¤ãºã大ããç¶æ ã§ãã¼ã¿éä¿¡ããã»ãããã±ããã®å¾å¾©ãå°ãªãã¦æ¸ããï¼ä¸¦åã«TCPã³ãã¯ã·ã§ã³ãå¼µãã¨ï¼ã¦ã£ã³ãã¦ãµã¤ãºãå°ããã¾ã¾ã®ç¶æ ã§ãã¼ã¿éä¿¡ããªããã°ãªããï¼ãã±ããã®å¾å¾©ãå¢ãã¦ãã¾ãï¼â¢ æå¾ã®"connection rationing by the client"ã¯ï¼ããããããªããã©ã¯ã©ã¤ã¢ã³ããã³ãã¯ã·ã§ã³ãå¼µãéãã¦ãµã¼ãã«è¿·æããããªãããã«åææ¥ç¶æ°ãå¶éãã¦ç®¡çããªããã°ãªããªãã¨ããããããã¨ãªæ°ãããï¼
HTTP 1.1
ãããã¯ï¼HTTP 1.0ããåé¡ã«ãªã£ã¦ãã¦ï¼HTTP 1.1ã§ã®è§£æ±ºçã¯ä»¥ä¸ã®ã¨ããã§ããï¼
HTTP 1.0ã®Keep Alive (HTTP/1.1: Connectionsã«ããï¼ä¸åº¦ç¢ºç«ããTCPã³ãã¯ã·ã§ã³ãã¯ãã¼ãºããã«ä½¿ãã¾ããï¼ããã§â ï¼â¡ãããç¨åº¦è§£æ±ºã§ããï¼
Keep Aliveãããåä¸ã®TCPã³ãã¯ã·ã§ã³ã«ããã¦ï¼HTTPã¯åºæ¬çã«ã¬ã¹ãã³ã¹ãè¿ã£ã¦ããã¾ã§æ¬¡ã®ãªã¯ã¨ã¹ããæããããªãï¼æ°ããTCPã³ãã¯ã·ã§ã³ã確ç«ããã°ãã¡ãããªã¯ã¨ã¹ãã¯æããããï¼ï¼åæã«è¤æ°ã®ãªã¯ã¨ã¹ããæããããã«ï¼åããHTTP 1.1ã®pipelining( HTTP/1.1: Connections ã使ãï¼
Keep Aliveã¨pipeliningã«ã¤ãã¦ã¯ä¸è¨ã®è¨äºã®èª¬æãããããããï¼
pipeliningã®åé¡ç¹
The problem with pipelining, it says, is that even when multiple requests are pipelined into one HTTP connection, the entire connection remains first-in-first-out, so a lost packet or delay in processing one request results in the delay of every subsequent request in the pipeline. LWN.netã®è¨äº Reducing HTTP latency with SPDY [LWN.net] ããå¼ç¨
èªåãªãã«è§£éããã¨ï¼pipeliningã¯ï¼HTTPã¬ã¹ãã³ã¹ã®åä¿¡ã«å¤±æã¾ãã¯åä¿¡ãé 延ããã¨ï¼pipelineä¸ã®ä»ã®HTTPãªã¯ã¨ã¹ããã¬ã¹ãã³ã¹ã®éåä¿¡ã失æã¾ãã¯é 延ãã¦ãã¾ãã¨ãããã¨ã ã¨æãï¼
ä¾ãã°ããã¬ã¹ãã³ã¹ã®åä¿¡ï¼å³ã§ã¯â¡ï¼ã«å¤±æããã¨ï¼TCPã³ãã¯ã·ã§ã³ãæ¥ç¶ç¢ºç«ãããç´ããªã©ã®å¯¾å¦ãå¿
è¦ã§ããï¼
ã¾ãï¼ãã±ãããã¹ãªã©ã®åå ã«ããâ¡ã®åä¿¡ãé
延ããã¨â¢ï¼â£ã®åä¿¡ãé
延ãã¦ãã¾ãï¼
ã¬ã¹ãã³ã¹ã®åä¿¡ã®å¤±æã«ã¤ãã¦ã¯ï¼ãªã«ãæåããæ¥ç¶ã®ç¢ºç«ãããç´ããªãã¦ã失æããã¬ã¹ãã³ã¹ã ããµã¼ããåéããã°ããã®ã§ã¯ã¨æã£ãï¼
ãããï¼åéã®ããã«ã¯ï¼ãµã¼ããã¯ã©ã¤ã¢ã³ãã®å信失æãæ¤ç¥ããªããã°ãªããï¼æ¤ç¥ããä»çµã¿ï¼TCPã®ç¢ºèªå¿ççãªãã®ï¼ãå®è£
ããªããã°ãªããªãï¼
ã¬ã¹ãã³ã¹ã®åä¿¡ã®é 延ã«ã¤ãã¦ã¯ï¼â¡ãç¡è¦ãã¦â¢ï¼â£ãå ã«åä¿¡ãããããªãã®ã¨æã£ããã©ï¼HTTP 1.1ã®ä»æ§ã§ã¯â ..â£ã®é ã«ã¬ã¹ãã³ã¹ãéä¿¡ããªããã°ãªããªãã¨ããå¶ç´ãããï¼
A server MUST send its responses to those requests in the same order that the requests were received.
RFC 2616 (HTTP/1.1) 8.1.2.2 Pipelining http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html#sec8.1.2.2 ããå¼ç¨
ããã§SPDY
SPDYã§ã¯TCPã®ä¸ã«TCPã®ãããªã¹ãã¼ããã«ãªãããã³ã«å±¤ã追å ãã¦ï¼pipeliningã®åé¡ç¹ã§ãã
- å信失ææã«TCPã³ãã¯ã·ã§ã³ãå確ç«ãã
- ãªã¯ã¨ã¹ãã®é çªã¨åãé çªã§å¯¾å¿ããã¬ã¹ãã³ã¹ãéä¿¡ããªããã°ãªããªã
ã解決ãã¦ããï¼
ï¼åºå ¸ï¼SPDY: SPDY: An experimental protocol for a faster web - The Chromium Projectsï¼
åè
ã»å¾è
ã¨ãã«ï¼åä¸ã®TCPã³ãã¯ã·ã§ã³ã®ä¸ã«è¤æ°ã®è«ççãªã¹ããªã¼ã ãæ§ç¯ãããã¨ã«ãã解決ããï¼
ããã§ããã¹ããªã¼ã ã¯HTTPãªã¯ã¨ã¹ãã¨å¯¾å¿ããã¬ã¹ãã³ã¹ã®ãã¢ã§ããï¼ï¼SPDYãå®ç¾©ããã¹ããªã¼ã ã¯ããåºç¾©ãªå®ç¾©ãããã¦ããï¼
ããã«ããï¼ãã¨ãåä¿¡ã«å¤±æãã¦ãã¹ããªã¼ã ãåããã ãã§ï¼TCPã³ãã¯ã·ã§ã³ãå確ç«ããå¿ è¦ããªãï¼
ããã«ï¼åã ã®ã¹ããªã¼ã ã¯ç¬ç«ãã¦ããã®ã§ï¼ãªã¯ã¨ã¹ãã®é çªã¨åãé çªã«ã¬ã¹ãã³ã¹ãè¿ããªããã°ãªããªãã¨ããå¶ç´ã¯ãªãï¼
The fully multiplexed approach taken by SPDY, however, allows multiple HTTP requests and responses to be interleaved in any order, more efficiently filling the TCP channel. A lost packet would still be retransmitted, but other requests could continue to be filled without pausing to wait for it. A request that requires server-side processing would form a bottleneck in an HTTP pipeline, but SPDY can continue to answer requests for static data over the channel while the server works on the slower request. LWN.netã®è¨äº Reducing HTTP latency with SPDY [LWN.net] ããå¼ç¨
è«ççãªã¹ããªã¼ã ã®æ§ç¯æ¹æ³
ã§ã¯è«ççãªã¹ããªã¼ã ãã©ãã®ããã«å®ç¾ãã¦ããã®ãï¼
SPDY defines 3 control frames to manage the lifecycle of a stream:
- SYN_STREAM - Open a new stream
- SYN_REPLY - Remote acknowledgement of a new, open stream
- RST_STREAM - Close a stream
SPDY Protocol Draft 3 - 2.3.1 Stream frames
SPDY ã§ã¯ã¹ããªã¼ã ã®ã©ã¤ããµã¤ã¯ã«ã管çããããã«3ã¤ã®ã³ã³ããã¼ã«ãã¬ã¼ã ãå®ç¾©ãã¾ãã SYN_STREAM - æ°ããã¹ããªã¼ã ã®éå§ SYN_REPLY - æ°ããéå§ããã¹ããªã¼ã ã®ãªã¢ã¼ãæ¿èª RST_STREAM - ã¹ããªã¼ã ã®çµäº
ã¹ããªã¼ã å¶å¾¡ã®ããã®ãã¼ã¿æ¬ä½ãå«ã¾ãªãå°ç¨ã®ã³ã³ããã¼ã«ãã¬ã¼ã ãç¨ãããã¨ã«ããï¼åä¸TCPã³ãã¯ã·ã§ã³ä¸ã«ã¹ããªã¼ã ã¨ããæ¦å¿µãå°å ¥ãã¦ããï¼ããããã®ã³ã³ããã¼ã«ãã¬ã¼ã ã¯Stream-IDããã¡ï¼ãã®IDã«ããåã¹ããªã¼ã ãåºå¥ããï¼
ãã¼ã¿æ¬ä½ã¯ï¼ãã¼ã¿ãã¬ã¼ã ã¨ãã¦éä¿¡ããï¼
SPDYã«ãããHTTPãªã¯ã¨ã¹ãã¨ã¬ã¹ãã³ã¹
ä¸è¨ã³ã³ããã¼ã«ãã¬ã¼ã ã¨ãã¼ã¿ãã¬ã¼ã ãç¨ãã¦ã©ã®ããã«ãã¦HTTPãªã¯ã¨ã¹ãã¨ã¬ã¹ãã³ã¹ã表ç¾ããã®ãï¼
大éæã«ã¾ã¨ããã¨ï¼ãªã¯ã¨ã¹ããSYN_STREAMãã¬ã¼ã ã«ç¸å½ãï¼ã¬ã¹ãã³ã¹ãSYN_REPLYã«ç¸å½ããï¼ ããããbodyãããå ´åã¯SYN_STREAM/SYN_REPLYãã¬ã¼ã ãéä¿¡å¾ã«ãã¼ã¿ãã¬ã¼ã ãéä¿¡ããï¼
詳細ã¯ä¸è¨åç §ï¼
ãªã¯ã¨ã¹ã
For requests which do not contain a body, the SYN_STREAM frame MUST set the FLAG_FIN, indicating that the client intends to send no further data on this stream. For requests which do contain a body, the SYN_STREAM will not contain the FLAG_FIN, and the body will follow the SYN_STREAM in a series of DATA frames. The last DATA frame will set the FLAG_FIN to indicate the end of the body.
SPDY Protocol Draft 3 - 3.2.1 Request
body ãå«ã¾ãªããªã¯ã¨ã¹ãã§ã¯ãã¯ã©ã¤ã¢ã³ããã¹ããªã¼ã ã«è¿½å ã®ãã¼ã¿ãéä¿¡ããªããã¨ã示ãããã«ãSYN_STREAM ãã¬ã¼ã ã« FLAG_FIN ãè¨å®ããªããã°ãªãã¾ãããbody ãå«ããªã¯ã¨ã¹ãã§ã¯ãSYN_STREAM 㯠FLAG_FIN ãå«ã¾ããbody 㯠SYN_STREAM ã®ãã¨ã«ç¶ãä¸é£ã® DATA ãã¬ã¼ã ã«å«ã¾ãã¾ããæå¾ã® DATA ãã¬ã¼ã ã«ã¯ãbody ã®çµããã§ãããã¨ã示ãããã® FLAG_FIN ãè¨å®ããã¾ãã
ã¬ã¹ãã³ã¹
The server responds to a client request with a SYN_REPLY frame. Symmetric to the client's upload stream, server will send data after the SYN_REPLY frame via a series of DATA frames, and the last data frame will contain the FLAG_FIN to indicate successful end-of-stream. If a response (like a 202 or 204 response) contains no body, the SYN_REPLY frame may contain the FLAG_FIN flag to indicate no further data will be sent on the stream.
SPDY Protocol Draft 3 - 3.2.2 Response
ãµã¼ãã¼ã¯ãã¯ã©ã¤ã¢ã³ãã®ãªã¯ã¨ã¹ãã« SYN_REPLY ãã¬ã¼ã ã§å¿ãã¾ããã¯ã©ã¤ã¢ã³ãã®ã¢ãããã¼ãã¹ããªã¼ã ã¨ã¯å¯¾è±¡çã«ããµã¼ãã¼ã¯ SYN_REPLY ãã¬ã¼ã å¾ã®ä¸é£ã® DATA ãã¬ã¼ã ã«ãããã¼ã¿ãéä¿¡ããæå¾ã® DATA ãã¬ã¼ã ã«ã¯ã¹ããªã¼ã ãæ£ããçµäºãããã¨ã示ã FLAG_FIN ãå«ã¾ãã¾ãã(202ã204ã¬ã¹ãã³ã¹ã¨ãã£ã) body ãå«ã¾ãªãã¬ã¹ãã³ã¹ã®å ´åãSYN_REPLY ãã¬ã¼ã ã«ã¯ããã®ã¹ããªã¼ã ã§ã¯ãã以ä¸éããããã¼ã¿ããªããã¨ã示ã FLAG_FIN ãè¨å®ãããããããã¾ããã
éæ
SPDYã®TCPã³ãã¯ã·ã§ã³ã1ã¤ã«ã¾ã¨ããã¨ãã観ç¹ã®ã¿ãåãåºãã¦èª¿ã¹ãï¼
並åã«TCPã³ãã¯ã·ã§ã³ãå¼µããã¨ã®åé¡ã¯åãããã£ã¦ï¼pipeliningã¨ãããã¦ã¿ããã©ï¼æ¬æ¥ã¹ãã¼ãã¬ã¹ãªHTTPã®ã¬ã¤ã¤ã§ã¹ãã¼ããã«ãªãã¨ããããã¨ãã¦ãã¾ããããªãããï¼SPDYãç»å ´ããã¿ãããªæãã§ã¯ï¼
SPDYã®ç¹ã«ãã¬ã¼ãã³ã°å±¤ã«ã¤ãã¦ã¯ããå°ãæºä¸ã·ãã¥ã¬ã¼ã·ã§ã³ãç¹°ãè¿ããªãã¨ããç解ã§ããªãããï¼
SPDYã¯HTTPã®ä¸ã§HTTPããããã¨ãã¦ããã¨ããè¨èããããã©ï¼å人çã«ã¯TCPã®ä¸ã§TCPããããã¨ãã¦ããã¤ã¡ã¼ã¸ãããï¼
è¿½è¨ æå¾ã®HTTPã®ä¸ã§HTTPã¨ããã®ã¯ä»¥ä¸ã®è¨äºããã®å¼ç¨ï¼ Webはインターネットになった - naoyaのはてなダイアリー