f# in social gaming by yan cui at codemotion dubai

210

Upload: codemotion-dubai

Post on 11-Apr-2017

136 views

Category:

Business


1 download

TRANSCRIPT

Page 1: F# in social gaming by Yan Cui at Codemotion Dubai
Page 2: F# in social gaming by Yan Cui at Codemotion Dubai

Hi, my name is Yan Cui.

Page 3: F# in social gaming by Yan Cui at Codemotion Dubai

Jan 2010

Nov 2015

Apr 2016

Page 4: F# in social gaming by Yan Cui at Codemotion Dubai

F#in�theReal�World

Page 5: F# in social gaming by Yan Cui at Codemotion Dubai

agenda

Page 6: F# in social gaming by Yan Cui at Codemotion Dubai

Domain ModellingInfrastructureGame LogicAlgorithms

DSLs

Page 7: F# in social gaming by Yan Cui at Codemotion Dubai

1MILLION USERS

ACTIVEDAILY

Page 8: F# in social gaming by Yan Cui at Codemotion Dubai

250MILLION DAY

PERREQUEST

Page 9: F# in social gaming by Yan Cui at Codemotion Dubai

2MONTH

TBP E R

secops25,000

Page 10: F# in social gaming by Yan Cui at Codemotion Dubai

we are polyglot

C#

Page 11: F# in social gaming by Yan Cui at Codemotion Dubai

why F#?

Page 12: F# in social gaming by Yan Cui at Codemotion Dubai

time to market

Page 13: F# in social gaming by Yan Cui at Codemotion Dubai

correctness

Page 14: F# in social gaming by Yan Cui at Codemotion Dubai

efficient

Page 15: F# in social gaming by Yan Cui at Codemotion Dubai

tame complexity

Page 16: F# in social gaming by Yan Cui at Codemotion Dubai
Page 17: F# in social gaming by Yan Cui at Codemotion Dubai

Collectables

Wager Size

Special SymbolAvg Wager Size

Web Server call

Page 18: F# in social gaming by Yan Cui at Codemotion Dubai

• Line Win– X number of matching symbols on adjacent columns– Positions have to be a ‘line’– Wild symbols substitute for other symbols

• Scatter Win– X number of matching symbols anywhere– Triggers bonus game

Page 19: F# in social gaming by Yan Cui at Codemotion Dubai

What symbols should land?Any special symbol wins?

Did the player win anything?

Page 20: F# in social gaming by Yan Cui at Codemotion Dubai

What the player’s new average wager?

Page 21: F# in social gaming by Yan Cui at Codemotion Dubai

Should the player receive collectables?

Page 22: F# in social gaming by Yan Cui at Codemotion Dubai

type Symbol = Standard of string | Wild

Page 23: F# in social gaming by Yan Cui at Codemotion Dubai

type Symbol = Standard of string | Wild

e.g. Standard “hat”Standard “shoe”Standard “bonus”…

Page 24: F# in social gaming by Yan Cui at Codemotion Dubai

type Symbol = Standard of string | Wild

i.e. Wild

Page 25: F# in social gaming by Yan Cui at Codemotion Dubai

type Win = LineWin of int * Symbol * int | ScatterWin of Symbol * int

Page 26: F# in social gaming by Yan Cui at Codemotion Dubai

type Win = LineWin of int * Symbol * int | ScatterWin of Symbol * int

e.g. LineWin (5, Standard “shoe”, 4)

Page 27: F# in social gaming by Yan Cui at Codemotion Dubai

type Win = LineWin of int * Symbol * int | ScatterWin of Symbol * int

e.g. ScatterWin (Standard “bonus”, 3)

Page 28: F# in social gaming by Yan Cui at Codemotion Dubai

type LineNum = inttype Count = int

type Win = LineWin of LineNum * Symbol * Count | ScatterWin of Symbol * Count

Page 29: F# in social gaming by Yan Cui at Codemotion Dubai

closed hierarchy

Page 30: F# in social gaming by Yan Cui at Codemotion Dubai

no Nulls

Page 31: F# in social gaming by Yan Cui at Codemotion Dubai

make invalid states unrepresentable

Page 32: F# in social gaming by Yan Cui at Codemotion Dubai

