[b3]couchbase server for speed and scale with interactive applications sdec deview 2012

22
1 Couchbase Server for Speed and Scale with Interac8ve Applica8ons Perry Krug Presenter Title

Upload: naver-d2

Post on 22-Jun-2015

1.139 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: [B3]couchbase server for speed and scale with interactive applications   sdec deview 2012

1  

Couchbase  Server  for  Speed  and  Scale  with  Interac8ve  Applica8ons  

Perry  Krug  Presenter  Title  

Page 2: [B3]couchbase server for speed and scale with interactive applications   sdec deview 2012

2  

Agenda  (just  an  outline)  

•  Needs  for  Interac8ve  Apps  –  Speed  

•  Speed  of  access  •  Speed  of  app  development  

–  Scale  •  Built  to  scale  

–  Unique  architectural  principals  •  Clustered  system  

–  Simple  for  applica8ons  –  Automa8c  sharding  of  data  across  cluster  

•  Single  index  view  –  No  need  to  define  sharding  keys  –  Automa8c,  online  transfer  of  data  across  cluster  

Page 3: [B3]couchbase server for speed and scale with interactive applications   sdec deview 2012

3  

The image cannot be displayed. Your computer may not have enough memory to open the image, or the image may have been corrupted. Restart your computer, and then open the file again. If the red x still appears, you may have to delete the image and then insert it again.

EXAMPLE  OF  AN  INTERACTIVE  APP  

Page 4: [B3]couchbase server for speed and scale with interactive applications   sdec deview 2012

4  

Instagrowth:  Android  Launch  

•  Instagram  gained  nearly  1  million  users  overnight  when  they  expanded  to  Android  

Example

Page 5: [B3]couchbase server for speed and scale with interactive applications   sdec deview 2012

5  

1 Instagram =

7.5M MAU*

Example

Page 6: [B3]couchbase server for speed and scale with interactive applications   sdec deview 2012

6  

Draw  Something  -­‐  Social  Game  

•  50  million  downloads  in  50  days  •  That’s  almost  5  Instagrams.  In  2  months.  

Page 7: [B3]couchbase server for speed and scale with interactive applications   sdec deview 2012

7  

Goes  Viral  3  Weeks  AZer  Launch  

19  17  15  13  11  9  7  5  3  3/1  28  26  24  22  20  18  16  14  12  10  8  2/6  

Draw  Something  by  OMGPOP  Daily  Ac8ve  Users  (millions)  

21  

2  

4  

6  

8  

10  

12  

14  

16  

Page 8: [B3]couchbase server for speed and scale with interactive applications   sdec deview 2012

8  

 Database  Opera8ons  

19  17  15  13  11  9  7  5  3  3/1  28  26  24  22  20  18  16  14  12  10  8  2/6  

Draw  Something  by  OMGPOP  Daily  Ac8ve  Users  (millions)  

21  

2  

4  

6  

8  

10  

12  

14  

16  

By  March  19,  there  were    over  30,000,000  downloads  of  the  app,  

over  5,000  drawings  being  stored  per  second,  over  2,200,000,000  drawings  stored,  

over  105,000  database  transac8ons  per  second,  and  over  3.3  terabytes  of  data  stored.  

Page 9: [B3]couchbase server for speed and scale with interactive applications   sdec deview 2012

9  

Social  Gaming  on  Couchbase  

iki  

Page 10: [B3]couchbase server for speed and scale with interactive applications   sdec deview 2012

10  

Speed  

•  Modern,  interac8ve  applica8ons  require  speed  – Web  pages  are  dynamic,  interac8ve  and  may  incrementally  fetch  content  for  display  

– Mobile  applica8ons  cannot  carry  all  of  the  content,  so  they  need  to  be  able  to  fetch  data  on  demand  

•  Couchbase  Speed  via…  – Managed,  built  in  cache  

•  memcached  compa8ble,  built  on  memcached  

–  Protocol  design  •  Client  can  directly  access  data  objects  within  the  cluster  •  No  quorum  reads  needed  to  determine  version,  always  consistent  

