Download - You are not alone - Scaling multiplayer games

Transcript
Page 1: You are not alone - Scaling multiplayer games

You are not aloneScaling Multiplayer Games

Jesper Richter-Reichhelm - @jrireiKnut Nesheim - @knutin

Page 2: You are not alone - Scaling multiplayer games
Page 3: You are not alone - Scaling multiplayer games
Page 4: You are not alone - Scaling multiplayer games
Page 5: You are not alone - Scaling multiplayer games
Page 6: You are not alone - Scaling multiplayer games
Page 7: You are not alone - Scaling multiplayer games
Page 8: You are not alone - Scaling multiplayer games
Page 9: You are not alone - Scaling multiplayer games

> 1,000,000 daily users

Page 10: You are not alone - Scaling multiplayer games

> 1,000,000 daily users

> 50,000 concurrent users

Page 11: You are not alone - Scaling multiplayer games

> 1,000,000 daily users

> 50,000 concurrent users

> 10,000 requests / second

Page 12: You are not alone - Scaling multiplayer games

Ok, you canhandle that.

Page 13: You are not alone - Scaling multiplayer games

Ok, you canhandle that.

But why onlysingle player?

Page 14: You are not alone - Scaling multiplayer games

The GamesThe Past

The PresentThe Future

The Foundation

Page 15: You are not alone - Scaling multiplayer games

Server Database

Page 16: You are not alone - Scaling multiplayer games

Server Database

Page 17: You are not alone - Scaling multiplayer games

Server Database

Page 18: You are not alone - Scaling multiplayer games

Server Database

Page 19: You are not alone - Scaling multiplayer games

Server Database

Page 20: You are not alone - Scaling multiplayer games

Server Database

Page 21: You are not alone - Scaling multiplayer games

DB is the bottleneck

Page 22: You are not alone - Scaling multiplayer games
Page 23: You are not alone - Scaling multiplayer games

Server Database

Page 24: You are not alone - Scaling multiplayer games

Server Database

Page 25: You are not alone - Scaling multiplayer games

Server Database

Page 26: You are not alone - Scaling multiplayer games

Server Database

One  Game  Session

Page 27: You are not alone - Scaling multiplayer games

Server Database

One  Game  Session

Page 28: You are not alone - Scaling multiplayer games

session

Page 29: You are not alone - Scaling multiplayer games

sessionsessionsessionsession

Page 30: You are not alone - Scaling multiplayer games

Server

sessionsessionsessionsession

Page 31: You are not alone - Scaling multiplayer games

Server

sessionsessionsessionsession

Page 32: You are not alone - Scaling multiplayer games

Server

sessionsessionsessionsession

Page 33: You are not alone - Scaling multiplayer games

Server

sessionsessionsessionsession

Page 34: You are not alone - Scaling multiplayer games

Server

sessionsessionsessionsession

Server

sessionsessionsessionsession

Server

sessionsessionsessionsession

Page 35: You are not alone - Scaling multiplayer games

The GamesThe Past

The PresentThe Future

The Foundation

ClientServer

Page 36: You are not alone - Scaling multiplayer games

ThoughtsClientServer

Operation

The GamesThe Past

The PresentThe Future

The Foundation

Page 37: You are not alone - Scaling multiplayer games

ThoughtsClientServer

Operation

The GamesThe Past

The PresentThe Future

The Foundation

Page 38: You are not alone - Scaling multiplayer games
Page 39: You are not alone - Scaling multiplayer games

You are not alone

Page 40: You are not alone - Scaling multiplayer games

Pessimistic

Page 41: You are not alone - Scaling multiplayer games

Pessimistic

Schizophrenic

Page 42: You are not alone - Scaling multiplayer games

Pessimistic

Schizophrenic

Optimistic

Page 43: You are not alone - Scaling multiplayer games

Pessimistic

Page 44: You are not alone - Scaling multiplayer games

ServerB

ClientA

ServerA

ClientB

Page 45: You are not alone - Scaling multiplayer games

ServerB

ServerA

ClientB

ClientA  @  B

