scalability & big data challenges in real time multiplayer games

108
Scalability & Big Data challenges in Real-Time Multiplayer games

Upload: yan-cui

Post on 23-Jan-2018

1.795 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Scalability & Big Data challenges in real time multiplayer games

Scalability & Big Data challenges in Real-Time Multiplayer

games

Page 2: Scalability & Big Data challenges in real time multiplayer games

Real-Time games in Top 100 Grossing (2017)

2014

2015

2016

2017

(3)

(6)

(8)

(13)

2018 ???

Page 3: Scalability & Big Data challenges in real time multiplayer games

Enabling Factors

Source: PC Mag

Page 4: Scalability & Big Data challenges in real time multiplayer games

Enabling Factors

Source: OpenSignal

Page 5: Scalability & Big Data challenges in real time multiplayer games

Enabling Factors

Page 6: Scalability & Big Data challenges in real time multiplayer games

QUIZ TIME: In 2017, which of these games has made the most revenue?

The world’s most popular MOBA on PC

The world’s most popular First Person Shooter Some game by Blizzard

Some game by EA A Chinese 5v5 mobile game you never hear of Some game by King

Page 7: Scalability & Big Data challenges in real time multiplayer games

The world’s most popular MOBA on PC

The world’s most popular First Person Shooter Some game by Blizzard

Some game by EA A Chinese 5v5 mobile game you never heard of Some game by King

QUIZ TIME: In 2017, which of these games has made the most revenue?

Page 8: Scalability & Big Data challenges in real time multiplayer games

>$400M Monthly RevenueSource: Bloomberg

>80M DAUSource: Tencent

Page 9: Scalability & Big Data challenges in real time multiplayer games
Page 10: Scalability & Big Data challenges in real time multiplayer games

10-20 inputs/s, sensitive to lags (> 300ms)

Page 11: Scalability & Big Data challenges in real time multiplayer games

unpredictable network, limited bandwidth

Page 12: Scalability & Big Data challenges in real time multiplayer games
Page 13: Scalability & Big Data challenges in real time multiplayer games

Decisions, decisions...Build vs Buy?

Self-hosted vs Cloud?

Global deployment vs Centralized?

TCP vs UDP?

Server Authoritative vs Lock-Step?

Page 14: Scalability & Big Data challenges in real time multiplayer games

Constraints/Trade-offs

Latency (RTT)

Cost

Complexity

Scalability

Operational overhead

Page 15: Scalability & Big Data challenges in real time multiplayer games

Global Deployment

vs

Centralised

Page 16: Scalability & Big Data challenges in real time multiplayer games
Page 17: Scalability & Big Data challenges in real time multiplayer games
Page 18: Scalability & Big Data challenges in real time multiplayer games

10-20 inputs/s, sensitive to lags (> 300ms)

Page 19: Scalability & Big Data challenges in real time multiplayer games
Page 20: Scalability & Big Data challenges in real time multiplayer games
Page 21: Scalability & Big Data challenges in real time multiplayer games

optimize for this

Page 22: Scalability & Big Data challenges in real time multiplayer games

Global Deployment● Players are geo-routed to closest multiplayer server.

● Matched with other players in the same geo-region for best UX.

● No need for players to “choose server”, it should just work.

Page 23: Scalability & Big Data challenges in real time multiplayer games

Global Deployment● Should leaderboards be global or regional?

● Should guilds/alliances be global or regional?

● Should chatrooms be global or regional?

● Should liveops events be global or regional?

● Should players be allowed to play with others in another region? ie. play with distant relatives/friends.

● Should players be allowed to switch default region? eg. moved to Europe after Brexit

Page 24: Scalability & Big Data challenges in real time multiplayer games

Server Authoritative

vs

Lock-Step

Page 25: Scalability & Big Data challenges in real time multiplayer games

Server Authoritative● Server decides game logic.

● Client sends all inputs to server.

● Client receives game state (either full, or delta) from server.

Page 26: Scalability & Big Data challenges in real time multiplayer games

Server Authoritative● Server decides game logic.

