36
CDN & Cloud Junho Choi <[email protected]> CDNetworks h7p://www.cdnetworks.com rev. 3

CDN and Cloud - PHPFest 2011

Embed Size (px)

DESCRIPTION

Presented in PHPFest 2011, Seoul, Korea Content Delivery Network How to set cacheability object in PHP Cloud Performance & CDN (very short)

Citation preview

Page 1: CDN and Cloud - PHPFest 2011

CDN  &  Cloud Junho  Choi  <[email protected]>  CDNetworks  h7p://www.cdnetworks.com  rev.  3

Page 2: CDN and Cloud - PHPFest 2011

Who  am  I?

  Junho  Choi  (최준호)    CTO/APAC,  VP  of  Engineering  |  CDNetworks  hAp://www.cdnetworks.com    FreeBSD  CommiAer(ports)  ([email protected],  2001-­‐2010)    Korea  FreeBSD  Users  Group  hAp://www.kr.freebsd.org  since  1999    TwiAer:  junhochoi  

PHPFest  2011   2  

Page 3: CDN and Cloud - PHPFest 2011

Contents

  CDN  –  what  problem  to  solve    Technology  in  CDN    How  to  uZlize  CDN/Cache  using  PHP    Cloud  CompuZng  &  CDN

PHPFest  2011   3  

Page 4: CDN and Cloud - PHPFest 2011

A  typical  web  site  

  You  built  a  fancy  web  site!    As  your  website  is  ge_ng  popular,  you  are  ge_ng  more  and  more  traffic.    Your  website  will  be  slow  when  more  users  visit.    Your  website  will  be  slow  when  users  from  other  countries  visit.    Your  website  can  be  down  due  to  hardware  failure,  network  failure.    Your  website  will  be  down  when  there  is  a  spike  of  traffic  because  your  we

bsite  is  suddenly  popular  on  famous  news  site,  twiAer,  slashdot,  facebook  etc.  

  Your  website  is  not  scalable  when  you  want  to  expand  more    You  want  to  have  a  streaming  video  on  your  website  but  don’t  want  to  bu

y  a  license  for  commercial  streaming  soluZon  such  as  Flash  Media  or  Windows  Media.  

  …

PHPFest  2011   4  

Page 5: CDN and Cloud - PHPFest 2011

Content  Delivery  Network

  Problem  to  solve  •  Network  Distance  •  Reliability  •  Scalability  

PHPFest  2011   5  

Page 6: CDN and Cloud - PHPFest 2011

Problem  to  Solve  –  Network  Distance

EMEA HQ

End-user

First  Mile  Same  Data  Center  

Same  ISP  Low  latency  

High  Bandwidth

Middle  Mile  Bad Routing

Network Failure Long distance

Last  Mile  Same  LocaZon  

Same  ISP  Low  latency  

Low  Bandwidth  

  Middle  Mile  Problem

“Origin  Server”  Customer’s  web  site

PHPFest  2011   6  

Page 7: CDN and Cloud - PHPFest 2011

Problem  to  Solve  –  Network  Distance

EMEA HQ

End-user

First  Mile Middle  Mile Last  Mile

Place  edge  (caching  or  mirroring)  server  on  nearest  locaZon  to  end  user

PHPFest  2011   7  

“Origin  Server”  Customer’s  web  site

“Edge  Server”  CDN  Cache

Page 8: CDN and Cloud - PHPFest 2011

Problem  to  Solve  –  Reliability

EMEA HQ

End-user

First  Mile Middle  Mile Last  Mile

SZll  able  to  access  on  CDN  Edge  server

PHPFest  2011   8  

Page 9: CDN and Cloud - PHPFest 2011

Problem  to  Solve  –  Scalability

EMEA HQ

End-user

First  Mile Middle  Mile Last  Mile

Put  more  edge  servers  instead  of  customer  Content  is  cached;  no  increase  on  origin  server  traffic

PHPFest  2011   9  

Page 10: CDN and Cloud - PHPFest 2011

History

  Late  90’s,  SandPiper  was  first  CDN  company  and  Akamai  made  it  a  successful  market  around  1999~2000  

  In  Korea,  CDN  service  started  around  2000  by  a  few  startups  including  CDNetworks  

  Now  CDN  provider  and  ISP  are  compeZng  each  other  

PHPFest  2011   10  

Page 11: CDN and Cloud - PHPFest 2011

