Games For The Masses Scaling Rails To The Extreme

51
GAMES FOR THE MASSES SCALING RAILS TO THE EXTREME EuRuKo 2011 in Berlin

description

 

Transcript of Games For The Masses Scaling Rails To The Extreme

Page 1: Games For The Masses Scaling Rails To The Extreme

GAMES  FOR  THE  MASSESSCALING  RAILS  TO  THE  EXTREME

EuRuKo  2011  in  Berlin

Page 2: Games For The Masses Scaling Rails To The Extreme

Who  is  that  guy?

Jesper  Richter-­‐Reichhelm

@jrirei

Berlin,  Germany

Head  of  Engineering  @  wooga

Page 3: Games For The Masses Scaling Rails To The Extreme

Wooga  develops  social  games

Page 4: Games For The Masses Scaling Rails To The Extreme

Wooga  has  dedicated  game  teams

PHPSQLCloud

RubySQL  +  Redis

Cloud

RubyRedis

Bare  Metal

Page 5: Games For The Masses Scaling Rails To The Extreme

Wooga  has  dedicated  game  teams

PHPSQLCloud

RubySQL  +  Redis

Cloud

RubyRedis

Bare  Metal

Page 6: Games For The Masses Scaling Rails To The Extreme

Both  games  are  similar  in  their  setup

Flash  client Ruby  backend

Page 7: Games For The Masses Scaling Rails To The Extreme

Both  games  have  similar  problems

High  traffic

• 200+  million  h=p  requests  /  day

High  DB  throughput

• 100.000  DB  operaDons  /  second

Hardest  problems  to  solve

• DB  migraDons,  DB  failover,  DB  performance,  ...

Page 8: Games For The Masses Scaling Rails To The Extreme

What’s  best?

Big  cloud  vs.  bare  metal

Hybrid  (SQL  +  Redis)  vs.  Redis  only

In-­‐memory  vs.  DB  hierarchy

Conclusion:  So  what’s  best?

Page 9: Games For The Masses Scaling Rails To The Extreme

Big  cloud  vs.  bare  metal

Big  cloud:  Amazon  EC2

• new  server  in  5  minutes

• automated  deployment

• load  based  setup

Page 10: Games For The Masses Scaling Rails To The Extreme

Big  cloud  vs.  bare  metal

Big  cloud:  Amazon  EC2

• new  server  in  5  minutes

• automated  deployment

• load  based  setup

Bare  metal:  Hetzner

• new  server  in  2-­‐14  days

• automated  deployment

Page 11: Games For The Masses Scaling Rails To The Extreme

What  kind  of  app  server  are  available?

XL  CPU  instance

• 8  virtual  cores

• 8  GB  RAM

Page 12: Games For The Masses Scaling Rails To The Extreme

Bare  metal  servers  are  more  powerful

XL  CPU  instance

• 8  virtual  cores

• 8  GB  RAM

EQ10  server

• 12  “processing  threads”

• 24  GB  RAM

Page 13: Games For The Masses Scaling Rails To The Extreme

Bare  metal  servers  are  more  powerful

XL  CPU  instance

• 8  virtual  cores

• 8  GB  RAM

=>  390,-­‐  €  /  month

EQ10  server

• 12  “processing  threads”

• 24  GB  RAM

=>  200,-­‐  €  /  month

Page 14: Games For The Masses Scaling Rails To The Extreme

And  how  is  the  network?

min  ping:  0.2  -­‐  0.3  ms min  ping:  0.2  ms

Page 15: Games For The Masses Scaling Rails To The Extreme

Want  a  fast  network?  Get  your  own!

min  ping:  0.2  -­‐  0.3  ms

max  ping:  7.8  -­‐  59  ms

avg  ping:  0.8  -­‐  4.4  ms

min  ping:  0.2  ms

max  ping:  0.3  ms

avg  ping:  0.2  ms

Page 16: Games For The Masses Scaling Rails To The Extreme

Want  a  fast  network?  Get  your  own!

min  ping:  0.2  -­‐  0.3  ms

max  ping:  7.8  -­‐  59  ms

avg  ping:  0.8  -­‐  4.4  ms

22  DB  calls  per  hfp  calls

min  ping:  0.2  ms

max  ping:  0.3  ms

avg  ping:  0.2  ms

saved  13  -­‐  92  ms  latency

Page 17: Games For The Masses Scaling Rails To The Extreme

What’s  befer?  Depends  on  your  needs!

Big  cloud  is  great  if  you

• don’t  know  your  load

• scale  up  /  down  quickly