[<Measure>]type Pence

e.g. 42<Pence>153<Pence>…

Page 33: F# in social gaming by Yan Cui at Codemotion Dubai

10<Meter> / 2<Second> = 5<Meter/Second>10<Meter> * 2<Second> = 20<Meter Second> 10<Meter> + 10<Meter> = 20<Meter>10<Meter> * 10 = 100<Meter>10<Meter> * 10<Meter> = 100<Meter2>10<Meter> + 2<Second> // error10<Meter> + 2 // error

Page 34: F# in social gaming by Yan Cui at Codemotion Dubai

10<Meter> / 2<Second> = 5<Meter/Second>10<Meter> * 2<Second> = 20<Meter Second> 10<Meter> + 10<Meter> = 20<Meter>10<Meter> * 10 = 100<Meter>10<Meter> * 10<Meter> = 100<Meter2>10<Meter> + 2<Second> // error10<Meter> + 2 // error

Page 35: F# in social gaming by Yan Cui at Codemotion Dubai

type Wager = int64<Pence>type Multiplier = int

type Payout = Coins of Wager | MultipliedCoins of Multiplier * Wager | Multi of Payout list | BonusGame

Page 36: F# in social gaming by Yan Cui at Codemotion Dubai

type Wager = int64<Pence>type Multiplier = int

type Payout = Coins of Wager | MultipliedCoins of Multiplier * Wager | Multi of Payout list | BonusGame

Page 37: F# in social gaming by Yan Cui at Codemotion Dubai

type Wager = int64<Pence>type Multiplier = int

type Payout = Coins of Wager | MultipliedCoins of Multiplier * Wager | Multi of Payout list | BonusGame

Page 38: F# in social gaming by Yan Cui at Codemotion Dubai

type State = {

AvgWager : WagerSpecialSymbol : SymbolCollectables : Map<Collectable, Count>

}

Page 39: F# in social gaming by Yan Cui at Codemotion Dubai

immutable by default

Page 40: F# in social gaming by Yan Cui at Codemotion Dubai
Page 41: F# in social gaming by Yan Cui at Codemotion Dubai

Recap

Page 42: F# in social gaming by Yan Cui at Codemotion Dubai

lightweight syntax for types & hierarchies

Page 43: F# in social gaming by Yan Cui at Codemotion Dubai

great for domain modelling

Page 44: F# in social gaming by Yan Cui at Codemotion Dubai

make invalid states unrepresentable

Page 45: F# in social gaming by Yan Cui at Codemotion Dubai

better correctness

Page 46: F# in social gaming by Yan Cui at Codemotion Dubai

order of magnitude increase in productivity

Page 47: F# in social gaming by Yan Cui at Codemotion Dubai
Page 48: F# in social gaming by Yan Cui at Codemotion Dubai
Page 49: F# in social gaming by Yan Cui at Codemotion Dubai

player states are big

Page 50: F# in social gaming by Yan Cui at Codemotion Dubai

Stateless Server DatabaseClient

Page 51: F# in social gaming by Yan Cui at Codemotion Dubai

1:1 read-write ratio

Page 52: F# in social gaming by Yan Cui at Codemotion Dubai
Page 53: F# in social gaming by Yan Cui at Codemotion Dubai

ServerClient

Session 1

Session 2

Page 54: F# in social gaming by Yan Cui at Codemotion Dubai

ServerClient Database

Page 55: F# in social gaming by Yan Cui at Codemotion Dubai

Elastic Load Balancer

S3

Auto scaling Group

Server A Server B

...

EC2

CloudFront

Stateful Server

Page 56: F# in social gaming by Yan Cui at Codemotion Dubai

Stateful Server

Game Logic

Stateless Middle-tier

Infrastructure

logging circuit breaker

perf tracking retry …

Page 57: F# in social gaming by Yan Cui at Codemotion Dubai

Stateful Server

Game Logic

Stateless Middle-tier

Infrastructure

logging circuit breaker

perf tracking retry …

Page 58: F# in social gaming by Yan Cui at Codemotion Dubai

Stateful Server

Game Logic

Stateful Middle-tier

Infrastructure

logging circuit breaker

