CDN and Cloud - PHPFest 2011


Published on

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

Published in: Technology
  • Be the first to comment

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

CDN and Cloud - PHPFest 2011

  1. 1. CDN  &  CloudJunho  Choi  <>  CDNetworks  h7p://  rev.  2
  2. 2. Who  am  I?  Junho  Choi  ( )    CTO/APAC,  VP  of  Engineering  |  CDNetworks  hAp://    FreeBSD  CommiAer(ports)  since  2001  (    Korea  FreeBSD  Users  Group  hAp://  since  1999    TwiAer:  junhochoi   PHPFest  2011   2  
  3. 3. Contents  CDN  –  what  problem  to  solve    Technology  in  CDN    How  to  uXlize  CDN/Cache  using  PHP    Cloud  CompuXng  &  CDN PHPFest  2011   3  
  4. 4. 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  soluXon  such  as  Flash  Media  or  Wind ows  Media.    … PHPFest  2011   4  
  5. 5. Content  Delivery  Network  Problem  to  solve   •  Network  Distance   •  Reliability   •  Scalability   PHPFest  2011   5  
  6. 6. Problem  to  Solve  –  Network  Distance  Middle  Mile  Problem EMEA HQ End-user “Origin  Server”   Customer’s  web  site First  Mile   Middle  Mile   Last  Mile   Same  Data  Center   Bad Routing Same  LocaXon   Same  ISP   Same  ISP   Network Failure Low  latency   Low  latency   High  Bandwidth Long distance Low  Bandwidth   PHPFest  2011   6  
  7. 7. Problem  to  Solve  –  Network  Distance “Edge  Server”   CDN  Cache EMEA HQ End-user “Origin  Server”   Customer’s  web  site First  Mile Middle  Mile Last  Mile Place  edge  (caching  or  mirroring)  server  on   nearest  locaXon  to  end  user PHPFest  2011   7  
  8. 8. Problem  to  Solve  –  Reliability EMEA HQ End-user First  Mile Middle  Mile Last  Mile SXll  able  to  access  on  CDN  Edge  server PHPFest  2011   8  
  9. 9. 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  
  10. 10. History  Late  90’s,  SandPiper  was  first  CDN  company  and  Akamai  made  it  a  success ful  market  around  1999~2000    In  Korea,  CDN  service  started  around  2000  by  a  few  startups  including  CD Networks    Now  CDN  provider  and  ISP  are  compeXng  each  other   PHPFest  2011   10  
  11. 11. 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    AddiXonal  Service   •  Storage  as  a  origin   •  P2P  delivery  (aka  grid  delivery)    Pay  for  usage:  traffic  (Gbytes)  or  bandwidth  (Gbit/sec)     PHPFest  2011   11  
  12. 12. 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  Xme  –  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  
  13. 13. Traffic  PaNern  of  a  web  siteAs  your  website  ge^ng  popular,  there  will  be  unexpected  traffic  paAerns   Website  only  can  handle  this   (limited  by  bandwidth,  server,  etc) PHPFest  2011   13  
  14. 14. High  Level  Architecture Data  Center,  or  PoP  (Point  Of  Presence) Cache Streaming Storage Monitoring Router GSLB Cache Management Cache Log  Processing Storage Monitoring Operator  Portal Router Customer  Portal Cache Admin  PoP  or  Control  Center Cache Storage Monitoring Router PHPFest  2011   14  
  15. 15. Main  Technology  GSLB   •  Global  Server  Load  Balancing   •  Typically  DNS  server  which  do  load  balancing  between  mulXple  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  configuraXon  parameter  and  HTTP  response  from  origin    Portal   •  Large  data  processing  –  processing  daily  logs   •  Controllable  via  UI  for  operators PHPFest  2011   15  
  16. 16. CDN  in  website hAp:// Typical  web  site  has  a  lot  of  objects   Inside  –  images,  flash,  video,  js,  css  etc hAp:// PHPFest  2011   16  
  17. 17. DNS  lookup  example%  dig    ;;  QUESTION  SECTION:  ;    IN  A    ;;  ANSWER  SECTION:  3420  IN  CNAME  20  IN  A  20  IN  A    ;;  AUTHORITY  SECTION:    68200  IN  NS    68200  IN  NS    ;;  ADDITIONAL  SECTION:  64021  IN  A  48212  IN  A PHPFest  2011   17  
  18. 18. DNS  lookup  example Root  DNS  (.com,  .net)   “What’s  DNS  Server  IP  address  of”   “What’s  IP  address  of”   Resolver   DNS  for   End  User   Local  DNS   Browser   “  is  (CNAME)        ”   PHPFest  2011   18  
  19. 19. DNS  lookup  example Root  DNS  (.com,  .net)   “What’s  DNS  Server  IP  address  of”   “What’s  DNS  Server  IP  address  of”   “What’s  IP  address  of”   Resolver   DNS  for   End  User   Local  DNS   Browser   “  is”   DNS  for  (GSLB)   “What’s  IP  address  of”   “  and”  (IP  of  Cache  Servers)   PHPFest  2011   19  
  20. 20. Object  delivery  and  whole  site  delivery  Object  delivery   •  Only  serves  specified  file  (image,  video,  js,  css)  and  sXll  other  page  is  served  fr om  origin  site hAp://   != hAp:// PHPFest  2011   20  
  21. 21. Object  delivery  and  whole  site  delivery  Whole  Site  Delivery   •  CDN  covers  whole  site  –  including  objects,  dynamic  pages  etc.   •  Need  more  aAenXon  –  what  is  cacheable  and  not  cacheable  not  to  break  sites   hAp://   == hAp:// PHPFest  2011   21  
  22. 22. 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)  –  lifeXme  in  Edge  Cache   •  Images,  Videos,  Documents,  CSS,  Javascript   •  Not  changed  by  me,  locaon,  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,  locaon,  session,  cookie,  browser   PHPFest  2011   22  
  23. 23. Cache  Control  You  can  control  cache-­‐ability  of  objects  using  various  headers  in  HTTP  resp onse.   •  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  
  24. 24. Example  of  non-­‐cacheable  object%  curl  -­‐I    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  
  25. 25. 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/1.1  302  Found  Date:  Thu,  26  May  2011  12:37:32  GMT  Server:  Apache  Location:  Vary:  Accept-­‐Encoding  Connection:  close  Content-­‐Type:  text/html;  charset=iso-­‐8859-­‐1 PHPFest  2011   25  
  26. 26. How  to  make  non-­‐cacheable  object  in  PHP  Using  header()  funcXon    <?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  
  27. 27. How  to  make  non-­‐cacheable  object  in  PHP%  curl  -­‐D-­‐  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  
  28. 28. 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  
  29. 29. Example  of  cacheable  object%  curl  -­‐I  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   TTL  is  7  day  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  
  30. 30. Example  of  cacheable  object  in  CDN  Server%  curl  -­‐I %  curl  -­‐I   u/2010/0611/nmms_215646753.gif  HTTP/1.1  200  OK   HTTP/1.1  200  OK  Date:  Thu,  26  May  2011  12:27:30  GMT   Date:  Thu,  26  May  2011  12:31:23  GMT  Server:  Apache/2.0.52   Server:  Apache/2.0.52  Last-­‐Modified:  Fri,  11  Jun  2010  12:56:4 Last-­‐Modified:  Fri,  11  Jun  2010  12:56:46  GMT   6  GMT  ETag:  "a06-­‐abe73f80"   ETag:  "a06-­‐abe73f80"  Accept-­‐Ranges:  bytes   Accept-­‐Ranges:  bytes  Content-­‐Length:  2566   Content-­‐Length:  2566  Cache-­‐Control:  max-­‐age=604800   Cache-­‐Control:  max-­‐age=604800  Content-­‐Type:  image/gif   Content-­‐Type:  image/gif  Age:  3     Age:  53    Expires:  Thu,  02  Jun  2011  12:27:23  GMT   Expires:  Thu,  02  Jun  2011  12:30:30  GMT   Age:  header  value  is  residing  Xme  (second)  in  Edge  Cache.   In  this  case  this  object  will  stored  in  Edge  Cache  for  7  day   (604800  sec). PHPFest  2011   30  
  31. 31. 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/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  
  32. 32. How  to  make  cacheable  object  in  PHP  (2)HTTP/1.1  200  OK   HTTP/1.1  200  OK  Date:  Thu,  26  May  2011  15:28:06  GMT   Date:  Thu,  26  May  2011  15:28:15  GMT  Server:  PWS/   Server:  PWS/  Cache-­‐Control:  max-­‐age=604800   Cache-­‐Control:  max-­‐age=604800  Expires:  Thu,  02  Jun  2011  15:28:07  GMT   Expires:  Thu,  02  Jun  2011  15:28:06  GMT  Age:  0     Age:  9  Content-­‐Length:  17     Content-­‐Length:  17  Content-­‐Type:  text/plain;charset=euc-­‐kr   Content-­‐Type:  text/plain;charset=euc-­‐kr  Connection:  keep-­‐alive   Connection:  keep-­‐alive      THIS  IS  TEST.TXT THIS  IS  TEST.TXT 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 PHPFest  2011   32  
  33. 33. CDN  &  Cloud  Cloud  CompuXng  provide  very  similar  purpose  of  CDN  such  as  reliability  an d  scalability,  but  not  helpful  to  solve  other  problems  such  as  Network  Dist ance  (middle  mile)  problem   •  Cloud:  Most  servers  are  located  in  ONE  locaXon    Combining  CDN  with  Cloud  service   •  Cloud  CompuXng  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  compeXng  products  with  CDN   •  Amazon’s  S3  storage  +  CloudFront   PHPFest  2011   33  
  34. 34. Example: PHPFest  2011   34  
  35. 35. Example: PHPFest  2011   35  
  36. 36. Other  keywords  ApplicaXon  Delivery    WAN  AcceleraXon/OpXmizaXon    Edge  CompuXng    Web  Page  OpXmizaXon    Mobile  OpXmizaXon    …   Thank  you!   PHPFest  2011   36  
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.