http 304 - not modified

37
HTTP 304 [ Not Modified ]

Upload: ricardo-dos-santos-pereira

Post on 25-Jan-2017

118 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: HTTP 304 - Not Modified

HTTP 304[ Not Modified ]

Page 2: HTTP 304 - Not Modified

HTTP 304

Page 3: HTTP 304 - Not Modified

HTTP 304

#QuienSoy Ricardo Pereira @Ricard0Per www.ricardopereira.es

Arquitecto PHP Senior Administrador de Sistemas

Page 4: HTTP 304 - Not Modified

Do You SpeakPORTUÑOL?

Page 5: HTTP 304 - Not Modified

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

Page 6: HTTP 304 - Not Modified

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

Page 7: HTTP 304 - Not Modified

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

Page 8: HTTP 304 - Not Modified

CACHÉ[ To The Rescue ]

HTTP 304

Page 9: HTTP 304 - Not Modified

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

Page 10: HTTP 304 - Not Modified

CADUCIDAD[ Modelo de ]

HTTP 304

Page 11: HTTP 304 - Not Modified

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

Page 12: HTTP 304 - Not Modified

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

Page 13: HTTP 304 - Not Modified

VALIDACIÓN[ Modelo de ]

HTTP 304

Page 14: HTTP 304 - Not Modified

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

Page 15: HTTP 304 - Not Modified

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

Page 16: HTTP 304 - Not Modified

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

Page 17: HTTP 304 - Not Modified

HTTP CACHÉTIPOS DE

HTTP 304

Page 18: HTTP 304 - Not Modified

HTTP 304

Client Cache

ResourceCache

beonprice.com

Page 19: HTTP 304 - Not Modified

HTTP 304

Proxy Cache

ResourceCache

Proxy Cache

beonprice.com

Corporate Domain or ISP

Page 20: HTTP 304 - Not Modified

HTTP 304

Gateway Cache

ResourceCache

Gateway Cache beonprice.com

Datacenter

Page 21: HTTP 304 - Not Modified

GATEWAY CACHE

HTTP 304

Page 22: HTTP 304 - Not Modified

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

Page 23: HTTP 304 - Not Modified

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

Page 24: HTTP 304 - Not Modified

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

Page 25: HTTP 304 - Not Modified

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

Page 26: HTTP 304 - Not Modified

HTTP 304

[ No iba hablar de ]

Page 27: HTTP 304 - Not Modified

HTTP 304

1001M10M100M

Page 28: HTTP 304 - Not Modified

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

Page 29: HTTP 304 - Not Modified

ESI[ To The Rescue ]

HTTP 304

Page 30: HTTP 304 - Not Modified

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>

Page 31: HTTP 304 - Not Modified

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

Page 32: HTTP 304 - Not Modified

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

Page 33: HTTP 304 - Not Modified

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

Page 34: HTTP 304 - Not Modified

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

Page 35: HTTP 304 - Not Modified

HTTP 304

100M

Page 36: HTTP 304 - Not Modified

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

Page 37: HTTP 304 - Not Modified

GRACIAS[ Preguntas ]

HTTP 304