● Client sends all inputs to server.

● Client receives game state (either full, or delta) from server.

● Client keeps internal state for game world, which mirrors server state.

● Client doesn’t modify world state directly, only display with some prediction to mask network latency.

Page 27: Scalability & Big Data challenges in real time multiplayer games

Client 1 Client 2Server

C1 control 1 C2 control 1

game state 1

Page 28: Scalability & Big Data challenges in real time multiplayer games

Client 1 Client 2Server

C1 control 1 C2 control 1

C2 control 2game state 1

game state 2

Page 29: Scalability & Big Data challenges in real time multiplayer games

Client 1 Client 2Server

C1 control 1 C2 control 1

C2 control 2game state 1

game state 2

Page 30: Scalability & Big Data challenges in real time multiplayer games

Client 1 Client 2Server

C1 control 1 C2 control 1

C2 control 2game state 1

game state 2

game state 3C1 control 1C2 control 1C2 control 2

game state 3C1 control 1C2 control 1C2 control 2

C2 control 3

Page 31: Scalability & Big Data challenges in real time multiplayer games

Client 1 Client 2Server

C1 control 1 C2 control 1

C2 control 2

C2 control 3

game state 1

game state 2

game state 3C1 control 1C2 control 1C2 control 2

game state 3C1 control 1C2 control 1C2 control 2

game state 4

Page 32: Scalability & Big Data challenges in real time multiplayer games

Client 1 Client 2Server

C1 control 1 C2 control 1

C2 control 2

C2 control 3

game state 1

game state 2

game state 3C1 control 1C2 control 1C2 control 2

game state 3C1 control 1C2 control 1C2 control 2

game state 4

Page 33: Scalability & Big Data challenges in real time multiplayer games

Client 1 Client 2Server

C1 control 1 C2 control 1

C2 control 2

C2 control 3

game state 1

game state 2

game state 3C1 control 1C2 control 1C2 control 2

game state 3C1 control 1C2 control 1C2 control 2

game state 5C2 control 3

game state 4

Page 34: Scalability & Big Data challenges in real time multiplayer games

Client 1 Client 2Server

C1 control 1 C2 control 1

C2 control 2

C2 control 3

game state 1

game state 2

game state 3C1 control 1C2 control 1C2 control 2

game state 3C1 control 1C2 control 1C2 control 2

game state 5C2 control 3

game state 4

Page 35: Scalability & Big Data challenges in real time multiplayer games
Page 36: Scalability & Big Data challenges in real time multiplayer games

Pros● Always in-sync.

● Hard to cheat - no memory hacks, etc.

● Easy (and quick) to join mid-match.

● Server can detect lagged/DC’d client and take over with AI.

Page 37: Scalability & Big Data challenges in real time multiplayer games

Cons● High server load.

● High bandwidth usage.

● Synchronization on the client is complicated.

● Little experience in the company with server-side .Net stack. (bus factor of 1)

● .NetCore was/is still a moving target.

Page 38: Scalability & Big Data challenges in real time multiplayer games

high server load and bandwidth needs

client has to receive more data

Page 39: Scalability & Big Data challenges in real time multiplayer games

Lock-Step*● Client sends all inputs to server.

● Server collects all inputs, and buffers them.

● Server sends all buffered inputs to all clients X times a second.

* traditional RTS games tend to use peer-to-peer model

Page 40: Scalability & Big Data challenges in real time multiplayer games

Lock-Step*● Client sends all inputs to server.

● Server collects all inputs, and buffers them.

● Server sends all buffered inputs to all clients X times a second.

● Client executes all inputs in the same order.

● Because everyone is 'guaranteed' to have executed the same input at the same frame in the same order, we get synchronicity.

● Use prediction to mask network latency.

* traditional RTS games tend to use peer-to-peer model

Page 41: Scalability & Big Data challenges in real time multiplayer games

Client 1 Client 2Server

C1 control 1 C2 control 1

C2 control 2

C2 control 3

C1 control 1C2 control 1C2 control 2