CDN  Services

  HTTP/HTTPS  Delivery  •  Web  Caching  Model  •  Mirroring  Model  

  Streaming  •  Windows  Media  Streaming  (VOD,  Live)  •  Flash  Media  Streaming  (VOD,  Live)  •  Caching  and  mirroring  model  

  AddiZonal  Service  •  Storage  as  a  origin  •  P2P  delivery  (aka  grid  delivery)  

  Pay  for  usage:  traffic  (Gbytes)  or  bandwidth  (Gbit/sec)    

PHPFest  2011   11  

Page 12: CDN and Cloud - PHPFest 2011

In  real  world

  Websites  (HTTP/HTTPS)  •  E-­‐Commerce  

−  A  large  number  of  images  −  Accessing  from  many  users  

•  Social  commerce  −  A  few  number  of  images  −  Many  users  at  the  same  Zme  –  high  spike  

•  Web  site  with  global  audience    Streaming  

•  E-­‐learning  Contents  for  students  •  Live  event  for  a  big  sports  game  •  User  Generated  Contents  

  Online  Gaming  •  Launching  a  new  game  •  Release  update  or  patch  

PHPFest  2011   12  

Page 13: CDN and Cloud - PHPFest 2011

Traffic  PaNern  of  a  web  site

Website  only  can  handle  this  (limited  by  bandwidth,  server,  etc)

PHPFest  2011   13  

As  your  website  ge_ng  popular,  there  will  be  unexpected  traffic  paAerns  

Page 14: CDN and Cloud - PHPFest 2011

High  Level  Architecture

GSLB

Management

Log  Processing

Operator  Portal

Cache

Storage Streaming

Monitoring

Router

Cache

Storage Cache

Monitoring

Router

Cache

Storage Cache

Monitoring

Router

Customer  Portal

PHPFest  2011   14  

Data  Center,  or  PoP  (Point  Of  Presence)

Admin  PoP  or  Control  Center

Page 15: CDN and Cloud - PHPFest 2011

Main  Technology

  GSLB  •  Global  Server  Load  Balancing  •  Typically  DNS  server  which  do  load  balancing  between  mulZple  servers  and  ne

tworks  •  Most  CDN  provider  use  GSLB  

  Cache  •  Web  Cache  for  HTTP/HTTPS  •  Cache  objects  in  storage  •  When  end  user  access  the  contents,  it  will  serve  objects  from  cache  if  possible  •  Controlled  by  several  configuraZon  parameter  and  HTTP  response  from  origin  

  Portal  •  Large  data  processing  –  processing  daily  logs  •  Controllable  via  UI  for  operators

PHPFest  2011   15  

Page 16: CDN and Cloud - PHPFest 2011

CDN  in  website

hAp://www.kr.cdnetworks.com/index.php

hAp://www.kr.cdnetworks.com/images/common/main_logo.gif

PHPFest  2011   16  

Typical  web  site  has  a  lot  of  objects  Inside  –  images,  flash,  video,  js,  css  etc

Page 17: CDN and Cloud - PHPFest 2011

DNS  lookup  example

%  dig  www.kr.cdnetworks.com    ;;  QUESTION  SECTION:  ;www.kr.cdnetworks.com.    IN  A    ;;  ANSWER  SECTION:  www.kr.cdnetworks.com.  3420  IN  CNAME  www.kr.cdnetworks.com.cdngc.net.  www.kr.cdnetworks.com.cdngc.net.  20  IN  A  61.110.226.28  www.kr.cdnetworks.com.cdngc.net.  20  IN  A  61.110.226.15    ;;  AUTHORITY  SECTION:  cdngc.net.    68200  IN  NS  ns2.panthercdn.com.  cdngc.net.    68200  IN  NS  ns1.panthercdn.com.    ;;  ADDITIONAL  SECTION:  ns1.panthercdn.com.  64021  IN  A  205.252.255.11  ns2.panthercdn.com.  48212  IN  A  67.72.21.11

PHPFest  2011   17  

Page 18: CDN and Cloud - PHPFest 2011

DNS  lookup  example

Root  DNS  (.com,  .net)  

DNS  for  cdnetworks.com  

“What’s  IP  address  of  www.kr.cdnetworks.com?”  

Resolver  Local  DNS  End  User  

Browser  

“What’s  DNS  Server  IP  address  of  cdnetworks.com?”  

“www.kr.cdnetworks.com  is  (CNAME)          www.kr.cdnetworks.cdngc.net”  

PHPFest  2011   18  

Page 19: CDN and Cloud - PHPFest 2011

DNS  lookup  example

Root  DNS  (.com,  .net)  

DNS  for  cdnetworks.com  

