CDN and Cloud - PHPFest 2011
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share

CDN and Cloud - PHPFest 2011

  • 2,749 views
Uploaded on

Presented in PHPFest 2011, Seoul, Korea ...

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

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
2,749
On Slideshare
2,749
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
67
Comments
0
Likes
2

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. CDN  &  CloudJunho  Choi  <junho.choi@cdnetworks.com>  CDNetworks  h7p://www.cdnetworks.com  rev.  2
  • 2. Who  am  I?  Junho  Choi  ( )    CTO/APAC,  VP  of  Engineering  |  CDNetworks  hAp://www.cdnetworks.com    FreeBSD  CommiAer(ports)  since  2001  (cjh@freebsd.org)    Korea  FreeBSD  Users  Group  hAp://www.kr.freebsd.org  since  1999    TwiAer:  junhochoi   PHPFest  2011   2  
  • 3. Contents  CDN  –  what  problem  to  solve    Technology  in  CDN    How  to  uXlize  CDN/Cache  using  PHP    Cloud  CompuXng  &  CDN PHPFest  2011   3  
  • 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. Content  Delivery  Network  Problem  to  solve   •  Network  Distance   •  Reliability   •  Scalability   PHPFest  2011   5  
  • 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. CDN  in  website hAp://www.kr.cdnetworks.com/index.php Typical  web  site  has  a  lot  of  objects   Inside  –  images,  flash,  video,  js,  css  etc hAp://www.kr.cdnetworks.com/images/common/main_logo.gif PHPFest  2011   16  
  • 17. 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  
  • 18. DNS  lookup  example Root  DNS  (.com,  .net)   “What’s  DNS  Server  IP  address  of  cdnetworks.com?”   “What’s  IP  address  of  www.kr.cdnetworks.com?”   Resolver   DNS  for  cdnetworks.com   End  User   Local  DNS   Browser   “www.kr.cdnetworks.com  is  (CNAME)          www.kr.cdnetworks.cdngc.net”   PHPFest  2011   18  
  • 19. DNS  lookup  example Root  DNS  (.com,  .net)   “What’s  DNS  Server  IP  address  of  cdnetworks.com?”   “What’s  DNS  Server  IP  address  of  cdngc.net?”   “What’s  IP  address  of  www.kr.cdnetworks.com?”   Resolver   DNS  for  cdnetworks.com   End  User   Local  DNS   Browser   “www.kr.cdnetworks.com  is  www.kr.cdnetworks.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)   PHPFest  2011   19  
  • 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://www.kr.cdnetworks.com/index.php www.kr.cdnetworks.com   !=  images.kr.cdnetworks.com hAp://images.kr.cdnetworks.com/images/common/main_logo.gif PHPFest  2011   20  
  • 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://www.kr.cdnetworks.com/index.php www.kr.cdnetworks.com   ==  www.kr.cdnetworks.com hAp://www.kr.cdnetworks.com/images/common/main_logo.gif PHPFest  2011   21  
  • 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. 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. 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  
  • 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://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  
  • 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. 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  
  • 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. 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   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. Example  of  cacheable  object  in  CDN  Server%  curl  -­‐I  http://static.naver.com/www/ %  curl  -­‐I  http://static.naver.com/www/u/2010/0611/nmms_215646753.gif   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. 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  
  • 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/1.7.2.3   Server:  PWS/1.7.2.3  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. 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. Example:  CloudSleuth.net PHPFest  2011   34  
  • 35. Example:  CloudSleuth.net PHPFest  2011   35  
  • 36. Other  keywords  ApplicaXon  Delivery    WAN  AcceleraXon/OpXmizaXon    Edge  CompuXng    Web  Page  OpXmizaXon    Mobile  OpXmizaXon    …   Thank  you!   PHPFest  2011   36