C1 control 1C2 control 1C2 control 2

C2 control 3

inputs, instead of game state

Page 42: Scalability & Big Data challenges in real time multiplayer games

Client 1 Client 2Server

C1 control 1 C2 control 1

C2 control 2

C2 control 3

C1 control 1C2 control 1C2 control 2

C1 control 1C2 control 1C2 control 2

C2 control 3

RTT: time between sending an input to receiving it back from server

Page 43: Scalability & Big Data challenges in real time multiplayer games

Client 1 Client 2Server

C1 control 1 C2 control 1

C2 control 2

C2 control 3

C1 control 1C2 control 1C2 control 2

C1 control 1C2 control 1C2 control 2

C2 control 3

Page 44: Scalability & Big Data challenges in real time multiplayer games

Client 1 Client 2Server

C1 control 1 C2 control 1

C2 control 2

C2 control 3

C1 control 1C2 control 1C2 control 2

C1 control 1C2 control 1C2 control 2

C2 control 3

RTTframe time

Page 45: Scalability & Big Data challenges in real time multiplayer games

Client 1 Client 2Server

C1 control 1 C2 control 1

C2 control 2

C2 control 3

C1 control 1C2 control 1C2 control 2

C1 control 1C2 control 1C2 control 2

C2 control 3

RTTframe time

RTT = latency x 2 + XXmin = 0, Xmax = frame time

Page 46: Scalability & Big Data challenges in real time multiplayer games
Page 47: Scalability & Big Data challenges in real time multiplayer games

Pros● Light server load.

● Lower bandwidth usage.

● Simpler server implementation.

Page 48: Scalability & Big Data challenges in real time multiplayer games

Cons● Needs deterministic game engine.

● Unity has long-standing determinism problem with floating point.

● Hackable, requires some form of server-side validation.

● All clients must take over lagged/DC’d client with AI.

● Slower to join mid-match, need to process all inputs.

● Need to ensure all clients in a match are compatible.

Page 49: Scalability & Big Data challenges in real time multiplayer games

fix-point math, server validation, ...

Page 50: Scalability & Big Data challenges in real time multiplayer games
Page 51: Scalability & Big Data challenges in real time multiplayer games
Page 52: Scalability & Big Data challenges in real time multiplayer games

bandwidth

Page 53: Scalability & Big Data challenges in real time multiplayer games

Build vs Buy

Page 54: Scalability & Big Data challenges in real time multiplayer games
Page 55: Scalability & Big Data challenges in real time multiplayer games

Pros● Easy to use.

● Already use it for prototype games.

● Multi-region, lobby, etc. come out-of-the-box.

● Had a long time to optimize their solution.

Page 56: Scalability & Big Data challenges in real time multiplayer games

Cons● Quite expensive, pay for provisioned peak monthly CCU.

● “can we bet the future of our company on a third-party?”.

● Unknown global distribution at scale

● Accessibility of support.

● Limited extensibility.

● Runs on Windows.

Page 57: Scalability & Big Data challenges in real time multiplayer games

So, we decided to build our own networking stack

Page 58: Scalability & Big Data challenges in real time multiplayer games

+

Page 59: Scalability & Big Data challenges in real time multiplayer games

A model for describing computation, coined by Carl Hewitt & co in 1973.

Later popularised by Erlang.

Actor Model

Carl Hewitt

Page 60: Scalability & Big Data challenges in real time multiplayer games

Everything is an actor. Every actor has a mailbox.

An actor is the fundamental unit that embodies the 3 essential things for computation:● processing● storage● communications

Actor Model

Page 61: Scalability & Big Data challenges in real time multiplayer games

Actors don’t share memory, they communicate only via messages.

When an actor receives a message, it can:● create new actors● send messages to other actors● do work

Actor Model

Page 62: Scalability & Big Data challenges in real time multiplayer games

Actors don’t share memory, they communicate only via messages.

When an actor receives a message, it can:● create new actors● send messages to other actors● do work

Actor Model Johnny?

Not sharing memory prevents cascade failures when an actor crashes.