perf tracking retry …

Page 59: F# in social gaming by Yan Cui at Codemotion Dubai

The Actor Model

An actor is the fundamental unit of computation which embodies the 3 things

• Processing• Storage• Communication

that are essential to computation.

-Carl Hewitt** http://bit.ly/HoNHbG

Page 60: F# in social gaming by Yan Cui at Codemotion Dubai

The Actor Model

• Everything is an actor• An actor has a mailbox• When an actor receives a message it can:– Create new actors– Send messages to actors– Designate how to handle the next message

Page 61: F# in social gaming by Yan Cui at Codemotion Dubai

Stateful Server

• Gatekeeper– Manages the local list of active workers– Spawns new workers

• Worker– Manages the states for a player– Optimistic locking– Persist state after period of inactivity

Page 62: F# in social gaming by Yan Cui at Codemotion Dubai

Stateful Server

Game Server

Player A

Player B

S3Worker C

Worker B

GatekeeperR

eque

st H

andl

ers

Asynchronous

Page 63: F# in social gaming by Yan Cui at Codemotion Dubai

Stateful Server

Game Server

Worker C

Worker B

Gatekeeper

Worker Aok

Req

uest

Han

dler

sPlayer A

Player B

Asynchronous

S3

Page 64: F# in social gaming by Yan Cui at Codemotion Dubai

Stateful Server

Game Server

S3Worker C

Worker B

Gatekeeper

Worker AR

eque

st H

andl

ers

Player A

Player B

Asynchronous

Page 65: F# in social gaming by Yan Cui at Codemotion Dubai

Stateful Server

Game Server

S3Worker C

Gatekeeper

Worker AR

eque

st H

andl

ers

Player A

Player B

Asynchronous

Page 66: F# in social gaming by Yan Cui at Codemotion Dubai

Stateful Server

Game Server

Worker C

Worker A

Gatekeeper

error

Req

uest

Han

dler

sPlayer A

Player B

S3

Asynchronous

Page 67: F# in social gaming by Yan Cui at Codemotion Dubai

type Agent<‘T> = MailboxProcessor<‘T>

Page 68: F# in social gaming by Yan Cui at Codemotion Dubai

type Agent<‘T> = MailboxProcessor<‘T>

type Message = | Get of AsyncReplyChannel<…> | Put of State * Version * AsyncReplyChannel<…>

Page 69: F# in social gaming by Yan Cui at Codemotion Dubai

type Agent<‘T> = MailboxProcessor<‘T>

type Message = | Get of AsyncReplyChannel<…> | Put of State * Version * AsyncReplyChannel<…>

Page 70: F# in social gaming by Yan Cui at Codemotion Dubai

type Result<‘T> = | Success of ’T | Failure of Exception

Page 71: F# in social gaming by Yan Cui at Codemotion Dubai

type Result<‘T> = | Success of ’T | Failure of Exception

type GetResult = Result<State * Version>type PutResult = Result<unit>

Page 72: F# in social gaming by Yan Cui at Codemotion Dubai

type Agent<‘T> = MailboxProcessor<‘T>

type Message = | Get of AsyncReplyChannel<GetResult> | Put of State * Version * AsyncReplyChannel<PutResult>

Page 73: F# in social gaming by Yan Cui at Codemotion Dubai

type Agent<‘T> = MailboxProcessor<‘T>

type Message = | Get of AsyncReplyChannel<GetResult> | Put of State * Version * AsyncReplyChannel<PutResult>

Page 74: F# in social gaming by Yan Cui at Codemotion Dubai

type Worker (playerId) = let agent = Agent<Message>.Start(fun inbox -> let state = getCurrentState playerId

let rec workingState (state, version) = async { … } and closedState () = async { … }

workingState (state, 1))

Page 75: F# in social gaming by Yan Cui at Codemotion Dubai

type Worker (playerId) = let agent = Agent<Message>.Start(fun inbox -> let state = getCurrentState playerId

let rec workingState (state, version) = async { … } and closedState () = async { … }

workingState (state, 1))

Page 76: F# in social gaming by Yan Cui at Codemotion Dubai