Page 46: You are not alone - Scaling multiplayer games

ServerB

ServerA

ClientB

ClientA  @  B

Page 47: You are not alone - Scaling multiplayer games

ServerB

ServerA

ClientB

ClientA  @  B

Page 48: You are not alone - Scaling multiplayer games

ServerB’

ServerA

ClientB

ClientA  @  B

Page 49: You are not alone - Scaling multiplayer games

ServerB’

ServerA

ClientB

ClientA  @  B

Page 50: You are not alone - Scaling multiplayer games

ServerB’

ServerA

ClientB

ClientA  @  B

Page 51: You are not alone - Scaling multiplayer games

ServerB’

ServerA

ClientB

ClientA  @  B’

Page 52: You are not alone - Scaling multiplayer games

ServerB’

ServerA

ClientB

ClientA  @  B’

Page 53: You are not alone - Scaling multiplayer games

ServerB’

ServerA

ClientA  @  B’

ClientB’

Page 54: You are not alone - Scaling multiplayer games

Waiting on server responses?

Page 55: You are not alone - Scaling multiplayer games

Waiting on server responses?

Are you outof your mind?

Page 56: You are not alone - Scaling multiplayer games

Schizophrenic

Page 57: You are not alone - Scaling multiplayer games

ClientA

ServerA

ClientB

ServerB

Page 58: You are not alone - Scaling multiplayer games

ServerA

ClientB

ServerB

ClientA  @  B

Page 59: You are not alone - Scaling multiplayer games

ClientB

ServerB

ServerA  +  B

ClientA  @  B

Page 60: You are not alone - Scaling multiplayer games

ClientB

ServerB

ServerA  +  B

ClientA  @  B’

Page 61: You are not alone - Scaling multiplayer games

ClientB

ServerB

ServerA  +  B

ClientA  @  B’

Page 62: You are not alone - Scaling multiplayer games

ClientB

ServerB

ServerA  +  B’

ClientA  @  B’

Page 63: You are not alone - Scaling multiplayer games

ClientB

ServerB

ServerA  +  B’

ClientA  @  B’

Page 64: You are not alone - Scaling multiplayer games

ClientB

ServerB

ServerA  +  B’

ClientA  @  B’

Page 65: You are not alone - Scaling multiplayer games

ServerB

ServerA  +  B’

ClientA  @  B’

ClientB’

Page 66: You are not alone - Scaling multiplayer games

ServerB

ServerA  +  B’

ClientA  @  B’

ClientB’

Page 67: You are not alone - Scaling multiplayer games

ServerA  +  B’

ClientA  @  B’

ClientB’

ServerB’

Page 68: You are not alone - Scaling multiplayer games

What about real interactions?

Page 69: You are not alone - Scaling multiplayer games

What about real interactions?

And what about complexity

in the backend?

Page 70: You are not alone - Scaling multiplayer games

Optimistic

Page 71: You are not alone - Scaling multiplayer games

ClientA

ServerA

ClientB

ServerB

Page 72: You are not alone - Scaling multiplayer games

ServerA

ClientB

ServerB

ClientA  @  B

Page 73: You are not alone - Scaling multiplayer games

ServerA

ClientB

ServerB

ClientA  @  B’

Page 74: You are not alone - Scaling multiplayer games

ServerA

ClientB

ServerB

ClientA  @  B’

Page 75: You are not alone - Scaling multiplayer games

ServerA

ClientB

ServerB

ClientA  @  B’

Page 76: You are not alone - Scaling multiplayer games

ServerA

ClientB

ServerB’

ClientA  @  B’

Page 77: You are not alone - Scaling multiplayer games

ServerA

ClientB

ServerB’

ClientA  @  B’

Page 78: You are not alone - Scaling multiplayer games

ServerA

ClientB

ServerB’

ClientA  @  B’

Page 79: You are not alone - Scaling multiplayer games

ServerA

ServerB’

ClientA  @  B’

ClientB’’

Page 80: You are not alone - Scaling multiplayer games

ServerA

ServerB’

ClientA  @  B’