Page 18: Games For The Masses Scaling Rails To The Extreme

What’s  befer?  Depends  on  your  needs!

Big  cloud  is  great  if  you

• don’t  know  your  load

• scale  up  /  down  quickly

Bare  metal  is  great  if  you

• want  to  save  money

• need  stable  performance

Page 19: Games For The Masses Scaling Rails To The Extreme

What’s  befer?  Depends  on  your  needs!

Big  cloud  is  great  if  you

• don’t  know  your  load

• scale  up  /  down  quickly

Say:  “Don’t  worry”

Bare  metal  is  great  if  you

• want  to  save  money

• need  stable  performance

Say:  “Think  ahead”

Page 20: Games For The Masses Scaling Rails To The Extreme

What’s  best?

Big  cloud  vs.  bare  metal

Hybrid  (SQL  +  Redis)  vs.  Redis  only

In-­‐memory  vs.  DB  hierarchy

Conclusion:  So  what’s  best?

Page 21: Games For The Masses Scaling Rails To The Extreme

Hybrid  (SQL  +  Redis)  vs.  Redis

Hybrid  (SQL  +  Redis)

• started  with  MySQL

• hit  a  wall  due  to  IO  limits

• introduced  Redis  later

Redis  only

Page 22: Games For The Masses Scaling Rails To The Extreme

If  MySQL  is  a  truck,  ...

Fast  enough  for  reads

Can  store  on  disk

Robust  replicakon

h=p://www.flickr.com/photos/erix/245657047/

Page 23: Games For The Masses Scaling Rails To The Extreme

If  MySQL  is  a  truck,  Redis  is  a  Ferrari

Fast  enough  for  reads

Can  store  on  disk

Robust  replicakon

Super  fast  reads/writes

Out  of  memory  =>  dead

Fragile  replicakon

h=p://www.flickr.com/photos/erix/245657047/

Page 24: Games For The Masses Scaling Rails To The Extreme

Hybrid  (SQL  +  Redis)  vs.  Redis

Hybrid  (SQL  +  Redis)

• started  with  MySQL

• hit  a  wall  due  to  IO  limits

• introduced  Redis  later

Redis  only

Page 25: Games For The Masses Scaling Rails To The Extreme

Hybrid  (SQL  +  Redis)  vs.  Redis

Hybrid  (SQL  +  Redis)

• started  with  MySQL

• hit  a  wall  due  to  IO  limits

• introduced  Redis  later

MySQL  has  its  hard  limits

Redis  only

Works  fine  if  done  right

Page 26: Games For The Masses Scaling Rails To The Extreme

How  many  tables  to  store  a  user  in?

22  MySQL  tables

7  Redis  hashes

Page 27: Games For The Masses Scaling Rails To The Extreme

How  many  tables  to  store  a  user  in?

22  MySQL  tables

7  Redis  hashes

1  Redis  Hash

Page 28: Games For The Masses Scaling Rails To The Extreme

How  many  tables  to  store  a  user  in?

22  MySQL  tables

7  Redis  hashes

Easy  to  implement

Faster  for  small  changes

1  Redis  Hash

Less  top  level  keys

Export  and  import  is  easy

Page 29: Games For The Masses Scaling Rails To The Extreme

What’s  best?

Big  cloud  vs.  bare  metal

Hybrid  (SQL  +  Redis)  vs.  Redis  only

In-­‐memory  vs.  DB  hierarchy

Conclusion:  So  what’s  best?

Page 30: Games For The Masses Scaling Rails To The Extreme

Redis  storage  type

Redis  works  in-­‐memory

Dumps  slow  down  master

• Dumping  on  slaves  only

Page 31: Games For The Masses Scaling Rails To The Extreme

Redis  storage  type

Redis  works  in-­‐memory

Dumps  slow  down  master

• Dumping  on  slaves  only

Redis  used  vm

Dumps  to  disk  impossible

• Own  system  to  store  JSON  files  to  disk

Page 32: Games For The Masses Scaling Rails To The Extreme

Redis  storage  type

Redis  works  in-­‐memory

Dumps  slow  down  master

• Dumping  on  slaves  only

Redis  used  vm

Dumps  to  disk  impossible

• Own  system  to  store  JSON  files  to  disk

Redis  became  a  cache  only

Page 33: Games For The Masses Scaling Rails To The Extreme

Redis  storage  type

Redis  works  in-­‐memory

Dumps  slow  down  master

• Dumping  on  slaves  only

Redis  now  uses  diskstore

Page 34: Games For The Masses Scaling Rails To The Extreme