type Worker (playerId) = let agent = Agent<Message>.Start(fun inbox -> let state = getCurrentState playerId

let rec workingState (state, version) = async { … } and closedState () = async { … }

workingState (state, 1))

Page 77: F# in social gaming by Yan Cui at Codemotion Dubai

type Worker (playerId) = let agent = Agent<Message>.Start(fun inbox -> let state = getCurrentState playerId

let rec workingState (state, version) = async { … } and closedState () = async { … }

workingState (state, 1))

Page 78: F# in social gaming by Yan Cui at Codemotion Dubai

type Worker (playerId) = let agent = Agent<Message>.Start(fun inbox -> let state = getCurrentState playerId

let rec workingState (state, version) = async { … } and closedState () = async { … }

workingState (state, 1))

Page 79: F# in social gaming by Yan Cui at Codemotion Dubai

let rec workingState (state, version) = async { let! msg = inbox.TryReceive(60000) match msg with | None -> do! persist state return! closedState() … }

Page 80: F# in social gaming by Yan Cui at Codemotion Dubai

let rec workingState (state, version) = async { let! msg = inbox.TryReceive(60000) match msg with | None -> do! persist state return! closedState() … }

Page 81: F# in social gaming by Yan Cui at Codemotion Dubai

let rec workingState (state, version) = async { let! msg = inbox.TryReceive(60000) match msg with | None -> do! persist state return! closedState() … }

Page 82: F# in social gaming by Yan Cui at Codemotion Dubai

non-blocking I/O

Page 83: F# in social gaming by Yan Cui at Codemotion Dubai

let rec workingState (state, version) = async { let! msg = inbox.TryReceive(60000) match msg with | None -> do! persist state return! closedState() … }

Page 84: F# in social gaming by Yan Cui at Codemotion Dubai

let rec workingState (state, version) = async { let! msg = inbox.TryReceive(60000) match msg with | None -> do! persist state return! closedState() … }

Page 85: F# in social gaming by Yan Cui at Codemotion Dubai

let rec workingState (state, version) = async { let! msg = inbox.TryReceive(60000) match msg with … | Some(Get(reply)) -> reply.Reply <| Success(state, version) return! workingState(state, version) … }

Page 86: F# in social gaming by Yan Cui at Codemotion Dubai

let rec workingState (state, version) = async { let! msg = inbox.TryReceive(60000) match msg with … | Some(Get(reply)) -> reply.Reply <| Success(state, version) return! workingState(state, version) … }

type Message =

| Get of AsyncReplyChannel<GetResult>

| Put of State * Version * AsyncReplyChannel<PutResult>

Page 87: F# in social gaming by Yan Cui at Codemotion Dubai

let rec workingState (state, version) = async { let! msg = inbox.TryReceive(60000) match msg with … | Some(Get(reply)) -> reply.Reply <| Success(state, version) return! workingState(state, version) … }

type GetResult = Result<State * Version>

type PutResult = Result<unit>

Page 88: F# in social gaming by Yan Cui at Codemotion Dubai

let rec workingState (state, version) = async { let! msg = inbox.TryReceive(60000) match msg with … | Some(Get(reply)) -> reply.Reply <| Success(state, version) return! workingState(state, version) … }

Page 89: F# in social gaming by Yan Cui at Codemotion Dubai

let rec workingState (state, version) = async { let! msg = inbox.TryReceive(60000) match msg with … | Some(Put(newState, v, reply)) when version = v -> reply.Reply <| Success() return! workingState(newState, version+1) … }

Page 90: F# in social gaming by Yan Cui at Codemotion Dubai

let rec workingState (state, version) = async { let! msg = inbox.TryReceive(60000) match msg with … | Some(Put(newState, v, reply)) when version = v -> reply.Reply <| Success() return! workingState(newState, version+1) … }

type Message =

| Get of AsyncReplyChannel<GetResult>

| Put of State * Version * AsyncReplyChannel<PutResult>

Page 91: F# in social gaming by Yan Cui at Codemotion Dubai

let rec workingState (state, version) = async { let! msg = inbox.TryReceive(60000) match msg with … | Some(Put(newState, v, reply)) when version = v -> reply.Reply <| Success() return! workingState(newState, version+1) … }