Page 11: [B3]couchbase server for speed and scale with interactive applications   sdec deview 2012

11  

Scale  

•  Modern  app  deployments  are  always  on,  available  24x7x365  –  Some  applica8ons  may  have  a  lifecycle  which  requires  scaling  down,  in  addi8onal  to  scaling  up  

•  Couchbase  scales  via…  –  Automa8cally  sharding  data  among  the  nodes  of  the  cluster  and  atomically  transferring  vbuckets  

–  Coordina8ng  these  changes  with  client  libraries  accessing  the  cluster  

Page 12: [B3]couchbase server for speed and scale with interactive applications   sdec deview 2012

12  

The image cannot be displayed. Your computer may not have enough memory to open the image, or the image may have been corrupted. Restart your computer, and then open the file again. If the red x still appears, you may have to delete the image and then insert it again.

CLUSTERING  ARCHITECTURE  

Page 13: [B3]couchbase server for speed and scale with interactive applications   sdec deview 2012

13  

                           

                           

         

COUCHBASE  CLIENT  LIBRARY      

Basic  Opera8on  

 Docs  distributed  evenly  across  servers  in  the  cluster  

 Each  server  stores  both  ac/ve  &  replica  docs    Only  one  server  ac8ve  at  a  8me  

 Client  library  provides  app  with  simple  interface  to  database  

 Cluster  map  provides  map  to  which  server  doc  is  on    App  never  needs  to  know  

  App  reads,  writes,  updates  docs  

  Mul8ple  App  Servers  can  access  same  document  at  same  8me  

 

                           

Doc  4  

Doc  2  

Doc  5  

SERVER  1  

Doc  6  

Doc  4  

SERVER  2  

Doc  7  

Doc  1  

SERVER  3  

Doc  3  

User  Configured  Replica  Count  =  1  

Read/Write/Update  

         

COUCHBASE  CLIENT  LIBRARY      

Read/Write/Update  

Doc  9  

Doc  7  

Doc  8   Doc  6  

Doc  3  

DOC  

DOC  

DOC  

DOC  

DOC  

DOC  

DOC  

DOC  

DOC  

DOC  

DOC  

DOC  

DOC  

DOC  

DOC  

Doc  9  

Doc  5  

DOC  

DOC  

DOC  

Doc  1  

Doc  8   Doc  2  

Replica  Docs   Replica  Docs   Replica  Docs  

Ac8ve  Docs   Ac8ve  Docs   Ac8ve  Docs  

CLUSTER  MAP      

CLUSTER  MAP      

APP  SERVER  1   APP  SERVER  2  

COUCHBASE  SERVER    CLUSTER  

Page 14: [B3]couchbase server for speed and scale with interactive applications   sdec deview 2012

14  

                           

                           

Add  Nodes  

  Two  servers  added  to  cluster    One-­‐click  opera8on  

  Docs  automa8cally  rebalanced  across  cluster    Even  distribu8on  of  

docs    Minimum  doc  movement  

  Cluster  map  updated  

  App  database  calls  now  distributed  over  larger  #  of  servers  

User  Configured  Replica  Count  =  1  

Read/Write/Update   Read/Write/Update  

Doc  7  

Doc  9  

Doc  3  

Ac8ve  Docs  

Replica  Docs  

Doc  6  

         

COUCHBASE  CLIENT  LIBRARY      CLUSTER  MAP  

   

APP  SERVER  1  

         

COUCHBASE  CLIENT  LIBRARY      CLUSTER  MAP  

   

APP  SERVER  2  

                           

                           

                           

Doc  4  

Doc  2  

Doc  5  

SERVER  1  

Doc  6  

Doc  4  

SERVER  2  

Doc  7  

Doc  1  

SERVER  3  

Doc  3  

Doc  9  

Doc  7  

Doc  8   Doc  6  

Doc  3  

DOC  

DOC  

DOC  

DOC  

DOC  

DOC  

DOC  

DOC  

DOC  

DOC  

DOC  

DOC  

DOC  

DOC  

DOC  