ClientB’’

Page 81: You are not alone - Scaling multiplayer games

ServerA

ServerB’

ClientA  @  B’

ClientB’’

Page 82: You are not alone - Scaling multiplayer games

ServerA

ServerB’

ClientA  @  B’

ClientB’

Page 83: You are not alone - Scaling multiplayer games

Hmm, client rollbacks?

Page 84: You are not alone - Scaling multiplayer games

Hmm, client rollbacks?

Are you sure you can build that?

Page 85: You are not alone - Scaling multiplayer games

The GamesThe Past

The PresentThe Future

The Foundation

Page 86: You are not alone - Scaling multiplayer games

The GamesThe Past

The PresentThe Future

The Foundation

ThoughtsClientServer

Operation

Page 87: You are not alone - Scaling multiplayer games

ClientA

ServerA

ClientB

ServerB

Page 88: You are not alone - Scaling multiplayer games
Page 89: You are not alone - Scaling multiplayer games
Page 90: You are not alone - Scaling multiplayer games

Client  A

Page 91: You are not alone - Scaling multiplayer games

Client  A

count  0max  3

state

Page 92: You are not alone - Scaling multiplayer games

Client  A

count  0max  3

state

move  

 

user  A

Page 93: You are not alone - Scaling multiplayer games

Client  A

count  0max  3

state

movepick

 

user  A

Page 94: You are not alone - Scaling multiplayer games

Client  A

count  1max  3

state

movepick

 

user  A

Page 95: You are not alone - Scaling multiplayer games

Client  A Server

count  1max  3

state

movepick

 

user  A

Page 96: You are not alone - Scaling multiplayer games

Client  A Server

user  A

count  1max  3

state

movepick

 

user  A

Page 97: You are not alone - Scaling multiplayer games

Client  A Server

count  0

loca,on

user  A

count  1max  3

state

movepick

 

user  A

Page 98: You are not alone - Scaling multiplayer games

Client  A Server

user  A

count  1max  3

state count  1

loca,on

movepick

 

user  A

Page 99: You are not alone - Scaling multiplayer games

Client  A Server

user  A

count  1max  3

state count  1

loca,on

movepick

 

user  A

Page 100: You are not alone - Scaling multiplayer games

Client  A Server

move  Apick  A

 

history

user  A

count  1max  3

state count  1

loca,on

movepick

 

user  A

Page 101: You are not alone - Scaling multiplayer games

move  Apick  A

   

history

Client  A

movepick    

user  A

count  1max  3

state count  1

loca,on

user  A

Server

Page 102: You are not alone - Scaling multiplayer games

move  Apick  A

   

history

Client  A

movepick    

user  A

count  1max  3

state count  1

loca,on

user  A

Server

Page 103: You are not alone - Scaling multiplayer games

move  Apick  A

   

history

Client  A

movepick    

user  A

count  1max  3

state count  1

loca,on

user  A

Server

user  B

Page 104: You are not alone - Scaling multiplayer games

move  Apick  A

   

history

Client  A

movepick    

user  A

count  1max  3

state count  1

loca,on

user  A

Server

loca,on

user  B

Page 105: You are not alone - Scaling multiplayer games

move  Apick  A

   

history

Client  A

movepick    

user  A

count  1max  3

state

user  A

Server

loca,on

user  B

count  2

loca,on

Page 106: You are not alone - Scaling multiplayer games

move  Apick  A

   

history

Client  A

movepick    

user  A

count  1max  3

state

user  A

Server

loca,on

user  B

count  2

loca,on

Page 107: You are not alone - Scaling multiplayer games

move  Apick  Apick  B

 

history

Client  A

movepick    

user  A

count  1max  3

state

user  A

Server

loca,on

user  B

count  2

loca,on

Page 108: You are not alone - Scaling multiplayer games

move  Apick  Apick  B

 

history

Client  A

movepick    

user  A

pick  

 

user  B

count  1max  3

state

user  A

Server

loca,on

user  B

count  2

loca,on

Page 109: You are not alone - Scaling multiplayer games