“What’s  IP  address  of  www.kr.cdnetworks.com?”  

Resolver  Local  DNS  End  User  

Browser  

“What’s  DNS  Server  IP  address  of  cdnetworks.com?”  “What’s  DNS  Server  IP  address  of  cdngc.net?”  

DNS  for  cdngc.net  (GSLB)  “What’s  IP  address  of  www.kr.cdnetworks.com.cdngc.net?”  “61.110.226.28  and  61.110.226.15”  (IP  of  Cache  Servers)  

“www.kr.cdnetworks.com  is  www.kr.cdnetworks.cdngc.net”  

PHPFest  2011   19  

Page 20: CDN and Cloud - PHPFest 2011

Object  delivery  and  whole  site  delivery

  Object  delivery  •  Only  serves  specified  file  (image,  video,  js,  css)  and  sZll  other  page  is  served  fr

om  origin  site

hAp://www.kr.cdnetworks.com/index.php

hAp://images.kr.cdnetworks.com/images/common/main_logo.gif

www.kr.cdnetworks.com  !=  images.kr.cdnetworks.com

PHPFest  2011   20  

Page 21: CDN and Cloud - PHPFest 2011

Object  delivery  and  whole  site  delivery

  Whole  Site  Delivery  •  CDN  covers  whole  site  –  including  objects,  dynamic  pages  etc.  •  Need  more  aAenZon  –  what  is  cacheable  and  not  cacheable  not  to  break  sites  

hAp://www.kr.cdnetworks.com/index.php

hAp://www.kr.cdnetworks.com/images/common/main_logo.gif

www.kr.cdnetworks.com  ==  www.kr.cdnetworks.com

PHPFest  2011   21  

Page 22: CDN and Cloud - PHPFest 2011

Cacheable  and  non-­‐cacheable

  Objects  are  cacheable  •  In  Edge  Cache  Server  •  In  Proxy  Cache  in  ISP  or  your  network  •  In  Browser  Cache  •  TTL  (Time  To  Live)  –  lifeZme  in  Edge  Cache  

•  Images,  Videos,  Documents,  CSS,  Javascript  •  Not  changed  by  \me,  loca\on,  session,  cookie,  browser  

  Objects  are  non-­‐cacheable  •  Dynamic  response  from  PHP/JSP/ASP/…  •  Cannot  be  stored  in  Edge  Cache/Proxy/Browser  Cache  

•  Dynamically  generated  HTML  pages,  AJAX  response,  API  •  Same  URL  but  different  contents  by  \me,  loca\on,  session,  cookie,  browser  

PHPFest  2011   22  

Page 23: CDN and Cloud - PHPFest 2011

Cache  Control

  You  can  control  cache-­‐ability  of  objects  using  various  headers  in  HTTP  response.  •  CDN  Edge  Cache  •  Browser  Cache  (local  PC)  

  2  Basic  Status  •  Cache  Hit:  when  cache  already  has  the  object  •  Cache  Miss:  cache  will  pull  the  object  from  origin  and  store  

  Cache  related  headers  •  Last-­‐Modified,  Etag  •  Cache-­‐Control  •  Pragma  •  Vary  •  Expires  

  Cache/Proxy  related  headers  •  Via,  Age  

PHPFest  2011   23  

Page 24: CDN and Cloud - PHPFest 2011

Example  of  non-­‐cacheable  object

%  curl  -­‐I  http://www.naver.com    HTTP/1.1  200  OK  Date:  Thu,  26  May  2011  12:23:01  GMT  Server:  Apache  Cache-­‐Control:  no-­‐cache,  no-­‐store,  must-­‐revalidate  Pragma:  no-­‐cache  P3P:  CP="CAO  DSP  CURa  ADMa  TAIa  PSAa  OUR  LAW  STP  PHY  ONL  UNI  PUR  FIN  COM  NAV  INT  DEM  STA  PRE"  Cache-­‐Control:  no-­‐cache,  no-­‐store,  must-­‐revalidate  Pragma:  no-­‐cache  Vary:  Accept-­‐Encoding,User-­‐Agent  Connection:  close  Content-­‐Type:  text/html;  charset=UTF-­‐8

PHPFest  2011   24  

Page 25: CDN and Cloud - PHPFest 2011

Example  of  non-­‐cacheable  object  –  from  iPod?