Doc  9  

Doc  5  

DOC  

DOC  

DOC  

Doc  1  

Doc  8   Doc  2  

Replica  Docs   Replica  Docs   Replica  Docs  

Ac8ve  Docs   Ac8ve  Docs   Ac8ve  Docs  

SERVER  4   SERVER  5  

Ac8ve  Docs   Ac8ve  Docs  

Replica  Docs   Replica  Docs  

COUCHBASE  SERVER    CLUSTER  

Page 15: [B3]couchbase server for speed and scale with interactive applications   sdec deview 2012

15  

                           

                           

Fail  Over  Node  

  App  servers  happily  accessing  docs  on  Server  3  

  Server  fails    App  server  requests  to  server  3  fail    Cluster  detects  server  has  failed  

  Promotes  replicas  of  docs  to  ac/ve    Updates  cluster  map  

  App  server  requests  for  docs  now  go  to  appropriate  server  

  Typically  rebalance    would  follow    

User  Configured  Replica  Count  =  1  

Doc  7  

Doc  9  

Doc  3  

Ac8ve  Docs  

Replica  Docs  

Doc  6  

         

COUCHBASE  CLIENT  LIBRARY      CLUSTER  MAP  

   

APP  SERVER  1  

         

COUCHBASE  CLIENT  LIBRARY      CLUSTER  MAP  

   

APP  SERVER  2  

                           

                           

                           

Doc  4  

Doc  2  

Doc  5  

SERVER  1  

Doc  6  

Doc  4  

SERVER  2  

Doc  7  

Doc  1  

SERVER  3  

Doc  3  

Doc  9  

Doc  7   Doc  8  

Doc  6  

Doc  3  

DOC  

DOC  

DOC  DOC  

DOC  

DOC  

DOC   DOC  

DOC  

DOC  

DOC   DOC  

DOC  

DOC  

DOC  

Doc  9  

Doc  5  DOC  

DOC  

DOC  

Doc  1  

Doc  8  

Doc  2  

Replica  Docs   Replica  Docs   Replica  Docs  

Ac8ve  Docs   Ac8ve  Docs   Ac8ve  Docs  

SERVER  4   SERVER  5  

Ac8ve  Docs   Ac8ve  Docs  

Replica  Docs   Replica  Docs  

COUCHBASE  SERVER    CLUSTER  

Page 16: [B3]couchbase server for speed and scale with interactive applications   sdec deview 2012

16  

The image cannot be displayed. Your computer may not have enough memory to open the image, or the image may have been corrupted. Restart your computer, and then open the file again. If the red x still appears, you may have to delete the image and then insert it again.

SINGLE  INDEX  VIEW  

Page 17: [B3]couchbase server for speed and scale with interactive applications   sdec deview 2012

17  

Couchbase  Server  Views  

•  Couchbase  has  a  method  of  building  and  maintaining  views  over  the  set  of  documents  within  a  bucket  

•  Can  be  used  for:  –  Secondary  indexes  –  Aggrega8ons  and  stats  –  Analyzing  datasets  

•  Built  for  speed  –  Allow  relaxed  consistency  for  speed,  or  consistent  if  required    

map:  function(doc) { emit(doc.name, [doc.city, doc.salary]); }  reduce:  function (key, values, rereduce) { var sum = 0; for(i=0; i < values.length; i++) { sum = sum + values[i]; } return(sum); }

Page 18: [B3]couchbase server for speed and scale with interactive applications   sdec deview 2012

18  

Views  are  B+Trees  Over  the  Data  

bits 0

Key: "f"Sum: 17

0 0 0 bits 0

Key: "f"Sum: 17

0 0 0

bits 0

Key: "f"Sum: 17

0 0 0 bits 0

Key: "f"Sum: 17

0 0 0 bits 0

Key: "f"Sum: 17

0 0 0 bits 0

Key: "f"Sum: 17

0 0 0

bits 0

Key: "f"Sum: 17

0 0 0 bits 0

Key: "f"Sum: 17

0 0 0 bits 0

Key: "f"Sum: 17