move  Apick  Apick  B

 

history

Client  A

movepick    

user  A

pick  

 

user  B

user  A

Server

loca,on

user  B

count  2max  3

state count  2

loca,on

Page 110: You are not alone - Scaling multiplayer games

pick  

 

user  B

movepick    

user  A

move  Apick  Apick  B

 

history

Client  A Server

count  2max  3

state count  2

loca,on

user  A

user  B

loca,on

Page 111: You are not alone - Scaling multiplayer games

pick  

 

user  B

movepickpick  

user  A

move  Apick  Apick  B

 

history

Client  A Server

count  2max  3

state count  2

loca,on

user  A

user  B

loca,on

Page 112: You are not alone - Scaling multiplayer games

pick  

 

user  B

movepickpick  

user  A

move  Apick  Apick  B

 

history

Client  A Server

count  2

loca,on

user  A

user  B

loca,on

count  3max  3

state

Page 113: You are not alone - Scaling multiplayer games

pick  

 

user  B

movepickpick  

user  A

move  Apick  Apick  B

 

history

Client  A Server

count  2

loca,on

user  A

user  B

loca,on

count  3max  3

state

Page 114: You are not alone - Scaling multiplayer games

pick  

 

user  B

movepickpick  

user  A

move  Apick  Apick  B

 

history

Client  A Server

count  2

loca,on

user  A

user  B

loca,on

count  3max  3

state

Page 115: You are not alone - Scaling multiplayer games

pick  

 

user  B

movepickpick  

user  A

move  Apick  Apick  B

 

history

Client  A Server

user  A

user  B

loca,on

count  3

loca,on

count  3max  3

state

Page 116: You are not alone - Scaling multiplayer games

pick  

 

user  B

movepickpick  

user  A

move  Apick  Apick  B

 

history

Client  A Server

user  A

user  B

loca,on

count  3

loca,on

count  3max  3

state

Page 117: You are not alone - Scaling multiplayer games

pick  

 

user  B

movepickpick  

user  A

move  Apick  Apick  B

 

history

Client  A Server

user  A

user  B

loca,on

count  3

loca,on

count  3max  3

state

Page 118: You are not alone - Scaling multiplayer games

pick  

 

user  B

movepickpick  

user  A

move  Apick  Apick  Bpick  B  

history

Client  A Server

user  A

user  B

loca,on

count  3

loca,on

count  3max  3

state

Page 119: You are not alone - Scaling multiplayer games

pickpick  

 

user  B

movepickpick  

user  A

move  Apick  Apick  Bpick  B  

history

Client  A Server

user  A

user  B

loca,on

count  3

loca,on

count  3max  3

state

Page 120: You are not alone - Scaling multiplayer games

pickpick  

 

user  B

movepickpick  

user  A

move  Apick  Apick  Bpick  B  

history

Client  A Server

user  A

user  B

loca,on

count  3

loca,on

count  3max  3

state

Page 121: You are not alone - Scaling multiplayer games

pickpick  

 

user  B

movepickpick  

user  A

move  Apick  Apick  Bpick  B  

history

Client  A Server

user  A

user  B

loca,on

count  3

loca,on

count  3max  3

state

Page 122: You are not alone - Scaling multiplayer games

pickpick  

 

user  B

movepickpick  

user  A

move  Apick  Apick  Bpick  B  

history

Client  A Server

user  A

user  B

loca,on

count  3

loca,on

count  3max  3

state

Page 123: You are not alone - Scaling multiplayer games

   

 

user  B

       

user  A

move  Apick  Apick  Bpick  B

history

Client  A Server

count  0max  3

state count  3

loca,on

user  A

user  B

loca,on

Page 124: You are not alone - Scaling multiplayer games

   

 

user  B

move  Apick  Apick  Bpick  B

history

Client  A Server

count  0max  3

state count  3

loca,on

user  A

user  B

loca,on

move      

user  A

Page 125: You are not alone - Scaling multiplayer games

   

 

user  B

move  Apick  Apick  Bpick  B

history

Client  A Server

count  3