%  curl  -­‐I  -­‐A  "Mozilla/5.0  (iPod;  U;  CPU  iPhone  OS  4_3_1  like  Mac  OS  X;  en-­‐us)  AppleWebKit/533.17.9  (KHTML,  like  Gecko)  Version/5.0.2  Mobile/8G4  Safari/6533.18.5"  http://www.naver.com  HTTP/1.1  302  Found  Date:  Thu,  26  May  2011  12:37:32  GMT  Server:  Apache  Location:  http://m.naver.com  Vary:  Accept-­‐Encoding  Connection:  close  Content-­‐Type:  text/html;  charset=iso-­‐8859-­‐1

PHPFest  2011   25  

Page 26: CDN and Cloud - PHPFest 2011

How  to  make  non-­‐cacheable  object  in  PHP

  Using  header()  funcZon    <?php  header(“Cache-­‐Control:  no-­‐cache,  no-­‐store,  must-­‐revalidate”);  header(“Pragma:  no-­‐cache”);  header(“Vary:  Accept-­‐Encoding,  User-­‐Agent”);  ?>  Hello  World    

PHPFest  2011   26  

Page 27: CDN and Cloud - PHPFest 2011

How  to  make  non-­‐cacheable  object  in  PHP

%  curl  -­‐D-­‐  http://www.kr.freebsd.org/~cjh/phpfest2011/nc.php  HTTP/1.1  200  OK  Date:  Thu,  26  May  2011  13:09:11  GMT  Server:  Apache/1.3.41  (Unix)  mod_perl/1.31  DAV/1.0.3  PHP/4.4.9  with  Suhosin-­‐Patch  mod_ssl/2.8.31  OpenSSL/0.9.7e-­‐p1  MS-­‐Author-­‐Via:  DAV  X-­‐Powered-­‐By:  PHP/4.4.9  Cache-­‐Control:  no-­‐cache,  no-­‐store,  must-­‐revalidate  Pragma:  no-­‐cache  Vary:  Accept-­‐Encoding,  User-­‐Agent  Transfer-­‐Encoding:  chunked  Content-­‐Type:  text/html;  charset=euc-­‐kr    Hello  World  

PHPFest  2011   27  

Page 28: CDN and Cloud - PHPFest 2011

How  to  make  non-­‐cacheable  object  in  PHP  (2)

<?php  header(“Cache-­‐Control:  no-­‐cache,  no-­‐store,  must-­‐revalidate”);  header(“Pragma:  no-­‐cache”);  header(“Vary:  Accept-­‐Encoding,  User-­‐Agent”);    if  (strstr($_SERVER["HTTP_USER_AGENT"],  "iPhone  OS"))  {          print  "<h1>Hello  iOS</h1>";          print  "<h1>Hello  iOS</h1>";          print  "<h1>Hello  iOS</h1>";          exit;  }  ?>  Hello  World    

PHPFest  2011   28  

Page 29: CDN and Cloud - PHPFest 2011

Example  of  cacheable  object

%  curl  -­‐I  'http://static.naver.com/www/u/2010/0611/nmms_215646753.gif'  HTTP/1.1  200  OK  Date:  Thu,  26  May  2011  12:27:30  GMT  Server:  Apache/2.0.52  Last-­‐Modified:  Fri,  11  Jun  2010  12:56:46  GMT  ETag:  "a06-­‐abe73f80"  Accept-­‐Ranges:  bytes  Content-­‐Length:  2566  Cache-­‐Control:  max-­‐age=604800  Content-­‐Type:  image/gif  Via:  1.1  SI2286-­‐239  (Jaguar/3.0-­‐62)  Age:  3  Expires:  Thu,  02  Jun  2011  12:27:23  GMT

PHPFest  2011   29  

TTL  is  7  day  

Page 30: CDN and Cloud - PHPFest 2011

Example  of  cacheable  object  in  CDN  Server

%  curl  -­‐I  'http://static.naver.com/www/u/2010/0611/nmms_215646753.gif'  HTTP/1.1  200  OK  Date:  Thu,  26  May  2011  12:27:30  GMT  Server:  Apache/2.0.52  Last-­‐Modified:  Fri,  11  Jun  2010  12:56:46  GMT  ETag:  "a06-­‐abe73f80"  Accept-­‐Ranges:  bytes  Content-­‐Length:  2566  Cache-­‐Control:  max-­‐age=604800  Content-­‐Type:  image/gif  Age:  3  Expires:  Thu,  02  Jun  2011  12:27:23  GMT    

