http 304 - not modified
TRANSCRIPT
HTTP 304[ Not Modified ]
HTTP 304
HTTP 304
#QuienSoy Ricardo Pereira @Ricard0Per www.ricardopereira.es
Arquitecto PHP Senior Administrador de Sistemas
Do You SpeakPORTUÑOL?
HTTP / 1.0 - Mayo 1996https://www.ietf.org/rfc/rfc1945.txt
HTTP / 1.1 - Junio 1999https://www.ietf.org/rfc/rfc2616.txt
Mayo 2015https://www.ietf.org/rfc/rfc7540.txt
HTTP 304
HTTP 304
Petición HTTP
ClienteHTTP
ServidorHTTP
GET /webpage HTTP/1.1Host: beonprice.comUser-Agent: FastBrowser/2.1Cache-Control: max-age=0If-Modified-Since: Fri, 01 Jan 2016If-None-Match: abcdef123456789Accept: text/html
HTTP/1.1 200 OKContent-Type: text/htmlContent-Length: 234Cache-Control: max-age=5Last-Modified: Sat, 02 Jan 2016ETag: abc123456789Vary: Accept-Encoding
GET /webpage HTTP/1.1Host: beonprice.comUser-Agent: FastBrowser/2.1Cache-Control: max-age=0If-Modified-Since: Fri, 01 Jan 2016If-None-Match: abcdef123456789Accept: text/html
HTTP/1.1 200 OKContent-Type: text/htmlContent-Length: 234Cache-Control: max-age=5Last-Modified: Sat, 02 Jan 2016ETag: abc123456789Vary: Accept-Encoding
HTTP 304
Peticiones HTTPUna página web en 2015 tiene de media unas 100 peticiones HTTP:
* 2Mb tamaño* 56 imágenes* 20 JavaScript* 7 CSS* 3 fuentes
REF.: http://www.sitepoint.com/2mb-web-pages-whos-blame/
Esta cantidad de peticiones implica determinadas desventajas:
* Obtener un elemento es lento y caro* Muchos recorridos de ida y vuelta* Gran tamaño de las respuestas* Costes de datos para el visitante* Tiempos de respuestas elevados
CACHÉ[ To The Rescue ]
HTTP 304
HTTP 304
Modelos de CachéDe caducidad
Expires( HTTP/1.0 )
Cache-Control( HTTP/1.1 )
De validación
If-None-MatchETag
If-Modified-SinceLast-Modified
CADUCIDAD[ Modelo de ]
HTTP 304
HTTP 304
Expires ( HTTP/1.0 )
Nav
egad
or
Cac
hé N
aveg
ador
Serv
idor
HTT
P
GET /webpage HTTP/1.0Host: beonprice.com
GET /webpage HTTP/1.0Host: beonprice.com
HTTP/1.0 200 OKExpires: Sat, 02 Jan 2016
HTTP/1.0 200 OKExpires: Sat, 02 Jan 2016
GET /webpage HTTP/1.0Host: beonprice.com
HTTP/1.0 304 OKExpires: Sat, 02 Jan 2016
Fri, 01 Jan 2016
Fri, 01 Jan 2016
..:: NOTA ::..No hay petición al servidor
HTTP 304
Cache-Control ( HTTP/1.1 )
Nav
egad
or
Cac
hé N
aveg
ador
Serv
idor
HTT
P
GET /webpage HTTP/1.1Host: beonprice.com
GET /webpage HTTP/1.1Host: beonprice.com
HTTP/1.1 200 OKCache-Control: max-age=60
GET /webpage HTTP/1.1Host: beonprice.com
12:00:00
12:00:30
..:: NOTA ::..No hay petición al servidor
HTTP/1.1 200 OKCache-Control: max-age=60
HTTP/1.1 304 OKCache-Control: max-age=60Age: 30
VALIDACIÓN[ Modelo de ]
HTTP 304
HTTP 304
If-None-Match / ETag
Nav
egad
or
Cac
hé N
aveg
ador
Serv
idor
HTT
P
GET /webpage HTTP/1.1Host: beonprice.com
GET /webpage HTTP/1.1Host: beonprice.com
HTTP/1.1 200 OKETag: abcd1234
HTTP/1.1 200 OKETag: abcd1234
GET /webpage HTTP/1.1Host: beonprice.comIf-None-Match: abcd1234
HTTP/1.1 304 OKETag: abcd1234
GET /webpage HTTP/1.1Host: beonprice.comIf-None-Match: abcd1234
HTTP/1.1 304 OKETag: abcd1234
HTTP 304
If-Modified-Since / Last-Modified
Nav
egad
or
Cac
hé N
aveg
ador
Serv
idor
HTT
P
GET /webpage HTTP/1.1Host: beonprice.com
GET /webpage HTTP/1.1Host: beonprice.com
HTTP/1.1 200 OKLast-Modified: Fri, 01 Jan 2016
HTTP/1.1 200 OKLast-Modified: Fri, 01 Jan 2016
GET /webpage HTTP/1.1Host: beonprice.comIf-Modified-Since: Fri, 01 Jan 2016
HTTP/1.1 304 OKLast-Modified: Fri, 01 Jan 2016
GET /webpage HTTP/1.1Host: beonprice.comIf-Modified-Since: Fri, 01 Jan 2016
HTTP/1.1 304 OKLast-Modified: Fri, 01 Jan 2016
HTTP 304
Puntos Relevantes
De caducidadEscalan mejor
Menos peticiones al servidorTiempos de respuesta más rápidos
Se recomienda en archivos estáticos
De validaciónAhorra tráfico de datos
Respuestas 304 sin contenidoContenido siempre actualizado
Se recomienda en páginas dinámicos
Se puede combinar las cabeceras que se deseeLas de caducidad ganan sobre las de validación
El objetivo es no generar la misma respuesta dos veces
HTTP CACHÉTIPOS DE
HTTP 304
HTTP 304
Client Cache
ResourceCache
beonprice.com
HTTP 304
Proxy Cache
ResourceCache
Proxy Cache
beonprice.com
Corporate Domain or ISP
HTTP 304
Gateway Cache
ResourceCache
Gateway Cache beonprice.com
Datacenter
GATEWAY CACHE
HTTP 304
HTTP 304
Sin Gateway CacheInconvenientes:
* Generar páginas dinámicas es lento y costoso
* Tienen de servir contenido estático de forma constante
* Congestionamientos de red
* Tiempos de respuesta altos
HTTP 304
Con Gateway CacheVentajas:
* Contenido estático se sirve muy rápido y con pocos recursos
* Gateway sirve 99% del contenido estático y servers solo contenido dinámico
* Tiempos de respuesta bajos
* La misma carga, menos servers
Solo si gateway no tiene caché
HTTP 304
Cache-Control ( HTTP/1.1 )
Nav
egad
or
Cac
hé N
aveg
ador
Serv
idor
HTT
P
GET /webpage HTTP/1.1Host: beonprice.com
12:00:00 GET /webpage HTTP/1.1Host: beonprice.com
GET /webpage HTTP/1.1Host: beonprice.com
Gat
eway
Cac
he
HTTP/1.1 200 OKCache-Control: max-age=60
HTTP/1.1 200 OKCache-Control: max-age=60
HTTP/1.1 200 OKCache-Control: max-age=60
HTTP/1.1 304 OKCache-Control: max-age=60Age: 30
..:: NOTA ::..No hay petición al gateway
GET /webpage HTTP/1.1Host: beonprice.com
12:00:30
..:: NOTA ::..No hay petición al servidor
HTTP 304
If-None-Match / ETag
Nav
egad
or
Cac
hé N
aveg
ador
Serv
idor
HTT
P
GET /webpage HTTP/1.1Host: beonprice.com
GET /webpage HTTP/1.1Host: beonprice.com
GET /webpage HTTP/1.1Host: beonprice.com
Gat
eway
Cac
he
HTTP/1.1 200 OKETag: abcd1234
HTTP/1.1 200 OKETag: abcd1234
HTTP/1.1 200 OKETag: abcd1234
HTTP/1.1 304 OKETag: abcd1234
GET /webpage HTTP/1.1Host: beonprice.comIf-None-Match: abcd1234
GET /webpage HTTP/1.1Host: beonprice.comIf-None-Match: abcd1234
GET /webpage HTTP/1.1Host: beonprice.comIf-None-Match: abcd1234
HTTP/1.1 304 OKETag: abcd1234
HTTP/1.1 304 OKETag: abcd1234
GET /webpage HTTP/1.1Host: beonprice.comIf-None-Match: abcd1234
HTTP/1.1 200 OKETag: efgh5678
GET /webpage HTTP/1.1Host: beonprice.comIf-None-Match: abcd1234
GET /webpage HTTP/1.1Host: beonprice.comIf-None-Match: abcd1234
HTTP/1.1 200 OKETag: efgh5678
HTTP/1.1 200 OKETag: efgh5678
HTTP 304
[ No iba hablar de ]
HTTP 304
1001M10M100M
HTTP 304
Problemas y más Problemas* Congestión de la red entre servers del datacenter
* Página muy dinámica y de coste elevado
* Sólo se puede almacenar páginas web enteras en caché
* Tiempos de caché por página muy pequeños para mantener frescura del bloque central (10 segundos)
* No es posible renderizar bloques en otros servers
ESI[ To The Rescue ]
HTTP 304
Edge Side Includes 1.0 - Agosto 2001https://www.w3.org/TR/esi-lang
HTTP 304
<html><body>
<div id="pagelet_composer"><esi:include src="/composer" />
</div><div id="topnews_main_stream">
<esi:include src="/topnews" /> </div><div class="home_right_column">
<esi:include src="/rightCol" /> </div><div id="pagelet_rhc_footer">
<esi:include src="/footer" /> </div>
</body></html>
HTTP 304
Petición ESI (0s)
Clie
nte
HTT
P
Gat
eway
Cac
he
Serv
idor
HTT
P
ESI P
roce
ssor
facebook.com/webpage
200 - Cache-Control: max-age: 10
/webpage /webpage
200 - Cache-Control: max-age: 10200 - Cache-Control: max-age: 10
/composer
200 - Cache-Control: s-maxage: 2592000
/composer
200 - Cache-Control: s-maxage: 2592000
/topnews
200 - Cache-Control: s-maxage: 10
/topnews
200 - Cache-Control: s-maxage: 10
/rightCol
200 - Cache-Control: s-maxage: 60
/rightCol
200 - Cache-Control: s-maxage: 60
/footer
200 - Cache-Control: s-maxage: 2592000
/footer
200 - Cache-Control: s-maxage: 2592000
HTTP 304
Petición ESI (+5s)
Clie
nte
HTT
P
Gat
eway
Cac
he
Serv
idor
HTT
P
ESI P
roce
ssor
facebook.com/webpage
304 - Age: 5
..:: NOTA ::..No hay petición al servidor
..:: NOTA ::..Procesador ESI sin carga
HTTP 304
Petición ESI (+11s)
Clie
nte
HTT
P
Gat
eway
Cac
he
Serv
idor
HTT
P
ESI P
roce
ssor
facebook.com/webpage
200 - Cache-Control: max-age: 10
/webpage /webpage
200 - Cache-Control: max-age: 10200 - Cache-Control: max-age: 10
/composer
304 - Age: 10
/topnews
200 - Cache-Control: s-maxage: 10
/topnews
200 - Cache-Control: s-maxage: 10
/rightCol
304 - Age: 10
/footer
304 - Age: 10
HTTP 304
Petición ESI (+61s)
Clie
nte
HTT
P
Gat
eway
Cac
he
Serv
idor
HTT
P
ESI P
roce
ssor
facebook.com/webpage
200 - Cache-Control: max-age: 10
/webpage /webpage
200 - Cache-Control: max-age: 10200 - Cache-Control: max-age: 10
/composer
304 - Age: 60
/topnews
200 - Cache-Control: s-maxage: 10
/topnews
200 - Cache-Control: s-maxage: 10
/rightCol
200 - Cache-Control: s-maxage: 60
/rightCol
200 - Cache-Control: s-maxage: 60
/footer
304 - Age: 60
HTTP 304
100M
HTTP 304
Ahorro de Datos en el Footer
1.591.000.000 usuarios en 201512.6 páginas vistas por usuario
Footer actual ocupa 1.7KBCódigo ESI ocupa 0.5KB
REF.:http://www.alexa.com/siteinfo/facebook.comhttp://expandedramblings.com/index.php/by-the-numbers-17-amazing-facebook-stats/
Tráfico dentro del datacenter:Footer sin ESI: 34.1TBFooter con ESI: 10TB
Ahorro: 24.1TB
NOTA: Ahorro por cada nivel de infraestructura
GRACIAS[ Preguntas ]
HTTP 304