loca,on

user  A

user  B

loca,on

movepick    

user  A

count  1max  3

state

Page 126: You are not alone - Scaling multiplayer games

move  Apick  Apick  Bpick  B

history

Client  A Server

count  3

loca,on

user  A

user  B

loca,on

movepick    

user  A

pick  

 

user  B

count  2max  3

state

Page 127: You are not alone - Scaling multiplayer games

move  Apick  Apick  Bpick  B

history

Client  A Server

count  3

loca,on

user  A

user  B

loca,on

movepick    

user  A

pickpick

 

user  B

count  3max  3

state

Page 128: You are not alone - Scaling multiplayer games

...

(Let’s lookinside)

Page 129: You are not alone - Scaling multiplayer games

The GamesThe Past

The PresentThe Future

The Foundation

Page 130: You are not alone - Scaling multiplayer games

The GamesThe Past

The PresentThe Future

The Foundation

ThoughtsClientServer

Operation

Page 131: You are not alone - Scaling multiplayer games

Erlang

Page 132: You are not alone - Scaling multiplayer games

Erlang

Process isolation

Page 133: You are not alone - Scaling multiplayer games

Erlang

Process isolation

Networking

Page 134: You are not alone - Scaling multiplayer games

Erlang

Process isolation

Networking

Distribution

Page 135: You are not alone - Scaling multiplayer games

User process

Page 136: You are not alone - Scaling multiplayer games

User process

Stores user state

Page 137: You are not alone - Scaling multiplayer games

User process

Stores user state

Real-time push to client

Page 138: You are not alone - Scaling multiplayer games

World process

Page 139: You are not alone - Scaling multiplayer games

World process

Serializes updates

Page 140: You are not alone - Scaling multiplayer games

World process

Serializes updates

Concurrency “control”

Page 141: You are not alone - Scaling multiplayer games

World process

Serializes updates

Concurrency “control”

Runs game logic

Page 142: You are not alone - Scaling multiplayer games

Game logic

Page 143: You are not alone - Scaling multiplayer games

Game logic

Pure

Page 144: You are not alone - Scaling multiplayer games

Game logic

Puref(State, Cmd) -> {NewState, Reply}

Page 145: You are not alone - Scaling multiplayer games

Game logic

Puref(State, Cmd) -> {NewState, Reply}

Transactions

Page 146: You are not alone - Scaling multiplayer games

Real-time push

Page 147: You are not alone - Scaling multiplayer games

Real-time push

Browser support

Page 148: You are not alone - Scaling multiplayer games

Real-time push

Browser support“Transfer-Encoding: chunked”

Page 149: You are not alone - Scaling multiplayer games

Real-time push

Browser support“Transfer-Encoding: chunked”

State updates as JSON

Page 150: You are not alone - Scaling multiplayer games

The GamesThe Past

The PresentThe Future

The Foundation

Page 151: You are not alone - Scaling multiplayer games

The GamesThe Past

The PresentThe Future

The Foundation

ThoughtsClientServer

Operation

Page 152: You are not alone - Scaling multiplayer games

Elli

Page 153: You are not alone - Scaling multiplayer games

Elli

Efficient, robust

Page 154: You are not alone - Scaling multiplayer games

Elli

Efficient, robust

High-throughput, low latency

Page 155: You are not alone - Scaling multiplayer games

Elli

Efficient, robust

High-throughput, low latency

Request-response model

Page 156: You are not alone - Scaling multiplayer games

Elli

Efficient, robust

High-throughput, low latency

Request-response model

github.com/knutin/elli

Page 157: You are not alone - Scaling multiplayer games

Distribution

Page 158: You are not alone - Scaling multiplayer games

Distribution

Idea: Identical nodes, Riak

Page 159: You are not alone - Scaling multiplayer games

Distribution

Idea: Identical nodes, Riak

No centralization/serialization

Page 160: You are not alone - Scaling multiplayer games

Distribution

Idea: Identical nodes, Riak

No centralization/serialization

No SPOF

Page 161: You are not alone - Scaling multiplayer games

