you are not alone - scaling multiplayer games

Post on 14-Nov-2014

6.155 Views

Category:

Technology

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

At Wooga we are creating the next generation of social games. To be truly social, a game needs to offer real interaction between players in different forms. Taking one of our upcoming games as an example we will present the state synchronization used in client and server, how we do real time communication without websockets and how we are making a backend scalable enough to support millions of users every day. We will also share secrets about our prototypes for first person and real time strategy games. The Erlang process model with evented IO, asynchronous messaging, links and isolation fits very well to real time multiplayer games. Come to our talk to see how it's used to build a very successful business.

TRANSCRIPT

You are not aloneScaling Multiplayer Games

Jesper Richter-Reichhelm - @jrireiKnut Nesheim - @knutin

> 1,000,000 daily users

> 1,000,000 daily users

> 50,000 concurrent users

> 1,000,000 daily users

> 50,000 concurrent users

> 10,000 requests / second

Ok, you canhandle that.

Ok, you canhandle that.

But why onlysingle player?

The GamesThe Past

The PresentThe Future

The Foundation

Server Database

Server Database

Server Database

Server Database

Server Database

Server Database

DB is the bottleneck

Server Database

Server Database

Server Database

Server Database

One  Game  Session

Server Database

One  Game  Session

session

sessionsessionsessionsession

Server

sessionsessionsessionsession

Server

sessionsessionsessionsession

Server

sessionsessionsessionsession

Server

sessionsessionsessionsession

Server

sessionsessionsessionsession

Server

sessionsessionsessionsession

Server

sessionsessionsessionsession

The GamesThe Past

The PresentThe Future

The Foundation

ClientServer

ThoughtsClientServer

Operation

The GamesThe Past

The PresentThe Future

The Foundation

ThoughtsClientServer

Operation

The GamesThe Past

The PresentThe Future

The Foundation

You are not alone

Pessimistic

Pessimistic

Schizophrenic

Pessimistic

Schizophrenic

Optimistic

Pessimistic

ServerB

ClientA

ServerA

ClientB

ServerB

ServerA

ClientB

ClientA  @  B

ServerB

ServerA

ClientB

ClientA  @  B

ServerB

ServerA

ClientB

ClientA  @  B

ServerB’

ServerA

ClientB

ClientA  @  B

ServerB’

ServerA

ClientB

ClientA  @  B

ServerB’

ServerA

ClientB

ClientA  @  B

ServerB’

ServerA

ClientB

ClientA  @  B’

ServerB’

ServerA

ClientB

ClientA  @  B’

ServerB’

ServerA

ClientA  @  B’

ClientB’

Waiting on server responses?

Waiting on server responses?

Are you outof your mind?

Schizophrenic

ClientA

ServerA

ClientB

ServerB

ServerA

ClientB

ServerB

ClientA  @  B

ClientB

ServerB

ServerA  +  B

ClientA  @  B

ClientB

ServerB

ServerA  +  B

ClientA  @  B’

ClientB

ServerB

ServerA  +  B

ClientA  @  B’

ClientB

ServerB

ServerA  +  B’

ClientA  @  B’

ClientB

ServerB

ServerA  +  B’

ClientA  @  B’

ClientB

ServerB

ServerA  +  B’

ClientA  @  B’

ServerB

ServerA  +  B’

ClientA  @  B’

ClientB’

ServerB

ServerA  +  B’

ClientA  @  B’

ClientB’

ServerA  +  B’

ClientA  @  B’

ClientB’

ServerB’

What about real interactions?

What about real interactions?

And what about complexity

in the backend?

Optimistic

ClientA

ServerA

ClientB

ServerB

ServerA

ClientB

ServerB

ClientA  @  B

ServerA

ClientB

ServerB

ClientA  @  B’

ServerA

ClientB

ServerB

ClientA  @  B’

ServerA

ClientB

ServerB

ClientA  @  B’

ServerA

ClientB

ServerB’

ClientA  @  B’

ServerA

ClientB

ServerB’

ClientA  @  B’

ServerA

ClientB

ServerB’

ClientA  @  B’

ServerA

ServerB’

ClientA  @  B’

ClientB’’

ServerA

ServerB’

ClientA  @  B’

ClientB’’

ServerA

ServerB’

ClientA  @  B’

ClientB’’

ServerA

ServerB’

ClientA  @  B’

ClientB’

Hmm, client rollbacks?

Hmm, client rollbacks?

Are you sure you can build that?

The GamesThe Past

The PresentThe Future

The Foundation

The GamesThe Past

The PresentThe Future

The Foundation

ThoughtsClientServer

Operation

ClientA

ServerA

ClientB

ServerB

Client  A

Client  A

count  0max  3

state

Client  A

count  0max  3

state

move  

 