Page 92: F# in social gaming by Yan Cui at Codemotion Dubai

let rec workingState (state, version) = async { let! msg = inbox.TryReceive(60000) match msg with … | Some(Put(newState, v, reply)) when version = v -> reply.Reply <| Success() return! workingState(newState, version+1) … }

Page 93: F# in social gaming by Yan Cui at Codemotion Dubai

let rec workingState (state, version) = async { let! msg = inbox.TryReceive(60000) match msg with … | Some(Put(_, v, reply)) -> reply.Reply <| Failure(VersionMismatch(version, v)) return! workingState(state, version) }

Page 94: F# in social gaming by Yan Cui at Codemotion Dubai

let rec workingState (state, version) = async { let! msg = inbox.TryReceive(60000) match msg with … | Some(Put(_, v, reply)) -> reply.Reply <| Failure(VersionMismatch(version, v)) return! workingState(state, version) } type Result<‘T> =

| Success of ’T

| Failure of Exception

Page 95: F# in social gaming by Yan Cui at Codemotion Dubai

let rec workingState (state, version) = async { let! msg = inbox.TryReceive(60000) match msg with | None -> … | Some(Get(reply)) -> … | Some(Put(newState, v, reply)) when version = v -> … | Some(Put(_, v, reply)) -> … }

Page 96: F# in social gaming by Yan Cui at Codemotion Dubai

and closedState () = async { let! msg = inbox.Receive() match msg with | Get(reply) -> reply.Reply <| Failure(WorkerStopped) return! closedState() | Put(_, _, reply) -> reply.Reply <| Failure(WorkerStopped) return! closedState() }

Page 97: F# in social gaming by Yan Cui at Codemotion Dubai

and closedState () = async { let! msg = inbox.Receive() match msg with | Get(reply) -> reply.Reply <| Failure(WorkerStopped) return! closedState() | Put(_, _, reply) -> reply.Reply <| Failure(WorkerStopped) return! closedState() }

Page 98: F# in social gaming by Yan Cui at Codemotion Dubai

5x efficient improvement

Page 99: F# in social gaming by Yan Cui at Codemotion Dubai

60% latency drop

Page 100: F# in social gaming by Yan Cui at Codemotion Dubai

no databases

Page 101: F# in social gaming by Yan Cui at Codemotion Dubai

90% cost saving

Page 102: F# in social gaming by Yan Cui at Codemotion Dubai

Recap

Page 103: F# in social gaming by Yan Cui at Codemotion Dubai

Agents• no locks• async message passing

Page 104: F# in social gaming by Yan Cui at Codemotion Dubai

Agents• no locks• async message passing• self-contained• easy to reason with

Page 105: F# in social gaming by Yan Cui at Codemotion Dubai

akka.Net

Orleans

Page 106: F# in social gaming by Yan Cui at Codemotion Dubai

Pattern Matching• clear & concise

Page 107: F# in social gaming by Yan Cui at Codemotion Dubai

Async Workflow• non-blocking I/O• no callbacks

Page 108: F# in social gaming by Yan Cui at Codemotion Dubai
Page 109: F# in social gaming by Yan Cui at Codemotion Dubai
Page 110: F# in social gaming by Yan Cui at Codemotion Dubai

Caught a Gnome

Page 111: F# in social gaming by Yan Cui at Codemotion Dubai

EXP Item Gold

Quest Progress

Caught a Gnome

Page 112: F# in social gaming by Yan Cui at Codemotion Dubai

Level Up

Quest Progress

EXP Item Gold

Caught a Gnome

Quest Complete

Page 113: F# in social gaming by Yan Cui at Codemotion Dubai

Level Up

Quest Progress

EXP Item Gold

Caught a Gnome

New Quest

Quest Complete

Page 114: F# in social gaming by Yan Cui at Codemotion Dubai

Quest Progress

EXP Item Gold

Caught a Gnome

Quest Complete

New Quest

Level Up

Page 115: F# in social gaming by Yan Cui at Codemotion Dubai

Quest Progress

New QuestAchievement

Progress

EXP Item Gold

Quest CompleteLevel Up

Caught a Gnome

Page 116: F# in social gaming by Yan Cui at Codemotion Dubai