Page 63: Scalability & Big Data challenges in real time multiplayer games
Page 64: Scalability & Big Data challenges in real time multiplayer games

Ericsson AXD301

Page 65: Scalability & Big Data challenges in real time multiplayer games

Inside an actor, messages are processed one-at-a-time, in a single-threaded fashion.

No need for locks!

Actor Model

single-threaded

Page 66: Scalability & Big Data challenges in real time multiplayer games

Inside an actor, messages are processed one-at-a-time, in a single-threaded fashion.

No need for locks!

Simplifies concurrency, no deadlocks, race conditions, etc.

Actor Model

single-threaded

Page 67: Scalability & Big Data challenges in real time multiplayer games

Lifts concurrency management to the mailbox.

Allows you to “think globally, but act locally”.

Actor Model

Page 68: Scalability & Big Data challenges in real time multiplayer games

Lifts concurrency management to the mailbox.

Allows you to “think globally, but act locally”.

Easier to think about a complex system in terms of states and transitions, than to manage state mutations.

Actor Model

Page 69: Scalability & Big Data challenges in real time multiplayer games

MATCH 1

C1 input

C2 input

current frame historyframe 1

frame 2

frame 3

buffering

Page 70: Scalability & Big Data challenges in real time multiplayer games

connection open

MATCH 1

C1 input

C2 input

current frame historyframe 1

frame 2

frame 3

buffering

Page 71: Scalability & Big Data challenges in real time multiplayer games

connection open

authenticate

MATCH 1

C1 input

C2 input

current frame historyframe 1

frame 2

frame 3C3 joined

buffering

Page 72: Scalability & Big Data challenges in real time multiplayer games

connection open

authenticate

send/receive

MATCH 1

C1 input

C2 input

current frame historyframe 1

frame 2

frame 3C3 joined

buffering

Page 73: Scalability & Big Data challenges in real time multiplayer games

MATCH 1

C1 input

C2 input

current frame historyframe 1

frame 2

frame 3C3 joined

C3 input

connection open

authenticate

send/receive

buffering

Page 74: Scalability & Big Data challenges in real time multiplayer games

MATCH 1

C1 input

C2 input

current frame historyframe 1

frame 2

frame 3C3 joined

C3 input

connection open

authenticate

send/receive

buffering

broadcast!

Page 75: Scalability & Big Data challenges in real time multiplayer games

MATCH 1

current frame historyframe 1

frame 2

frame 3

C1 input C2 input C3 joined C3 input

connection open

authenticate

send/receive

buffering

broadcast!

Page 76: Scalability & Big Data challenges in real time multiplayer games

MATCH 1

current frame historyframe 1

frame 2

frame 3

frame 4

connection open

authenticate

send/receive

buffering

broadcast!

Page 77: Scalability & Big Data challenges in real time multiplayer games

MATCH 1

current frame historyframe 1

frame 2

frame 3

frame 4

connection open

authenticate

send/receive

buffering

broadcast!C3 input

Page 78: Scalability & Big Data challenges in real time multiplayer games
Page 79: Scalability & Big Data challenges in real time multiplayer games

concurrency

Page 80: Scalability & Big Data challenges in real time multiplayer games

MATCH 1

current frame historyframe 1

frame 2

frame 3

...

C1 input C2 input C3 joined C3 input

connection open

authenticate

send/receive

buffering

broadcast!

C1 input

Page 81: Scalability & Big Data challenges in real time multiplayer games

MATCH 1

current frame historyframe 1

frame 2

frame 3

...

C1 input C2 input C3 joined C3 input

buffering

broadcast!

C1 inputC2 input

Page 82: Scalability & Big Data challenges in real time multiplayer games

MATCH MATCH MATCH MATCH MATCH

Page 83: Scalability & Big Data challenges in real time multiplayer games

MATCH MATCH MATCH MATCH MATCH

MATCH MATCH MATCH MATCH MATCH

Page 84: Scalability & Big Data challenges in real time multiplayer games

MATCH MATCH MATCH MATCH MATCH