user  A

Client  A

count  0max  3

state

movepick

 

user  A

Client  A

count  1max  3

state

movepick

 

user  A

Client  A Server

count  1max  3

state

movepick

 

user  A

Client  A Server

user  A

count  1max  3

state

movepick

 

user  A

Client  A Server

count  0

loca,on

user  A

count  1max  3

state

movepick

 

user  A

Client  A Server

user  A

count  1max  3

state count  1

loca,on

movepick

 

user  A

Client  A Server

user  A

count  1max  3

state count  1

loca,on

movepick

 

user  A

Client  A Server

move  Apick  A

 

history

user  A

count  1max  3

state count  1

loca,on

movepick

 

user  A

move  Apick  A

   

history

Client  A

movepick    

user  A

count  1max  3

state count  1

loca,on

user  A

Server

move  Apick  A

   

history

Client  A

movepick    

user  A

count  1max  3

state count  1

loca,on

user  A

Server

move  Apick  A

   

history

Client  A

movepick    

user  A

count  1max  3

state count  1

loca,on

user  A

Server

user  B

move  Apick  A

   

history

Client  A

movepick    

user  A

count  1max  3

state count  1

loca,on

user  A

Server

loca,on

user  B

move  Apick  A

   

history

Client  A

movepick    

user  A

count  1max  3

state

user  A

Server

loca,on

user  B

count  2

loca,on

move  Apick  A

   

history

Client  A

movepick    

user  A

count  1max  3

state

user  A

Server

loca,on

user  B

count  2

loca,on

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

   

 

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

   

 

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

   

 

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

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

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

...

(Let’s lookinside)

The GamesThe Past

The PresentThe Future

The Foundation

The GamesThe Past

The PresentThe Future

The Foundation

ThoughtsClientServer

Operation

Erlang

Erlang

Process isolation

Erlang

Process isolation

Networking

Erlang

Process isolation

Networking

Distribution

User process

User process

Stores user state

User process

Stores user state

Real-time push to client

World process

World process

Serializes updates

World process

Serializes updates

Concurrency “control”

World process

Serializes updates

Concurrency “control”

Runs game logic

Game logic

Game logic

Pure

Game logic

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

Game logic

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

Transactions

Real-time push

Real-time push

Browser support

Real-time push

Browser support“Transfer-Encoding: chunked”

Real-time push

Browser support“Transfer-Encoding: chunked”

State updates as JSON

The GamesThe Past

The PresentThe Future

The Foundation

The GamesThe Past

The PresentThe Future

The Foundation

ThoughtsClientServer

Operation

Elli

Elli

Efficient, robust

Elli

Efficient, robust

High-throughput, low latency

Elli

Efficient, robust

High-throughput, low latency

Request-response model

Elli

Efficient, robust

High-throughput, low latency

Request-response model

github.com/knutin/elli

Distribution

Distribution

Idea: Identical nodes, Riak

Distribution

Idea: Identical nodes, Riak

No centralization/serialization

Distribution

Idea: Identical nodes, Riak

No centralization/serialization

No SPOF

Distribution needs

Distribution needs

Locking

Distribution needs

Locking

Dynamic cluster

Meet “locker”

Meet “locker”

Distributed lock table

Meet “locker”

Distributed lock table

CAS

Meet “locker”

Distributed lock table

CAS

Write quorum, 2PC

Meet “locker”

Distributed lock table

CAS

Write quorum, 2PC

Asynchronous replication

Meet “locker”

Distributed lock table

CAS

Write quorum, 2PC

Asynchronous replication

330 SLOC, one gen_server

The GamesThe Past

The PresentThe Future

The Foundation

Research

Research

Aka “hacking”

Everything is possible

Everything is possible

First person

Everything is possible

First person

Real-time strategy

Everything is possible

First person

Real-time strategy

Turn-based

Everything is possible

First person

Real-time strategy

Turn-based

Etc

Nothing is possible

Nothing is possible

Network latency kills gameplay

Lag compensation

Lag compensation

Many solutions

Lag compensation

Many solutions

Depends on game

FPS

FPS

Speed is king

FPS

Speed is king

Divergent simulations

FPS

Speed is king

Divergent simulations

Server keeps history

FPS

Speed is king

Divergent simulations

Server keeps history

Validates delayed commands

RTS

RTS

Synchronization is king

RTS

Synchronization is king

Identical simulations

RTS

Synchronization is king

Identical simulations

Server buffers commands

RTS

Synchronization is king

Identical simulations

Server buffers commands

Broadcasts, lockstep

The GamesThe Past

The PresentThe Future

The Foundation

Small independent teams

Each team adds something

Based on previous learnings

Standing on the

shoulders of giants

Slides: http://woo.ga/backend

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

Questions?

Questions?

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

top related