Level Up

Quest Progress

EXP Item Gold

Caught a Gnome

Quest Complete

New QuestAchievement

Progress

Achievement Complete

Page 117: F# in social gaming by Yan Cui at Codemotion Dubai

Level Up

Quest Progress

EXP Item Gold

Caught a Gnome

Quest Complete

New QuestAchievement

Progress

Achievement Complete

Page 118: F# in social gaming by Yan Cui at Codemotion Dubai

100+ actions

Page 119: F# in social gaming by Yan Cui at Codemotion Dubai
Page 120: F# in social gaming by Yan Cui at Codemotion Dubai

triggered by different abstraction layers

Page 121: F# in social gaming by Yan Cui at Codemotion Dubai

non-functional requirements

Page 122: F# in social gaming by Yan Cui at Codemotion Dubai
Page 123: F# in social gaming by Yan Cui at Codemotion Dubai

message-broker pattern

Page 124: F# in social gaming by Yan Cui at Codemotion Dubai

Caught Gnome Trapping

Queue

Levelling

Quests

Achievements

Analytics

Partner Reporting

Page 125: F# in social gaming by Yan Cui at Codemotion Dubai

Caught Gnome Trapping

Queue

Levelling

Quests

Achievements

Analytics

Partner Reporting

Ignore

Process

Process

Process

Process

Ignore

Page 126: F# in social gaming by Yan Cui at Codemotion Dubai

Caught Gnome Trapping

Queue

Levelling

Quests

Achievements

Analytics

Partner Reporting

EXPItemGold

Page 127: F# in social gaming by Yan Cui at Codemotion Dubai

Caught Gnome Trapping

Queue

Levelling

Quests

Achievements

Analytics

Partner Reporting

EXPItemGold

Page 128: F# in social gaming by Yan Cui at Codemotion Dubai

Caught Gnome Trapping

Queue

Levelling

Quests

Achievements

Analytics

Partner Reporting

EXPItemGold

Process

Ignore

Ignore

Ignore

Process

Ignore

Page 129: F# in social gaming by Yan Cui at Codemotion Dubai

Caught Gnome Trapping

Queue

Levelling

Quests

Achievements

Analytics

Partner Reporting

EXPItemGold

Level Up

Page 130: F# in social gaming by Yan Cui at Codemotion Dubai

Caught Gnome Trapping

Queue

Levelling

Quests

Achievements

Analytics

Partner Reporting

EXPItemGold

Level Up

Page 131: F# in social gaming by Yan Cui at Codemotion Dubai

need lots of facts

Page 132: F# in social gaming by Yan Cui at Codemotion Dubai

type Fact = | GotExp of Exp | GotGold of Gold | GotItem of Item * Count | CaughtMonster of Monster * Bait * Location | LevelUp of OldLevel * NewLevel …

Page 133: F# in social gaming by Yan Cui at Codemotion Dubai

type Reward = | GotExp of Exp | GotGold of Gold | GotItem of Item * Count

type StateChange = | LevelUp of OldLevel * NewLevel …

Page 134: F# in social gaming by Yan Cui at Codemotion Dubai

type Fact = | StateChange of StateChange | Reward of Reward | Trapping of Trapping | Fishing of Fishing …

Page 135: F# in social gaming by Yan Cui at Codemotion Dubai

let process fact = match fact with | StateChange(stateChange) -> … | Reward(reward) -> … | Trapping(trapping) -> … …

Page 136: F# in social gaming by Yan Cui at Codemotion Dubai

C# interop

Page 137: F# in social gaming by Yan Cui at Codemotion Dubai

…var fact = Fact.NewStateChange(

StateChange.NewLevelUp(oldLvl, newLvl));…

Page 138: F# in social gaming by Yan Cui at Codemotion Dubai

type IFact = interface end

type Reward = | GotExp of Exp | GotGold of Gold | GotItem of Item * Count interface IFact

Page 139: F# in social gaming by Yan Cui at Codemotion Dubai

type IFact = interface end

type Reward = | GotExp of Exp | GotGold of Gold | GotItem of Item * Count interface IFact

Page 140: F# in social gaming by Yan Cui at Codemotion Dubai