0 0 0 bits 0

Key: "f"Sum: 17

0 0 0 bits 0

Key: "f"Sum: 17

0 0 0 bits 0

Key: "f"Sum: 17

0 0 0 bits 0

Key: "f"Sum: 17

0 0 0 bits 0

Key: "f"Sum: 17

0 0 0

Key: "a"Value: 4

vBucket: 1

Key: "b"Value: 2

vBucket: 2

Key: "c"Value: 0

vBucket: 3

Key: "d"Value: 6

vBucket: 4

Key: "e"Value: 4

vBucket: 5

Key: "f"Value: 4

vBucket: 6

Key: "j"Value: 4

vBucket: 10

Key: "k"Value: 4

vBucket: 11

Key: "l"Value: 4

vBucket: 12

Key: "m"Value: 4

vBucket: 13

Key: "n"Value: 4

vBucket: 14

Key: "o"Value: 4

vBucket: 15

Key: "p"Value: 4

vBucket: 16

Key: "q"Value: 4

vBucket: 17

Key: "r"Value: 4

vBucket: 18

Key: "s"Value: 4

vBucket: 19

Key: "g"Value: 4

vBucket: 7

Key: "h"Value: 4

vBucket: 8

Key: "i"Value: 4

vBucket: 9

Key: "t"Value: 4

vBucket: 20

Key: "u"Value: 4

vBucket: 21

Key: "v"Value: 4

vBucket: 22

Key: "w"Value: 4

vBucket: 23

Key: "x"Value: 4

vBucket: 24

Key: "y"Value: 4

vBucket: 25

Key: "z"Value: 4

vBucket: 26

Views  are  Built  Atop  Incremental  Map  Reduce  •  Distributed  throughout  the  cluster  •  Query  API  abstracts  the  cluster  topology,  and  automa8cally  gathers  the  results  •  Rebuilds  subsets  of  the  B+Tree  based  on  updates  

Page 19: [B3]couchbase server for speed and scale with interactive applications   sdec deview 2012

19  

bits 0

Key: "m"Sum: 92

0 0 0 bits 0

Key: "z"Sum: 17

0 0 0

bits 0

Key: "f"Sum: 21

0 0 0 bits 0

Key: "m"Sum: 71

0 0 0

bits 0

Key: "d"Sum: 10

0 0 0 bits 0

Key: "f"Sum: 11

0 0 0 bits 0

Key: "i"Sum: 24

0 0 0 bits 0

Key: "m"Sum: 47

0 0 0

Key: "a"Value: 4

vBucket: 1

Key: "b"Value: 2

vBucket: 2

Key: "c"Value: 0

vBucket: 3

Key: "d"Value: 6

vBucket: 4

Key: "e"Value: 4

vBucket: 5

Key: "f"Value: 4

vBucket: 6

Key: "j"Value: 4

vBucket: 10

Key: "k"Value: 4

vBucket: 11

Key: "l"Value: 4

vBucket: 12

Key: "m"Value: 4

vBucket: 13

Key: "g"Value: 4

vBucket: 7

Key: "h"Value: 4

vBucket: 8

Key: "i"Value: 4

vBucket: 9

Page 20: [B3]couchbase server for speed and scale with interactive applications   sdec deview 2012

20  

Data  is  Distributed  Using  vbuckets,  but…  

•  Couchbase  Server  has  1024  vbuckets  stored  throughout  the  cluster  

Page 21: [B3]couchbase server for speed and scale with interactive applications   sdec deview 2012

21  

B-­‐Superstar:  a  new  B+Tree  ready  for  vbuckets  

Only  one  B+Tree  per  node  with  masking  of  ac8ve  vbucket  Data.  

S8ll  allows  concurrent  access  and  even  

materializing  tree  during  rebalance  

Read  more  on  Damien’s  blog:  hmp://damienkatz.net/2012/05/stabilizing_couchbase_server_2.html  

Page 22: [B3]couchbase server for speed and scale with interactive applications   sdec deview 2012

22  

Perry  Krug  

Thanks  Q&A