%  curl  -­‐I  'http://static.naver.com/www/u/2010/0611/nmms_215646753.gif'  HTTP/1.1  200  OK  Date:  Thu,  26  May  2011  12:31:23  GMT  Server:  Apache/2.0.52  Last-­‐Modified:  Fri,  11  Jun  2010  12:56:46  GMT  ETag:  "a06-­‐abe73f80"  Accept-­‐Ranges:  bytes  Content-­‐Length:  2566  Cache-­‐Control:  max-­‐age=604800  Content-­‐Type:  image/gif  Age:  53  Expires:  Thu,  02  Jun  2011  12:30:30  GMT

   

PHPFest  2011   30  

Age:  header  value  is  residing  Zme  (second)  in  Edge  Cache.  In  this  case  this  object  will  stored  in  Edge  Cache  for  7  day  (604800  sec).

Page 31: CDN and Cloud - PHPFest 2011

How  to  make  cacheable  object  in  PHP

<?php  header("Cache-­‐Control:  max-­‐age=604800");  //  tell  CDN  cache  to  store  object  for  next  24  hours  header("Content-­‐Type:  text/plain");  header("Content-­‐Length:  ".filesize("test.txt"));  readfile("test.txt");  ?>    %  curl  -­‐D-­‐  http://www.kr.freebsd.org/~cjh/phpfest2011/c.php  HTTP/1.1  200  OK  Date:  Thu,  26  May  2011  13:35:32  GMT  Server:  Apache/1.3.41  (Unix)  mod_perl/1.31  DAV/1.0.3  PHP/4.4.9  with  Suhosin-­‐Patch  mod_ssl/2.8.31  OpenSSL/0.9.7e-­‐p1  MS-­‐Author-­‐Via:  DAV  X-­‐Powered-­‐By:  PHP/4.4.9  Cache-­‐Control:  max-­‐age=604800  Content-­‐Length:  17  Content-­‐Type:  text/plain;charset=euc-­‐kr    THIS  IS  TEST.TXT  

PHPFest  2011   31  

Page 32: CDN and Cloud - PHPFest 2011

How  to  make  cacheable  object  in  PHP  (2)

HTTP/1.1  200  OK  Date:  Thu,  26  May  2011  15:28:06  GMT  Server:  PWS/1.7.2.3  Cache-­‐Control:  max-­‐age=604800  Expires:  Thu,  02  Jun  2011  15:28:07  GMT  Age:  0  Content-­‐Length:  17  Content-­‐Type:  text/plain;charset=euc-­‐kr  Connection:  keep-­‐alive    THIS  IS  TEST.TXT

HTTP/1.1  200  OK  Date:  Thu,  26  May  2011  15:28:15  GMT  Server:  PWS/1.7.2.3  Cache-­‐Control:  max-­‐age=604800  Expires:  Thu,  02  Jun  2011  15:28:06  GMT  Age:  9  Content-­‐Length:  17  Content-­‐Type:  text/plain;charset=euc-­‐kr  Connection:  keep-­‐alive    THIS  IS  TEST.TXT

PHPFest  2011   32  

As  you  can  see  now  this  URL  is  cached  in  Edge  Cache,  although  this  page  is  generated  by  PHP.  Also  check  origin  server  if  access  from  cache  exists    should  be  none

   

Page 33: CDN and Cloud - PHPFest 2011

CDN  &  Cloud

  Cloud  CompuZng  provide  very  similar  purpose  of  CDN  such  as  reliability  and  scalability,  but  not  helpful  to  solve  other  problems  such  as  Network  Distance  (middle  mile)  problem  •  Cloud:  Most  servers  are  located  in  ONE  locaZon  

  Combining  CDN  with  Cloud  service  •  Cloud  CompuZng  can  solve  a  lot  of  origin  issue  such  as  scalability  •  CDN  can  provide  fast  access  to  cacheable  objects  •  For  high  performance,  global-­‐accessed  websites  •  Example  

−  Origin  Server  use  VM  Cloud  and  Storage  −  Use  CDN  for  caching  and  low  latency  

  Cloud  Service  company  has  compeZng  products  with  CDN  •  Amazon’s  S3  storage  +  CloudFront  

PHPFest  2011   33  

Page 34: CDN and Cloud - PHPFest 2011

Example:  CloudSleuth.net

PHPFest  2011   34  

Page 35: CDN and Cloud - PHPFest 2011

Example:  CloudSleuth.net

PHPFest  2011   35  

Page 36: CDN and Cloud - PHPFest 2011

Other  keywords

  ApplicaZon  Delivery    WAN  AcceleraZon/OpZmizaZon    Edge  CompuZng    Web  Page  OpZmizaZon    Mobile  OpZmizaZon    …  

Thank  you!  

PHPFest  2011   36