let process (fact : IFact) = match fact with | :? StateChange as stateChange -> … | :? Reward as reward -> … | :? Trapping as trapping -> … … | _ -> raise <| NotSupportedFact fact

Page 141: F# in social gaming by Yan Cui at Codemotion Dubai

let process (fact : IFact) = match fact with | :? StateChange as stateChange -> … | :? Reward as reward -> … | :? Trapping as trapping -> … … | _ -> raise <| NotSupportedFact fact

Page 142: F# in social gaming by Yan Cui at Codemotion Dubai

simple

Page 143: F# in social gaming by Yan Cui at Codemotion Dubai

flexible

Page 144: F# in social gaming by Yan Cui at Codemotion Dubai

saver

Page 145: F# in social gaming by Yan Cui at Codemotion Dubai
Page 146: F# in social gaming by Yan Cui at Codemotion Dubai

location baitattraction rate

catch rate

Page 147: F# in social gaming by Yan Cui at Codemotion Dubai

auto-tuning trapping stats

Page 148: F# in social gaming by Yan Cui at Codemotion Dubai

Monsterstrength speed

intelligence

Trapstrength speed

technology

Page 149: F# in social gaming by Yan Cui at Codemotion Dubai

Monsterstrength speed

intelligence

Trapstrength speed

technology

Catch Rate %

Page 150: F# in social gaming by Yan Cui at Codemotion Dubai

trial-and-error

Page 151: F# in social gaming by Yan Cui at Codemotion Dubai

“if you require constant diligence you’re setting

everyone up for failure and hurt”

- Bryan Hunter

Page 152: F# in social gaming by Yan Cui at Codemotion Dubai

genetic algorithms

Page 153: F# in social gaming by Yan Cui at Codemotion Dubai
Page 154: F# in social gaming by Yan Cui at Codemotion Dubai
Page 155: F# in social gaming by Yan Cui at Codemotion Dubai
Page 156: F# in social gaming by Yan Cui at Codemotion Dubai
Page 157: F# in social gaming by Yan Cui at Codemotion Dubai
Page 158: F# in social gaming by Yan Cui at Codemotion Dubai
Page 159: F# in social gaming by Yan Cui at Codemotion Dubai
Page 160: F# in social gaming by Yan Cui at Codemotion Dubai
Page 161: F# in social gaming by Yan Cui at Codemotion Dubai
Page 162: F# in social gaming by Yan Cui at Codemotion Dubai
Page 163: F# in social gaming by Yan Cui at Codemotion Dubai
Page 164: F# in social gaming by Yan Cui at Codemotion Dubai

F#-powered DSLs.Awesome!

Page 165: F# in social gaming by Yan Cui at Codemotion Dubai
Page 166: F# in social gaming by Yan Cui at Codemotion Dubai
Page 167: F# in social gaming by Yan Cui at Codemotion Dubai

wanna find correlations?

Page 168: F# in social gaming by Yan Cui at Codemotion Dubai

wanna find correlations?

you can DIY it!

;-)

Page 169: F# in social gaming by Yan Cui at Codemotion Dubai

Amazon.CloudWatch.Selector

github.com/fsprojects/Amazon.CloudWatch.Selector

Page 170: F# in social gaming by Yan Cui at Codemotion Dubai

Find metrics whose 5 min average exceeded

1 second during last 12 hours

Page 171: F# in social gaming by Yan Cui at Codemotion Dubai

cloudWatch.Select( unitIs “milliseconds” + average (>) 1000.0 @ last 12 hours |> intervalOf 5 minutes)

Page 172: F# in social gaming by Yan Cui at Codemotion Dubai

cloudWatch.Select(“ unitIs ‘milliseconds’ and average > 1000.0 duringLast 12 hours at intervalOf 5 minutes”)

Page 173: F# in social gaming by Yan Cui at Codemotion Dubai

Did any cache nodes’ CPU spike yesterday?

Page 174: F# in social gaming by Yan Cui at Codemotion Dubai

cloudWatch.Select( namespaceLike “elasticache” + nameLike “cpu” + max (>) 80.0 @ last 24 hours |> intervalOf 15 minutes)

Page 175: F# in social gaming by Yan Cui at Codemotion Dubai