MATCH MATCH MATCH MATCH MATCH

MATCH MATCH MATCH MATCH MATCH

Page 85: Scalability & Big Data challenges in real time multiplayer games

MATCH

C1 input

C2 input

current frame historyframe 1

frame 2

frame 3C3 joined

connection open

authenticate

send/receivebuffering

broadcast!

Page 86: Scalability & Big Data challenges in real time multiplayer games

MATCH

C1 input C2 input

current frame historyframe 1

frame 2

frame 3C3 joined

connection open

authenticate

send/receivebuffering

broadcast!

Page 87: Scalability & Big Data challenges in real time multiplayer games

MATCH

current frame historyframe 1

frame 2

frame 3

C1 input

C2 input

C3 joined

Socket actor

Match actor

Page 88: Scalability & Big Data challenges in real time multiplayer games

MATCH

current frame historyframe 1

frame 2

frame 3

C1 input

C2 input

C3 joined

Root Aggregate

Socket actor

Match actor

Page 89: Scalability & Big Data challenges in real time multiplayer games

MATCH

current frame historyframe 1

frame 2

frame 3

C1 input

C2 input

C3 joined

Root Aggregate

Socket actor

Match actor

Page 90: Scalability & Big Data challenges in real time multiplayer games

MATCH

current frame historyframe 1

frame 2

frame 3

C1 input

C2 input

C3 joined

Page 91: Scalability & Big Data challenges in real time multiplayer games

MATCH

current frame historyframe 1

frame 2

frame 3

C1 input

C2 input

C3 joined

C3 joined

act locally

think globallyhow actors interact with each other

aka, the “protocol”

Page 92: Scalability & Big Data challenges in real time multiplayer games
Page 93: Scalability & Big Data challenges in real time multiplayer games
Page 94: Scalability & Big Data challenges in real time multiplayer games

the secret to building high performance systems is simplicity

complexity kills performance

Page 95: Scalability & Big Data challenges in real time multiplayer games

Higher CCU per server

Fewer servers

Lower cost

Less operational overhead

Performance Matters

Page 96: Scalability & Big Data challenges in real time multiplayer games

We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3%.

Performance Matters

Page 97: Scalability & Big Data challenges in real time multiplayer games

We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3%.

Performance Matters

Page 98: Scalability & Big Data challenges in real time multiplayer games

Threads are heavy OS constructs.

Each thread is allocated 1MB stack space by default.

Context Switching is expensive at scale.

Actors are cheap.

Actor system can optimise use of threads to minimise context switching.

Actor Model >

Page 99: Scalability & Big Data challenges in real time multiplayer games

Non-blocking I/O framework for JVM.

Highly performant.

Simplifies implementation of socket servers (TCP/ UDP).

UDP support is “meh”...

Netty

Page 100: Scalability & Big Data challenges in real time multiplayer games

Custom network protocol (bandwidth).

Buffer pooling (GC pressure).

Minimise Netty object creations (GC pressure).

Using direct buffers (GC pressure).

Disable Nagle's algorithm (latency).

Epoll.

Performance Tuning

Page 101: Scalability & Big Data challenges in real time multiplayer games

AWS Lambda functions to run bot clients (written with Akka):

● Cheaper● Faster to boot up● Easy to update

Each Lambda invocation could simulate up to 100 bots.

Automated Load Testing

Page 102: Scalability & Big Data challenges in real time multiplayer games
Page 103: Scalability & Big Data challenges in real time multiplayer games
Page 104: Scalability & Big Data challenges in real time multiplayer games

from US-EAST (Lambda) to EU-WEST (game server)

Page 105: Scalability & Big Data challenges in real time multiplayer games

optimize for tail latencies

from US-EAST (Lambda) to EU-WEST (game server)

Page 106: Scalability & Big Data challenges in real time multiplayer games

http://bit.ly/2xgGHXZ

Page 107: Scalability & Big Data challenges in real time multiplayer games

Thank You!

Page 108: Scalability & Big Data challenges in real time multiplayer games

QUESTIONS?