Redis  storage  type

Redis  works  in-­‐memory

Dumps  slow  down  master

• Dumping  on  slaves  only

Redis  now  uses  diskstore

• Experimental  branch

• Stores  async.  to  disk  

Page 35: Games For The Masses Scaling Rails To The Extreme

Redis  storage  type

Redis  works  in-­‐memory

Dumps  slow  down  master

• Dumping  on  slaves  only

Redis  now  uses  diskstore

• Experimental  branch

• Stores  async.  to  disk  

Redis  became  a  DB  again

Page 36: Games For The Masses Scaling Rails To The Extreme

There  are  many  inackve  users

  hourly

daily

monthly

lifetime

0M 2M 4M 6M

6,0M

3,0M

0,4M

0,1Mhourly

daily

monthly

lifetime

0M 8M 16M 24M

20,8M

8,0M

1,3M

0,3M

Page 37: Games For The Masses Scaling Rails To The Extreme

Not  all  users  play  at  the  same  day

In-­‐memory

100%  of  users  in  RAM

DB  hierarchy

• Redis  in-­‐memory

• Redis  diskstore  on  disk

3%  of  users  in  RAM

Page 38: Games For The Masses Scaling Rails To The Extreme

What’s  best?

Big  cloud  vs.  bare  metal

Hybrid  (SQL  +  Redis)  vs.  Redis  only

In-­‐memory  vs.  DB  hierarchy

Conclusion:  So  what’s  best?

Page 39: Games For The Masses Scaling Rails To The Extreme

So,  what  didn’t  work?

Big  cloud

Hybrid  (SQL  +  Redis)

In-­‐memory  “only”

Bare  metal

Redis  only

DB  hierarchy

Page 40: Games For The Masses Scaling Rails To The Extreme

So,  what  didn’t  work?

Big  cloud

Hybrid  (SQL  +  Redis)

In-­‐memory  “only”

Bare  metal

Redis  only

DB  hierarchy

Page 41: Games For The Masses Scaling Rails To The Extreme

Let’s  dig  a  bit  deeper

1,300,000  daily  users

5000  hfp  calls/s  peak

100  ms  response  kme

35-­‐70  servers

400,000  daily  users  

2500  hfp  calls/s  peak

10  ms  response  kme

11  servers

Page 42: Games For The Masses Scaling Rails To The Extreme

Hoskng  costs  /  DAU  compared

HosDng

5x  higher

Page 43: Games For The Masses Scaling Rails To The Extreme

There  are  2  main  reasons  for  higher  cost

Databases Other

DB:  20x  higher

Other:  3x  higher

Page 44: Games For The Masses Scaling Rails To The Extreme

There  are  2  main  reasons  for  higher  cost

Databases Other

DB:  20x  higher(both  RAM  and  cost)

Other:  3x  higher

No  DB  hierarchy!

Page 45: Games For The Masses Scaling Rails To The Extreme

So,  what  didn’t  work?

Big  cloud

Hybrid  (SQL  +  Redis)

In-­‐memory  “only”

Bare  metal

Redis  only

DB  hierarchy

Page 46: Games For The Masses Scaling Rails To The Extreme

So,  what  didn’t  work?

Big  cloud

Hybrid  (SQL  +  Redis)

In-­‐memory  “only”

Bare  metal

Redis  only

DB  hierarchy

depends  ...

Page 47: Games For The Masses Scaling Rails To The Extreme

So,  what  didn’t  work?

Big  cloud

Hybrid  (SQL  +  Redis)

In-­‐memory  “only”

Bare  metal

Redis  only

DB  hierarchy

depends  ...

never

again!

Page 48: Games For The Masses Scaling Rails To The Extreme

So,  what  didn’t  work?

Big  cloud

Hybrid  (SQL  +  Redis)

In-­‐memory  “only”

Bare  metal

Redis  only

DB  hierarchy

depends  ...

never,  ever,

ever  again!

Page 49: Games For The Masses Scaling Rails To The Extreme

Next  game  will  do  things  befer

Start  in  cloud  and  then  go  metal?

Redis  only

DB  hierarchy

Page 50: Games For The Masses Scaling Rails To The Extreme

BTW,  wooga  is  hiring!

Q  &  A

slideshare.net/wooga

Jesper  Richter-­‐Reichhelm@jrirei

wooga.com/jobs

Page 51: Games For The Masses Scaling Rails To The Extreme

BTW,  wooga  is  hiring!

Thank  you

slideshare.net/wooga

Jesper  Richter-­‐Reichhelm@jrirei

wooga.com/jobs