cloudWatch.Select( namespaceLike “elasticache” + nameLike “cpu” + max (>) 80.0 @ last 24 hours |> intervalOf 15 minutes)

regex support

Page 176: F# in social gaming by Yan Cui at Codemotion Dubai
Page 177: F# in social gaming by Yan Cui at Codemotion Dubai
Page 178: F# in social gaming by Yan Cui at Codemotion Dubai
Page 179: F# in social gaming by Yan Cui at Codemotion Dubai

Amazing

F# =

Page 180: F# in social gaming by Yan Cui at Codemotion Dubai
Page 181: F# in social gaming by Yan Cui at Codemotion Dubai

managedkey-value store

Page 182: F# in social gaming by Yan Cui at Codemotion Dubai

redundancy9-9s guarantee

Page 183: F# in social gaming by Yan Cui at Codemotion Dubai

great performance

Page 184: F# in social gaming by Yan Cui at Codemotion Dubai

name your throughput

Page 185: F# in social gaming by Yan Cui at Codemotion Dubai
Page 186: F# in social gaming by Yan Cui at Codemotion Dubai

select GameTitle, UserId, TopScore from GameScores where GameTitle = “Starship X” and TopScore >= 1000 order desc limit 3 with (NoConsistentRead, Index(GameTitleIndex, true))

Page 187: F# in social gaming by Yan Cui at Codemotion Dubai

DynamoDB.SQL

github.com/fsprojects/DynamoDb.SQL

Page 188: F# in social gaming by Yan Cui at Codemotion Dubai

GOAL

Disguise complexity

Page 189: F# in social gaming by Yan Cui at Codemotion Dubai

GOAL

SELECT UserId, TopScore FROM GameScore WHERE GameTitle CONTAINS “Zelda” ORDER DESCLIMIT 3 WITH (NoConsistentRead)

Page 190: F# in social gaming by Yan Cui at Codemotion Dubai

Query

AST

Execution

Page 191: F# in social gaming by Yan Cui at Codemotion Dubai

F# & FParsec*

*www.quanttec.com/fparsec

External DSL via

Page 192: F# in social gaming by Yan Cui at Codemotion Dubai
Page 193: F# in social gaming by Yan Cui at Codemotion Dubai

SELECT * FROM GameScore

Abstract Syntax Tree (AST)

FParsec

Page 194: F# in social gaming by Yan Cui at Codemotion Dubai
Page 195: F# in social gaming by Yan Cui at Codemotion Dubai

select GameTitle, UserId, TopScore from GameScores where GameTitle = “Starship X” and TopScore >= 1000 order desc limit 3 with (NoConsistentRead, Index(GameTitleIndex, true))

Page 196: F# in social gaming by Yan Cui at Codemotion Dubai
Page 197: F# in social gaming by Yan Cui at Codemotion Dubai

< 50 LOC

Page 198: F# in social gaming by Yan Cui at Codemotion Dubai

S3 Provider

github.com/fsprojects/S3Provider

F# type provider for Amazon S3

Page 199: F# in social gaming by Yan Cui at Codemotion Dubai
Page 200: F# in social gaming by Yan Cui at Codemotion Dubai
Page 201: F# in social gaming by Yan Cui at Codemotion Dubai

intellisense over S3

Page 202: F# in social gaming by Yan Cui at Codemotion Dubai

compile time validation

Page 203: F# in social gaming by Yan Cui at Codemotion Dubai

no code generation

Page 204: F# in social gaming by Yan Cui at Codemotion Dubai

Domain ModellingInfrastructureGame LogicAlgorithms

DSLs

Page 205: F# in social gaming by Yan Cui at Codemotion Dubai

why F#?

Page 206: F# in social gaming by Yan Cui at Codemotion Dubai

time to market

Page 207: F# in social gaming by Yan Cui at Codemotion Dubai

correctness

Page 208: F# in social gaming by Yan Cui at Codemotion Dubai

efficient

Page 209: F# in social gaming by Yan Cui at Codemotion Dubai

tame complexity

Page 210: F# in social gaming by Yan Cui at Codemotion Dubai

@theburningmonktheburningmonk.comgithub.com/theburningmonk