Distribution needs

Page 162: You are not alone - Scaling multiplayer games

Distribution needs

Locking

Page 163: You are not alone - Scaling multiplayer games

Distribution needs

Locking

Dynamic cluster

Page 164: You are not alone - Scaling multiplayer games

Meet “locker”

Page 165: You are not alone - Scaling multiplayer games

Meet “locker”

Distributed lock table

Page 166: You are not alone - Scaling multiplayer games

Meet “locker”

Distributed lock table

CAS

Page 167: You are not alone - Scaling multiplayer games

Meet “locker”

Distributed lock table

CAS

Write quorum, 2PC

Page 168: You are not alone - Scaling multiplayer games

Meet “locker”

Distributed lock table

CAS

Write quorum, 2PC

Asynchronous replication

Page 169: You are not alone - Scaling multiplayer games

Meet “locker”

Distributed lock table

CAS

Write quorum, 2PC

Asynchronous replication

330 SLOC, one gen_server

Page 170: You are not alone - Scaling multiplayer games

The GamesThe Past

The PresentThe Future

The Foundation

Page 171: You are not alone - Scaling multiplayer games

Research

Page 172: You are not alone - Scaling multiplayer games

Research

Aka “hacking”

Page 173: You are not alone - Scaling multiplayer games

Everything is possible

Page 174: You are not alone - Scaling multiplayer games

Everything is possible

First person

Page 175: You are not alone - Scaling multiplayer games

Everything is possible

First person

Real-time strategy

Page 176: You are not alone - Scaling multiplayer games

Everything is possible

First person

Real-time strategy

Turn-based

Page 177: You are not alone - Scaling multiplayer games

Everything is possible

First person

Real-time strategy

Turn-based

Etc

Page 178: You are not alone - Scaling multiplayer games

Nothing is possible

Page 179: You are not alone - Scaling multiplayer games

Nothing is possible

Network latency kills gameplay

Page 180: You are not alone - Scaling multiplayer games

Lag compensation

Page 181: You are not alone - Scaling multiplayer games

Lag compensation

Many solutions

Page 182: You are not alone - Scaling multiplayer games

Lag compensation

Many solutions

Depends on game

Page 183: You are not alone - Scaling multiplayer games

FPS

Page 184: You are not alone - Scaling multiplayer games

FPS

Speed is king

Page 185: You are not alone - Scaling multiplayer games

FPS

Speed is king

Divergent simulations

Page 186: You are not alone - Scaling multiplayer games

FPS

Speed is king

Divergent simulations

Server keeps history

Page 187: You are not alone - Scaling multiplayer games

FPS

Speed is king

Divergent simulations

Server keeps history

Validates delayed commands

Page 188: You are not alone - Scaling multiplayer games

RTS

Page 189: You are not alone - Scaling multiplayer games

RTS

Synchronization is king

Page 190: You are not alone - Scaling multiplayer games

RTS

Synchronization is king

Identical simulations

Page 191: You are not alone - Scaling multiplayer games

RTS

Synchronization is king

Identical simulations

Server buffers commands

Page 192: You are not alone - Scaling multiplayer games

RTS

Synchronization is king

Identical simulations

Server buffers commands

Broadcasts, lockstep

Page 193: You are not alone - Scaling multiplayer games

The GamesThe Past

The PresentThe Future

The Foundation

Page 194: You are not alone - Scaling multiplayer games

Small independent teams

Page 195: You are not alone - Scaling multiplayer games

Each team adds something

Page 196: You are not alone - Scaling multiplayer games

Based on previous learnings

Page 197: You are not alone - Scaling multiplayer games

Standing on the

shoulders of giants

Page 198: You are not alone - Scaling multiplayer games

Slides: http://woo.ga/backend

Page 199: You are not alone - Scaling multiplayer games

Slides: http://woo.ga/backendCode: http://github.com/wooga

Page 200: You are not alone - Scaling multiplayer games

Questions?

Page 201: You are not alone - Scaling multiplayer games

Questions?

@jrirei @knutinhttp://wooga.com/jobs